detectIncognito.js

repository·main·Indexed 19 days ago

https://github.com/joe12387/detectincognito

A 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.

Tokens
869
Snippets
4
Records
6
Agent score
19%

What's inside detectincognitojs

  1. Install detectIncognito.js via CDN

    main

    You 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>
  2. Important notes and limitations

    main

    When using detectincognitojs, be aware of the following:

    • False Positives: Can occur in certain browser setups or Chrome Guest mode.
    • Firefox Containers: Firefox Container Tabs are not detected.
    • HTTPS Requirement: The script must be served over HTTPS to function correctly.
    • CDN Blocking: Brave and uBlock Origin may block the jsDelivr CDN; self-hosting the script is recommended.
    • Error Handling: The library throws an error if the browser cannot be identified.
  3. Use detectIncognito() to detect private browsing

    main

    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);
    });
  4. Access detectIncognito via the window object

    main

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