Skip to content

Instantly share code, notes, and snippets.

@zackdouglas
Created May 19, 2017 16:33
Show Gist options
  • Save zackdouglas/1c7d23171a57541f8395b5807d71f212 to your computer and use it in GitHub Desktop.
Save zackdouglas/1c7d23171a57541f8395b5807d71f212 to your computer and use it in GitHub Desktop.
Detect if a user is in Private Browsing mode
function detectPrivateMode(a){var b;if(window.webkitRequestFileSystem)window.webkitRequestFileSystem(window.TEMPORARY,1,function(){b=!1},function(a){b=!0});else if(window.indexedDB&&/Firefox/.test(window.navigator.userAgent)){var c;try{c=window.indexedDB.open("test")}catch(a){b=!0}void 0===b&&t(function(){return"done"===c.readyState},function(a){a||(b=!c.result)})}else if(o(window.navigator.userAgent)){b=!1;try{window.indexedDB||(b=!0)}catch(a){b=!0}}else if(window.localStorage&&/Safari/.test(window.navigator.userAgent)){if(window.safariIncognito)b=!0;else try{window.localStorage.setItem("test",1)}catch(a){b=!0}void 0===b&&(b=!1,window.localStorage.removeItem("test"))}t(function(){return void 0!==b},function(c){a(b)})}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment