Is it possible to determine if Chrome is turned on incognito using a user script?

I asked this question before , but didn’t make it clear what I meant in the user script, and not in JavaScript from the web page. Therefore, I will now be more clear.

Is it possible to determine whether Google Chrome works incognito using a user-script (basically, the script is executed as an extension in the browser, not the script that is executed on the web page)?

+18
google-chrome userscripts incognito-mode
May 26 '10 at 21:15
source share
3 answers

If you are developing an extension, you can use the tabs API to determine if a window / tab is enabled.

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

If you just work with a web page or custom text, this is not easy, and it is designed that way. However, I noticed that all attempts to open the database (window.database) will fail when in incongnito, this is because when in incognito there are no traces of data on the user's computer.

I have not tested it, but I suspect that all localStorage calls do not work either.

+7
May 26 '10 at 22:02
source share

To determine if a window is in incognito mode, check the incognito property of the corresponding tab or Window object. For example:

var bgPage = chrome.extension.getBackgroundPage(); function saveTabData(tab, data) { if (tab.incognito) { bgPage[tab.url] = data; // Persist data ONLY in memory } else { localStorage[tab.url] = data; // OK to store data } 

http://code.google.com/chrome/extensions/overview.html

+11
May 26 '10 at 21:20
source share

This is currently pretty easy to do from a content script. Just use

 if(chrome.extension.inIncognitoContext) { //you're incognito } else { //you're not } 
0
Aug 10 '16 at 7:51
source share



All Articles