Coder Social home page Coder Social logo

joe12387 / detectincognito Goto Github PK

View Code? Open in Web Editor NEW
309.0 19.0 40.0 188 KB

JavaScript detection of Incognito & other private browsing modes on Chrome, Edge, Safari, Brave, Firefox, Opera and MSIE.

License: MIT License

HTML 33.01% TypeScript 44.72% JavaScript 22.27%
incognito chrome edge safari firefox internet-explorer private-browsing incognito-mode incognito-browsing incognito-window

detectincognito's Introduction

Note: The npm package is now detectincognitojs.

detectIncognito.js

detectIncognito.js can be used to detect incognito mode & other private browsing modes on most modern browsers as of 2024.

  • Detects Incognito mode on Google Chrome
  • Detects Private Windows on Safari for macOS
  • Detects Private Tabs on Safari for iOS
  • Detects Private Windows in Firefox
  • Detects InPrivate Windows on Microsoft Edge
  • Detects InPrivate Windows on Microsoft Internet Explorer
  • Detects Private Windows in Brave (see notes)
  • Detects Private Windows in Opera

Demo

https://detectincognito.com/

Usage

Get script from CDN (may be blocked by adblockers, see notes)

<script src="https://cdn.jsdelivr.net/gh/Joe12387/detectIncognito@main/dist/es5/detectIncognito.min.js"></script>

Or install from NPM

npm i detectincognitojs
import { detectIncognito } from "detectincognitojs";

Run the detect function

detectIncognito().then((result) => {
  console.log(result.browserName, result.isPrivate);
});

Supported Browsers

Browser Platform(s) Versions Notes
Safari iOS 8 to 18 Beta 3
Safari macOS ≤ 17.5
Chrome/Chromium All 50 to 127 Beta
Edge All 15 to 18; 79 to 126
Firefox All 44 to 128
Brave All ≤ 1.67 CDN is blocked if shields are up
MSIE Windows 11 Promise polyfill required

Please note that although this script works on almost all modern browsers, detecting private modes in browsers is very much an arms race. As such, I cannot guarantee that this script will continue to work into the future. However, I will continue to actively maintain this script to support as many browsers as is possible.

If you are aware of any modern browsers this script does not work with, please let me know by creating an issue.

Notes

  • There will be a false positive in certain browser configurations, as well as in Chrome's Guest mode. (Issue #21).
  • This script does not detect Container Tabs on Firefox as they work differently compared to private mode.
  • An error will be thrown if the browser cannot be identified.
  • The script only works remotely on a web server using HTTPS. Running the script locally or with HTTP may produce a false result, or it may not run at all.
  • Brave and uBlock Origin currently block the script from loading from the CDN. Hosting the script elsewhere should bypass this.

Similar Projects

License

Copyright (c) 2024 Joe Rutkowski

Released under MIT License

detectincognito's People

Contributors

deokti avatar joe12387 avatar michaelkolesidis avatar mykolashevchuk avatar napthedev avatar p810 avatar surferjeff avatar toxic-johann avatar xiren7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

detectincognito's Issues

macOs Safari 15 automated tests detected as Private Mode

Hello,
thank's for your job. It is currently the only library that works on all versions of all major vendors.

In my job I have to integrate the control on the verification of the private mode through automated tests using webdriver.io and selenium-standalone.
While testing with Safari 15 on macOS I found that the library detects the browser as private mode even though it is not.
For other browsers such as Chrome, Firefox and Edge / IE the detection occurs correctly.

Firefox displays incorrect isPrivate value when the site URL is HTTP

OS:- MacOs ventura(13.2.1)
Browser: Firefox(113.0.1)

When the site URL is HTTP, the isPrivate value is incorrectly displayed as true instead of false in normal mode.

Solution:

const firefoxPrivateTest = () => {
  const db = indexedDB.open('test');

    db.onerror = function () {
      __callback(true);
    };
    db.onsuccess = function () {
      __callback(false);
    };
};

Doesn't work on Safari 16.0 on MacOS and Mobile

Hello and thank you for your job! But the last update of safari crashes everything. On 1.1.1 it doesn't work and even doesn't throw any errors on safari 16.0. Do you have some thoughts about it? Can you fix it?

chrome/v8 106+ support

106's update comes with jsHeapSizeLimit matching incongnito and normal browsing. Arms race continues.. I will update if I find a new way... any ideas are welcome

check error Chrome 107.0.5304.108

image

function storageQuotaChromePrivateTest() {
      navigator.webkitTemporaryStorage.queryUsageAndQuota(
        function (usage, quota) {
          console.log(quota, getQuotaLimit()); // 1119775232 1098907648
          _resolveFn(quota < getQuotaLimit());  // false
        },
        function (e) {
          reject(new Error("detectIncognito somehow failed to query storage quota: " + e.message));
        }
      );
    }

Vivaldi always shows as isPrivate

I use Vivaldi and it is a Major boon to my workflow, However, we need to stop incognito in browsers for most of our pages. Unfortunately this also throws Vivaldi users under the bus. We have tried several of the work-arounds that no longer work with the current version of Vivaldi.

This is probably a know issue, but would appreciate feedback.

Error: File '/node_modules/detectincognitojs/dist/detectIncognito.d.ts' is not a module.ts(2306)

I install the package, I follow the instructions and I try to import it

import { detectIncognito } from "detectincognitojs";

And I get an error:

File '/node_modules/detectincognitojs/dist/detectIncognito.d.ts' is not a module.ts(2306)

I am using create-react-app with the TypeScript template

I have also created a minimal reproducible example, an empty test project and when I tried to import it, I had the exact same problem.

The previous version (1.1.2) works fine, the error only occurs in the latest version (1.2.0).

Version: 1.2.0
Browsers: All

TypeError: undefined is not an object (evaluating 'iframe.contentWindow.applicationCache.addEventListener') on iOS 16

error

image

code

try {
    const result = await detectIncognito();

    if (result.isPrivate) {
      alert(
        'using private mode',
      );
      window.addEventListener('beforeunload', (e) => {
        e.preventDefault();
        e.returnValue =
          'using private mode';
      });
    }
  } catch (error) {
    console.error(error);
  }

environment

safari 16
iOS 16
iPhone 14 on Xcode simulator

code base

ESbuild
react
typescript


btw awesome package ! work well on chrome and iOS 15

firefox 108.0 is not correct when http access

my firefox is not in private mode, but i access web page with http, when i get navigator.serviceWorker, it is undefined, and it will be judged to be private mode.

the firefox version is 108.0

iPhone QR Code scanner

Hi,
Thanks for your great work.

There is one case I'm not sure how you see it, but would help me and possibly many others a LOT:
When opening an URL from the camera app, it will open in normal Safari, either in normal or private mode (whatever was last opened). But when scanning a QR code from the quick access menu (Control Center) shortcut, it will open some single browser window without a URL bar. And this window will not share it's session with Safari, meaning that if someone is authenticated in Safari, he will not be authenticated in this session, which seems to me to be very similar like being in Incognito mode.
Is this something your script could detect as well?
Thank you

Email broken?

Trying to send you an email, but...

<[[email protected]](mailto:[email protected])>: host aspmx.l.google.com[142.250.27.27] said: 550-5.1.1 The
    email account that you tried to reach does not exist. Please try 550-5.1.1
    double-checking the recipient's email address for typos or 550-5.1.1
    unnecessary spaces. Learn more at 550 5.1.1
    https://support.google.com/mail/?p=NoSuchUser
    gb41-20020a170907962900b0078db6f56d51si11074896ejc.808 - gsmtp (in reply to
    RCPT TO command)

new/easier safari method

navigator.storage.getDirectory().then(ok => {
  console.log('not private')
}, err => {
  console.log('private')
})

False positives

From what I see, the Chrome detection is based on storage quota < physical memory from here, but this condition is not exclusive to incognito mode. It's also in:

  • Guest mode
  • Privacy and security settings
    • Clear cookies and site data when you close all windows
    • Sites that clear cookies when you close them
  • Anytime storage quota < jsHeapSizeLimit. Example: 3.99GB quota and 4GB jsHeapSizeLimit would get detected as incognito

Firefox can also produce false positives if the user disables Service Workers and Push API

  • dom.serviceWorkers.enabled
  • dom.push.enabled

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.