Can you tell if Chrome is turned on incognito using a script?

Is it possible to determine if Google Chrome is in incognito mode using a script?

Edit: I really meant that this is possible with a user-script, but the answers suggest that JavaScript works on the web page. I asked a question here regarding custom scripts.

+106
javascript google-chrome incognito-mode
May 26 '10 at 12:04 a.m.
source share
10 answers

Yes. FileSystem API is disabled in incognito mode. Check out https://jsfiddle.net/w49x9f1a/ when you are and are not in incognito mode.

Code example:

var fs = window.RequestFileSystem || window.webkitRequestFileSystem; if (!fs) { console.log("check failed?"); } else { fs(window.TEMPORARY, 100, console.log.bind(console, "not in incognito mode"), console.log.bind(console, "incognito mode")); } 

+225
Jan 06 '15 at 19:09
source share

One way is to visit the unique URL and then check if the link to this URL is considered as visited CSS.

You can see an example of this in "Incognito Detection" (Dead link).

Research paper by the same author to replace Incognito Discovery link above

In main.html add iframe,

  <iframe id='testFrame' name='testFrame' onload='setUniqueSource(this)' src='' style="width:0; height:0; visibility:hidden;"></iframe> 

and some JavaScript code:

 function checkResult() { var a = frames[0].document.getElementById('test'); if (!a) return; var color; if (a.currentStyle) { color = a.currentStyle.color; } else { color = frames[0].getComputedStyle(a, '').color; } var visited = (color == 'rgb(51, 102, 160)' || color == '#3366a0'); alert('mode is ' + (visited ? 'NOT Private' : 'Private')); } function setUniqueSource(frame) { frame.src = "test.html?" + Math.random(); frame.onload = ''; } 

Then in test.html , which are loaded in the iFrame:

 <style> a:link { color: #336699; } a:visited { color: #3366A0; } </style> <script> setTimeout(function() { var a = document.createElement('a'); a.href = location; a.id = 'test'; document.body.appendChild(a); parent.checkResult(); }, 100); </script> 

NOTE. Try this from the file system to scream Chrome about "Unsafe Javascript." This will work, however, from a web server.

+18
May 26 '10 at
source share

You can see JHurrah's answer in JavaScript. Except that no links are highlighted, the entire incognito mode does not save browsing history and cookies. From google man page :

  • Web pages that you open and files downloaded during incognito are not displayed in your browser and download history.
  • All new cookies are deleted after closing all the incognito windows that you opened.

As you can see, the differences between normal browsing and incognito happen after you visit a web page, so there is nothing that the browser connects to the server when it is in this mode.

You can see what exactly your browser sends to the server using one of the many HTTP request analyzers, for example this one here . Compare the headers between your regular session and incognito, and you will not see any difference.

+8
May 26 '10 at
source share

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

More information can be found here .

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

I have not tested this, but I suspect that all calls to localStorage also fail.

+4
May 26 '10 at 7:24 a.m.
source share

This uses the promise to wait until the asynchronous code sets the flag, so we can use it synchronously later.

 let isIncognito = await new Promise((resolve, reject)=>{ var fs = window.RequestFileSystem || window.webkitRequestFileSystem; if (!fs) reject('Check incognito failed'); else fs(window.TEMPORARY, 100, ()=>resolve(false), ()=>resolve(true)); }); 

then we can do

 if(isIncognito) alert('in incognito'); else alert('not in incognito'); 
+3
Mar 30 '18 at 14:28
source share

In Chrome 74+, you can determine this by evaluating the available file system storage space.

 if ('storage' in navigator && 'estimate' in navigator.storage) { const {usage, quota} = await navigator.storage.estimate(); console.log('Using ${usage} out of ${quota} bytes.'); if(quota < 120000000){ console.log('Incognito') } else { console.log('Not Incognito') } } else { console.log('Can not detect') } 
+3
Aug 10 '19 at 2:48
source share

Alok Answer- based quick copy paste (note: this is asynchronous)

 function ifIncognito(incog,func){ var fs = window.RequestFileSystem || window.webkitRequestFileSystem; if (!fs) console.log("checking incognito failed"); else { if(incog) fs(window.TEMPORARY, 100, ()=>{}, func); else fs(window.TEMPORARY, 100, func, ()=>{}); } } 

using:

 ifIncognito(true, ()=>{ alert('in incognito') }); // or ifIncognito(false, ()=>{ alert('not in incognito') }); 
0
Apr 30 '17 at 11:17
source share

Here is a suggested answer written in ES6 syntax and a little cleared up.

 const isIncognito = () => new Promise((resolve, reject) => { const fs = window.RequestFileSystem || window.webkitRequestFileSystem; if (!fs) { reject('Cant determine whether browser is running in incognito mode!'); } fs(window.TEMPORARY, 100, resolve.bind(null, false), resolve.bind(null, true)); }); // Usage isIncognito() .then(console.log) .catch(console.error) 
0
Oct 20 '18 at 11:44
source share

Yes, but should you? (Hint: no you shouldn't)

0
Apr 10 '19 at 16:54
source share

Incognito mode documentation specifically says that websites will not behave differently. I believe this means that there is no answer.

-9
May 26 '10 at a.m.
source share



All Articles