{"version":3,"file":"detectBrowserExtension.js","sources":["../../../../../src/utils/detectBrowserExtension.ts"],"sourcesContent":["import { consoleSandbox, getLocationHref } from '@sentry/core/browser';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { WINDOW } from '../helpers';\n\ntype ExtensionRuntime = {\n runtime?: {\n id?: string;\n };\n};\ntype ExtensionProperties = {\n chrome?: ExtensionRuntime;\n browser?: ExtensionRuntime;\n nw?: unknown;\n};\n\n/**\n * Returns true if the SDK is running in an embedded browser extension.\n * Stand-alone browser extensions (which do not share the same data as the main browser page) are fine.\n */\nexport function checkAndWarnIfIsEmbeddedBrowserExtension(): boolean {\n if (_isEmbeddedBrowserExtension()) {\n if (DEBUG_BUILD) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.error(\n '[Sentry] You cannot use Sentry.init() in a browser extension, see: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/',\n );\n });\n }\n\n return true;\n }\n\n return false;\n}\n\nfunction _isEmbeddedBrowserExtension(): boolean {\n if (typeof WINDOW.window === 'undefined') {\n // No need to show the error if we're not in a browser window environment (e.g. service workers)\n return false;\n }\n\n const _window = WINDOW as typeof WINDOW & ExtensionProperties;\n\n // Running the SDK in NW.js, which appears like a browser extension but isn't, is also fine\n // see: https://github.com/getsentry/sentry-javascript/issues/12668\n if (_window.nw) {\n return false;\n }\n\n const extensionObject = _window['chrome'] || _window['browser'];\n\n if (!extensionObject?.runtime?.id) {\n return false;\n }\n\n const href = getLocationHref();\n\n // Running the SDK in a dedicated extension page and calling Sentry.init is fine; no risk of data leakage\n const isDedicatedExtensionPage =\n WINDOW === WINDOW.top &&\n /^(?:chrome-extension|moz-extension|ms-browser-extension|safari-web-extension):\\/\\//.test(href);\n\n return !isDedicatedExtensionPage;\n}\n"],"names":[],"mappings":";;;;AAmBO,SAAS,wCAAA,GAAoD;AAClE,EAAA,IAAI,6BAA4B,EAAG;AACjC,IAAA,IAAI,WAAA,EAAa;AACf,MAAA,cAAA,CAAe,MAAM;AAEnB,QAAA,OAAA,CAAQ,KAAA;AAAA,UACN;AAAA,SACF;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAEA,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,2BAAA,GAAuC;AAC9C,EAAA,IAAI,OAAO,MAAA,CAAO,MAAA,KAAW,WAAA,EAAa;AAExC,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,OAAA,GAAU,MAAA;AAIhB,EAAA,IAAI,QAAQ,EAAA,EAAI;AACd,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,eAAA,GAAkB,OAAA,CAAQ,QAAQ,CAAA,IAAK,QAAQ,SAAS,CAAA;AAE9D,EAAA,IAAI,CAAC,eAAA,EAAiB,OAAA,EAAS,EAAA,EAAI;AACjC,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,OAAO,eAAA,EAAgB;AAG7B,EAAA,MAAM,2BACJ,MAAA,KAAW,MAAA,CAAO,GAAA,IAClB,oFAAA,CAAqF,KAAK,IAAI,CAAA;AAEhG,EAAA,OAAO,CAAC,wBAAA;AACV;;;;"}