Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 794
RodeoClown Avatar asked May 26 '10 21:05

RodeoClown


People also ask

Can you detect Incognito mode?

Websites see you as a new user and won't know who you are, as long as you don't sign in. If you're browsing in Chrome Incognito mode, you are, by default, not signed into any accounts or sites. Your school, Internet Service Provider, or any parental tracking software may be able to see your activity.


3 Answers

To detect whether a window is in incognito mode, check the incognito property of the relevant 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

like image 114
Sharjeel Aziz Avatar answered Oct 20 '22 09:10

Sharjeel Aziz


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.

like image 42
Kinlan Avatar answered Oct 20 '22 10:10

Kinlan


Nowadays it's quite easy to do this from a content script. Just use

if(chrome.extension.inIncognitoContext) {
    //you're incognito
} else {
    //you're not
}
like image 39
jberculo Avatar answered Oct 20 '22 08:10

jberculo