google-chrome-extensionuserscriptsincognito-mode

Is it possible to determine if Chrome is in incognito mode via a user-script?


I asked this question before but didn't make it clear that I meant in user script, not in JavaScript from a webpage.So I'll be more clear now.

Is it possible to determine if Google Chrome is in incognito mode via a user-script (basically a script run as an extension in the browser, not a script being run on a webpage)?


Solution

  • If you are developing an Extension then you can use the tabs API to determine if a window/tab incognito.

    More information can be found on code.google.com.

    If you are just working with a webpage or a userscript, it is not easy, and it is designed to be that way. However, I have noticed that all attempts to open a database (window.database) fail when in incongnito, this is because when in incognito no trace of data is allowed to be left on the users machine.

    I haven't tested it but I suspect all calls to localStorage fail too.