Install detectincognitojs via NPM
mainTo use the library in a Node.js or bundled frontend project, install the detectincognitojs package using npm.
npm i detectincognitojsrepository·main·Indexed 19 days ago
https://github.com/joe12387/detectincognitoA lightweight library for detecting Incognito, Private, and InPrivate browsing modes across modern web browsers including Chrome, Safari, Firefox, and Edge. Version 1.8.0 provides the detectIncognito() function, which returns a Promise indicating the browser name and private mode status. Requires HTTPS to function correctly.
To use the library in a Node.js or bundled frontend project, install the detectincognitojs package using npm.
npm i detectincognitojsYou can include the script directly in your HTML via a CDN.
Warning: Brave and uBlock Origin may block this CDN. To ensure reliability, host the script yourself.
Warning: The script must run over HTTPS. Running locally or via HTTP might cause detection to fail.
<script src="https://cdn.jsdelivr.net/gh/Joe12387/detectIncognito@main/dist/es5/detectIncognito.min.js"></script>When using detectincognitojs, be aware of the following:
Import the detectIncognito function from detectincognitojs. Calling this function returns a Promise that resolves to an object containing the browser name and a boolean indicating if the user is in a private/incognito mode.
Note: An error is thrown if the browser cannot be identified.
import { detectIncognito } from "detectincognitojs";
detectIncognito().then((result) => {
console.log(result.browserName, result.isPrivate);
});The library supports detection across the following browsers:
| Browser | Platform(s) | Versions | Notes |
|---|---|---|---|
| Safari | All | ≤ 26.5 | |
| Chromium | All | 83 to 150 | |
| Firefox | All | 44 to 153 | |
| MSIE | Windows | 11 | Requires Promise polyfill |
When used in a browser environment, detectIncognito is automatically attached to the global window object. This allows you to call it without an explicit import if the library has already been loaded into the global scope.
Type Definition:
window.detectIncognito matches the signature of the detectIncognito() function.
// If the library is loaded via a <script> tag or similar
(async () => {
const result = await window.detectIncognito();
console.log(result);
})();