UNPKG

detectincognitojs

Version:

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

32 lines 7.59 kB
/*! * * detectIncognito v1.7.0 * * https://github.com/Joe12387/detectIncognito * * MIT License * * Copyright (c) 2021 - 2026 Joe Rutkowski <Joe@dreggle.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Please keep this comment intact in order to properly abide by the MIT License. * **/ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.detectIncognito=t():e.detectIncognito=t()}(this,function(){return function(){"use strict";var e={};return{598:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,a){function i(e){try{s(r.next(e))}catch(e){a(e)}}function c(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(i,c)}s((r=r.apply(e,t||[])).next())})},r=this&&this.__generator||function(e,t){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}};function o(){return n(this,void 0,Promise,function(){return r(this,function(e){switch(e.label){case 0:return[4,new Promise(function(e,t){var o="Unknown",a=!1;function i(t){a||(a=!0,e({isPrivate:t,browserName:o}))}function c(){var e=0,t=parseInt("-1");try{t.toFixed(t)}catch(t){e=t.message.length}return e}function s(){return n(this,void 0,void 0,function(){var e,t;return r(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,navigator.storage.getDirectory()];case 1:return n.sent(),i(!1),[3,3];case 2:return e=n.sent(),t=e instanceof Error&&"string"==typeof e.message?e.message:String(e),i(t.includes("unknown transient reason")),[3,3];case 3:return[2]}})})}function u(){var e;return n(this,void 0,Promise,function(){return r(this,function(t){switch(t.label){case 0:return"function"!=typeof(null===(e=navigator.storage)||void 0===e?void 0:e.getDirectory)?[3,2]:[4,s()];case 1:return t.sent(),[3,3];case 2:void 0!==navigator.maxTouchPoints?function(){var e=String(Math.random());try{var t=indexedDB.open(e,1);t.onupgradeneeded=function(t){var n=t.target.result,r=function(e){i(e)};try{n.createObjectStore("t",{autoIncrement:!0}).put(new Blob),r(!1)}catch(e){(e instanceof Error&&"string"==typeof e.message?e.message:String(e)).includes("are not yet supported")?r(!0):r(!1)}finally{n.close(),indexedDB.deleteDatabase(e)}},t.onerror=function(){return i(!1)}}catch(e){i(!1)}}():function(){var e=window.openDatabase,t=window.localStorage;try{e(null,null,null,null)}catch(e){return void i(!0)}try{t.setItem("test","1"),t.removeItem("test")}catch(e){return void i(!0)}i(!1)}(),t.label=3;case 3:return[2]}})})}function l(){var e;return n(this,void 0,Promise,function(){var t,n,o;return r(this,function(r){switch(r.label){case 0:if("function"!=typeof(null===(e=navigator.storage)||void 0===e?void 0:e.getDirectory))return[3,5];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,navigator.storage.getDirectory()];case 2:return r.sent(),i(!1),[3,4];case 3:return t=r.sent(),n=t instanceof Error&&"string"==typeof t.message?t.message:String(t),i(n.includes("Security error")),[2];case 4:return[3,6];case 5:(o=indexedDB.open("inPrivate")).onerror=function(e){o.error&&"InvalidStateError"===o.error.name&&e.preventDefault(),i(!0)},o.onsuccess=function(){indexedDB.deleteDatabase("inPrivate"),i(!1)},r.label=6;case 6:return[2]}})})}(function(){return n(this,void 0,Promise,function(){return r(this,function(e){switch(e.label){case 0:return 44!==c()&&43!==c()?[3,2]:(o="Safari",[4,u()]);case 1:return e.sent(),[3,6];case 2:return 51!==c()?[3,3]:(a=navigator.userAgent,o=a.match(/Chrome/)?void 0!==navigator.brave?"Brave":a.match(/Edg/)?"Edge":a.match(/OPR/)?"Opera":"Chrome":"Chromium",function(){var e=this,t="__di_"+Math.random().toString(36).slice(2),o=new Uint8Array(16384),a=indexedDB.open(t,1);a.onupgradeneeded=function(){a.result.createObjectStore("s")},a.onerror=function(){indexedDB.deleteDatabase(t),i(!1)},a.onsuccess=function(){var c=a.result,s=!1;try{var u=c.transaction("s","readwrite",{durability:"strict"});s="strict"===u.durability,u.abort()}catch(e){}if(!s)return c.close(),indexedDB.deleteDatabase(t),void i(!1);var l=function(e){return new Promise(function(t,n){var r=performance.now(),a=0,i=function(){if(15!==a){var s=c.transaction("s","readwrite",{durability:e});s.objectStore("s").put(o,a),a++,s.oncomplete=i,s.onerror=s.onabort=function(){return n(s.error)}}else t(performance.now()-r)};i()})};n(e,void 0,void 0,function(){var e,n,o,a,s;return r(this,function(r){switch(r.label){case 0:return e=performance.now(),[4,l("relaxed")];case 1:return r.sent(),[4,l("strict")];case 2:r.sent(),n=[],o=0,r.label=3;case 3:return o<15?[4,l("relaxed")]:[3,7];case 4:return a=r.sent(),[4,l("strict")];case 5:if(s=r.sent(),n.push(a>0?s/a:1/0),n.length>=7&&performance.now()-e>=1e3)return[3,7];r.label=6;case 6:return o++,[3,3];case 7:return n.sort(function(e,t){return e-t}),c.close(),indexedDB.deleteDatabase(t),i(n[n.length>>1]<1.3),[2]}})}).catch(function(){c.close(),indexedDB.deleteDatabase(t),i(!1)})}}(),[3,6]);case 3:return 25!==c()?[3,5]:(o="Firefox",[4,l()]);case 4:return e.sent(),[3,6];case 5:void 0!==navigator.msSaveBlob?(o="Internet Explorer",i(void 0===window.indexedDB)):t(new Error("detectIncognito cannot determine the browser")),e.label=6;case 6:return[2]}var a})})})().catch(t)})];case 1:return[2,e.sent()]}})})}Object.defineProperty(t,"__esModule",{value:!0}),t.detectIncognito=void 0,t.detectIncognito=o,"undefined"!=typeof window&&(window.detectIncognito=o),t.default=o}}[598].call(e,0,e),e=e.default}()});