123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- Object.defineProperty(exports, '__esModule', { value: true });
- const core = require('@sentry/core');
- const utils = require('@sentry/utils');
- const client = require('./client.js');
- const debugBuild = require('./debug-build.js');
- const helpers = require('./helpers.js');
- const breadcrumbs = require('./integrations/breadcrumbs.js');
- const dedupe = require('./integrations/dedupe.js');
- const globalhandlers = require('./integrations/globalhandlers.js');
- const httpcontext = require('./integrations/httpcontext.js');
- const linkederrors = require('./integrations/linkederrors.js');
- const trycatch = require('./integrations/trycatch.js');
- const stackParsers = require('./stack-parsers.js');
- const fetch = require('./transports/fetch.js');
- const xhr = require('./transports/xhr.js');
- const defaultIntegrations = [
- core.inboundFiltersIntegration(),
- core.functionToStringIntegration(),
- trycatch.browserApiErrorsIntegration(),
- breadcrumbs.breadcrumbsIntegration(),
- globalhandlers.globalHandlersIntegration(),
- linkederrors.linkedErrorsIntegration(),
- dedupe.dedupeIntegration(),
- httpcontext.httpContextIntegration(),
- ];
- function getDefaultIntegrations(_options) {
-
- return [
-
- ...defaultIntegrations,
- ];
- }
- function init(options = {}) {
- if (options.defaultIntegrations === undefined) {
- options.defaultIntegrations = getDefaultIntegrations();
- }
- if (options.release === undefined) {
-
- if (typeof __SENTRY_RELEASE__ === 'string') {
- options.release = __SENTRY_RELEASE__;
- }
-
- if (helpers.WINDOW.SENTRY_RELEASE && helpers.WINDOW.SENTRY_RELEASE.id) {
- options.release = helpers.WINDOW.SENTRY_RELEASE.id;
- }
- }
- if (options.autoSessionTracking === undefined) {
- options.autoSessionTracking = true;
- }
- if (options.sendClientReports === undefined) {
- options.sendClientReports = true;
- }
- const clientOptions = {
- ...options,
- stackParser: utils.stackParserFromStackParserOptions(options.stackParser || stackParsers.defaultStackParser),
- integrations: core.getIntegrationsToSetup(options),
- transport: options.transport || (utils.supportsFetch() ? fetch.makeFetchTransport : xhr.makeXHRTransport),
- };
- core.initAndBind(client.BrowserClient, clientOptions);
- if (options.autoSessionTracking) {
- startSessionTracking();
- }
- }
- const showReportDialog = (
-
- options = {},
-
- hub = core.getCurrentHub(),
- ) => {
-
- if (!helpers.WINDOW.document) {
- debugBuild.DEBUG_BUILD && utils.logger.error('Global document not defined in showReportDialog call');
- return;
- }
-
- const { client, scope } = hub.getStackTop();
- const dsn = options.dsn || (client && client.getDsn());
- if (!dsn) {
- debugBuild.DEBUG_BUILD && utils.logger.error('DSN not configured for showReportDialog call');
- return;
- }
- if (scope) {
- options.user = {
- ...scope.getUser(),
- ...options.user,
- };
- }
-
-
- if (!options.eventId) {
-
- options.eventId = hub.lastEventId();
- }
- const script = helpers.WINDOW.document.createElement('script');
- script.async = true;
- script.crossOrigin = 'anonymous';
- script.src = core.getReportDialogEndpoint(dsn, options);
- if (options.onLoad) {
- script.onload = options.onLoad;
- }
- const { onClose } = options;
- if (onClose) {
- const reportDialogClosedMessageHandler = (event) => {
- if (event.data === '__sentry_reportdialog_closed__') {
- try {
- onClose();
- } finally {
- helpers.WINDOW.removeEventListener('message', reportDialogClosedMessageHandler);
- }
- }
- };
- helpers.WINDOW.addEventListener('message', reportDialogClosedMessageHandler);
- }
- const injectionPoint = helpers.WINDOW.document.head || helpers.WINDOW.document.body;
- if (injectionPoint) {
- injectionPoint.appendChild(script);
- } else {
- debugBuild.DEBUG_BUILD && utils.logger.error('Not injecting report dialog. No injection point found in HTML');
- }
- };
- function forceLoad() {
-
- }
- function onLoad(callback) {
- callback();
- }
- function wrap(fn) {
- return helpers.wrap(fn)();
- }
- function startSessionTracking() {
- if (typeof helpers.WINDOW.document === 'undefined') {
- debugBuild.DEBUG_BUILD && utils.logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
- return;
- }
-
-
-
-
- core.startSession({ ignoreDuration: true });
- core.captureSession();
-
- utils.addHistoryInstrumentationHandler(({ from, to }) => {
-
- if (from !== undefined && from !== to) {
- core.startSession({ ignoreDuration: true });
- core.captureSession();
- }
- });
- }
- function captureUserFeedback(feedback) {
- const client = core.getClient();
- if (client) {
- client.captureUserFeedback(feedback);
- }
- }
- exports.captureUserFeedback = captureUserFeedback;
- exports.defaultIntegrations = defaultIntegrations;
- exports.forceLoad = forceLoad;
- exports.getDefaultIntegrations = getDefaultIntegrations;
- exports.init = init;
- exports.onLoad = onLoad;
- exports.showReportDialog = showReportDialog;
- exports.wrap = wrap;
|