@sentry/browser
Version:
Official Sentry SDK for browsers
29 lines (28 loc) • 1.26 kB
JavaScript
import { DEBUG_BUILD } from "../debug-build.js";
import { WINDOW } from "../helpers.js";
import { consoleSandbox } from "@sentry/core";
import { getLocationHref } from "@sentry/browser-utils";
// src/utils/detectBrowserExtension.ts
/**
* Returns true if the SDK is running in an embedded browser extension.
* Stand-alone browser extensions (which do not share the same data as the main browser page) are fine.
*/
function checkAndWarnIfIsEmbeddedBrowserExtension() {
if (_isEmbeddedBrowserExtension()) {
if (DEBUG_BUILD) consoleSandbox(() => {
console.error("[Sentry] You cannot use Sentry.init() in a browser extension, see: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/");
});
return true;
}
return false;
}
function _isEmbeddedBrowserExtension() {
if (typeof WINDOW.window === "undefined") return false;
const _window = WINDOW;
if (_window.nw) return false;
if (!(_window["chrome"] || _window["browser"])?.runtime?.id) return false;
const href = getLocationHref();
return !(WINDOW === WINDOW.top && /^(?:chrome-extension|moz-extension|ms-browser-extension|safari-web-extension):\/\//.test(href));
}
export { checkAndWarnIfIsEmbeddedBrowserExtension };
//# sourceMappingURL=detectBrowserExtension.js.map