How do I know if I am on an anonymous or normal chrome page?


I'm making a page html to use locally on my PC with Windows , but I needed some way to know how I'm in the browser Chrome . I wanted to present a phrase that would change depending on the way I was.


  • Incognito Mode

    This page is in anonymous mode!

  • Normal Mode

    This page is in normal mode!

I've tried this example in the jsfiddle but unsuccessfully.


I was able to get the desired result with the jsfilddle example as mentioned by @TomMelo. But in my case I uploaded to a server, however what I need is to use locally without the need to use a server, is there any other way to do it?

asked by anonymous 02.08.2017 / 12:09

3 answers


I do not recommend doing this type of verification.

An HTTP request must contain, in a very brief way, only the address to be obtained, the way of obtaining it (ie GET) and optionally parameters for the page. Any data in addition is courtesy of the browser. So much so that it is trivial to make a client go through any browser.

The intent of anonymous mode is to pass as little data as possible to the page you want to get. If you decide to get the data that the browser wants to hide, you have entered a game of cat and mouse. This is exactly why some solutions proposed in two previous answers (already deleted and only visible to those with more than 10,000 points) have already worked one day, but they do not work anymore.

If you can get something that works today, tomorrow may not work anymore. And when it stops working, it's going to be unannounced, and you'll have to chase after another gambiarra.

Finally, this afternoon's solution is to use the File System API, which from time to time behaves differently in incognito mode. When this technique starts to be used a lot (it will not take long), the Chromium people will find a way to solve this. Until then, you can risk your luck. You can find the documentation on how to use it in MDN, but even there you already start your study with this warning (my emphases):


This feature is non-standard and is not on a standard track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future .

In Portuguese:


This feature is not standard and is not on the trail of the patterns to implement. Do not use this on production sites and web-accessible: this will not work for all users. There may be large incompatibilities between implementations and behavior may change in the future . p>

02.08.2017 / 13:48

The FileSystem API is disabled in Incognito mode. The code you mentioned works ...

var fs = window.RequestFileSystem || window.webkitRequestFileSystem;
fs(window.TEMPORARY, 10, function() {
   console.log('modo normal');
}, function(error) {
   console.log('modo incognito');

Detail : If you try to open the file (.html) in the browser:


This code will always display the error callback message .

Test your page through Apache, for example.


As already mentioned in the previous answers, this validation is not recommended (do not implement to run in production).

However, if it is just a test to run on the local machine, you can try the validation through the FileSystem api.

20.09.2017 / 22:17

Try this simple code:

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

Source: link

21.09.2017 / 19:46