123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- import { inboundFiltersIntegration, functionToStringIntegration, getIntegrationsToSetup, initAndBind, getReportDialogEndpoint, getCurrentHub, startSession, captureSession, getClient } from '@sentry/core';
- import { stackParserFromStackParserOptions, supportsFetch, logger, addHistoryInstrumentationHandler } from '@sentry/utils';
- import { BrowserClient } from './client.js';
- import { DEBUG_BUILD } from './debug-build.js';
- import { WINDOW, wrap as wrap$1 } from './helpers.js';
- import { breadcrumbsIntegration } from './integrations/breadcrumbs.js';
- import { dedupeIntegration } from './integrations/dedupe.js';
- import { globalHandlersIntegration } from './integrations/globalhandlers.js';
- import { httpContextIntegration } from './integrations/httpcontext.js';
- import { linkedErrorsIntegration } from './integrations/linkederrors.js';
- import { browserApiErrorsIntegration } from './integrations/trycatch.js';
- import { defaultStackParser } from './stack-parsers.js';
- import { makeFetchTransport } from './transports/fetch.js';
- import { makeXHRTransport } from './transports/xhr.js';
- const defaultIntegrations = [
- inboundFiltersIntegration(),
- functionToStringIntegration(),
- browserApiErrorsIntegration(),
- breadcrumbsIntegration(),
- globalHandlersIntegration(),
- linkedErrorsIntegration(),
- dedupeIntegration(),
- 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 (WINDOW.SENTRY_RELEASE && WINDOW.SENTRY_RELEASE.id) {
- options.release = WINDOW.SENTRY_RELEASE.id;
- }
- }
- if (options.autoSessionTracking === undefined) {
- options.autoSessionTracking = true;
- }
- if (options.sendClientReports === undefined) {
- options.sendClientReports = true;
- }
- const clientOptions = {
- ...options,
- stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),
- integrations: getIntegrationsToSetup(options),
- transport: options.transport || (supportsFetch() ? makeFetchTransport : makeXHRTransport),
- };
- initAndBind(BrowserClient, clientOptions);
- if (options.autoSessionTracking) {
- startSessionTracking();
- }
- }
- const showReportDialog = (
-
- options = {},
-
- hub = getCurrentHub(),
- ) => {
-
- if (!WINDOW.document) {
- DEBUG_BUILD && logger.error('Global document not defined in showReportDialog call');
- return;
- }
-
- const { client, scope } = hub.getStackTop();
- const dsn = options.dsn || (client && client.getDsn());
- if (!dsn) {
- DEBUG_BUILD && 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 = WINDOW.document.createElement('script');
- script.async = true;
- script.crossOrigin = 'anonymous';
- script.src = 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 {
- WINDOW.removeEventListener('message', reportDialogClosedMessageHandler);
- }
- }
- };
- WINDOW.addEventListener('message', reportDialogClosedMessageHandler);
- }
- const injectionPoint = WINDOW.document.head || WINDOW.document.body;
- if (injectionPoint) {
- injectionPoint.appendChild(script);
- } else {
- DEBUG_BUILD && logger.error('Not injecting report dialog. No injection point found in HTML');
- }
- };
- function forceLoad() {
-
- }
- function onLoad(callback) {
- callback();
- }
- function wrap(fn) {
- return wrap$1(fn)();
- }
- function startSessionTracking() {
- if (typeof WINDOW.document === 'undefined') {
- DEBUG_BUILD && logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
- return;
- }
-
-
-
-
- startSession({ ignoreDuration: true });
- captureSession();
-
- addHistoryInstrumentationHandler(({ from, to }) => {
-
- if (from !== undefined && from !== to) {
- startSession({ ignoreDuration: true });
- captureSession();
- }
- });
- }
- function captureUserFeedback(feedback) {
- const client = getClient();
- if (client) {
- client.captureUserFeedback(feedback);
- }
- }
- export { captureUserFeedback, defaultIntegrations, forceLoad, getDefaultIntegrations, init, onLoad, showReportDialog, wrap };
|