javascriptgoogle-chromeincognito-mode

Can you determine if Chrome is in incognito mode via a script?


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

Edit: I actually meant is it possible via user-script, but the answers assume JavaScript is running on a web page. I've re-asked the question here in regards to user scripts.


Solution

  • The functionality of this answer is Chrome version dependant. The most recent comment was this works in v90

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

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