How do I know if I’m on an anonymous or normal Chrome page?

Asked

Viewed 2,456 times

10

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

Example:

  • Incognito Mode

    This page is in anonymous mode!

  • Normal Mode

    This page is in normal mode!

I’ve tried this example on jsfiddle but without success.

Edit1:


I was able to get the desired result with the jsfilddle example as you mentioned @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, there is some other way to do it?

3 answers

20

I don’t recommend doing this kind of checking.

An HTTP request needs to contain, in a well summarized form, only the address to get, the way to get (i.e.: GET) and optionally parameters for the page. Any data in addition are courtesy of the browser. So much so that it is trivial to make a client who passes for any browser.

The intention of the anonymous mode is precisely to pass the minimum possible data to the page you want to get. If you decide to get the data that the browser intends to hide, you have already entered a game of cat and mouse. It is exactly for this reason that some solutions proposed in two previous answers (already deleted and only visible to those who have more than 10 thousand points) have already worked one day, but no longer work today.

If you get something that works today, tomorrow it might not work anymore. And when it stops working, it will be without warning, and you will have to run after another gambiarra.

Finally, this afternoon’s solution is to use the file system API, which from time to time has a different behavior in Incognite mode. When this technique starts to be used (it doesn’t take long), the Chromium people will find a way to solve this. Until then, you can risk your luck. You can find documentation on how to use it on MDN, but even there you already start your study with this warning (emphasis mine):

This Feature is non-standard and is not on a standards 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 functionality is not standard and is not in the path of standards to be implemented. Do not use this on production and web accessible websites: this will not work for all users. There may be major incompatibilities between implementations and behavior may change in the future.

  • thanks for the reply, the use I was going to give was homemade and for a very simple thing, as I said it was only to show the message, I will try to dig deeper and try to discover something and hope that someone can help me.

1

To 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:

file:///diretorio/arquivo.html

this code will always display the error callback message.

Test your page through Apache, for example.

EDIT


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

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

  • 5

    MDN already starts the link page with a warning: This Feature is non-standard and is not on a standards 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.

  • Yes, this is not to be used in production. It is only for the author who is "making html page to use locally on Windows PC"

  • @Tommelo there is some way to do it but without the need for a server?

  • @Tmc believes that if you open Chrome with the --allow-file-access-from-files flag it should work... Remembering that this is just for testing. You need to do it yourself?

  • 1

    The problem of this solution in a next update they may simply cut the script and you have to run after another Pog to solve this.

0

Try this simple code:

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"));
}

Source: https://stackoverflow.com/a/17741714/7934535

  • has any solution for Chrome?

  • @Tmc I searched, but no solution I found really works

Browser other questions tagged

You are not signed in. Login or sign up in order to post.