Sometimes, we want to determine if Chrome is in incognito mode via a script with JavaScript.
In this article, we’ll look at how to determine if Chrome is in incognito mode via a script with JavaScript.
How to determine if Chrome is in incognito mode via a script with JavaScript?
To determine if Chrome is in incognito mode via a script with JavaScript, we check if the file systems API can’t be used.
For instance, we write
const 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")
);
}
to check if fs
is undefined.
If it’s undefined, then the script is run in incognito mode.
Otherwise, we call fs
with callbacks to check if it’s executed successfully.
The 3rd argument is the success callback and the 4th is the error callback.
If the error callback is run, then the user is in incognito mode.
Conclusion
To determine if Chrome is in incognito mode via a script with JavaScript, we check if the file systems API can’t be used.
One reply on “How to determine if Chrome is in incognito mode via a script with JavaScript?”
This doesn’t work any more.
See https://stackoverflow.com/questions/2860879/detecting-if-a-browser-is-using-private-browsing-mode/22623958#22623958 for details