All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.build.npm.esm.sdk.js.map Maven / Gradle / Ivy

There is a newer version: 8.40.0
Show newest version
{"version":3,"file":"sdk.js","sources":["../../../src/sdk.ts"],"sourcesContent":["import { getCurrentScope } from '@sentry/core';\nimport { functionToStringIntegration, inboundFiltersIntegration } from '@sentry/core';\nimport {\n  captureSession,\n  getClient,\n  getIntegrationsToSetup,\n  getReportDialogEndpoint,\n  initAndBind,\n  lastEventId,\n  startSession,\n} from '@sentry/core';\nimport type { Client, DsnLike, Integration, Options, UserFeedback } from '@sentry/types';\nimport { consoleSandbox, logger, stackParserFromStackParserOptions, supportsFetch } from '@sentry/utils';\n\nimport { addHistoryInstrumentationHandler } from '@sentry-internal/browser-utils';\nimport { dedupeIntegration } from '@sentry/core';\nimport type { BrowserClientOptions, BrowserOptions } from './client';\nimport { BrowserClient } from './client';\nimport { DEBUG_BUILD } from './debug-build';\nimport { WINDOW } from './helpers';\nimport { breadcrumbsIntegration } from './integrations/breadcrumbs';\nimport { browserApiErrorsIntegration } from './integrations/browserapierrors';\nimport { globalHandlersIntegration } from './integrations/globalhandlers';\nimport { httpContextIntegration } from './integrations/httpcontext';\nimport { linkedErrorsIntegration } from './integrations/linkederrors';\nimport { defaultStackParser } from './stack-parsers';\nimport { makeFetchTransport } from './transports/fetch';\n\n/** Get the default integrations for the browser SDK. */\nexport function getDefaultIntegrations(_options: Options): Integration[] {\n  /**\n   * Note: Please make sure this stays in sync with Angular SDK, which re-exports\n   * `getDefaultIntegrations` but with an adjusted set of integrations.\n   */\n  return [\n    inboundFiltersIntegration(),\n    functionToStringIntegration(),\n    browserApiErrorsIntegration(),\n    breadcrumbsIntegration(),\n    globalHandlersIntegration(),\n    linkedErrorsIntegration(),\n    dedupeIntegration(),\n    httpContextIntegration(),\n  ];\n}\n\nfunction applyDefaultOptions(optionsArg: BrowserOptions = {}): BrowserOptions {\n  const defaultOptions: BrowserOptions = {\n    defaultIntegrations: getDefaultIntegrations(optionsArg),\n    release:\n      typeof __SENTRY_RELEASE__ === 'string' // This allows build tooling to find-and-replace __SENTRY_RELEASE__ to inject a release value\n        ? __SENTRY_RELEASE__\n        : WINDOW.SENTRY_RELEASE && WINDOW.SENTRY_RELEASE.id // This supports the variable that sentry-webpack-plugin injects\n          ? WINDOW.SENTRY_RELEASE.id\n          : undefined,\n    autoSessionTracking: true,\n    sendClientReports: true,\n  };\n\n  // TODO: Instead of dropping just `defaultIntegrations`, we should simply\n  // call `dropUndefinedKeys` on the entire `optionsArg`.\n  // However, for this to work we need to adjust the `hasTracingEnabled()` logic\n  // first as it differentiates between `undefined` and the key not being in the object.\n  if (optionsArg.defaultIntegrations == null) {\n    delete optionsArg.defaultIntegrations;\n  }\n\n  return { ...defaultOptions, ...optionsArg };\n}\n\ntype ExtensionProperties = {\n  chrome?: Runtime;\n  browser?: Runtime;\n  nw?: unknown;\n};\ntype Runtime = {\n  runtime?: {\n    id?: string;\n  };\n};\n\nfunction shouldShowBrowserExtensionError(): boolean {\n  const windowWithMaybeExtension =\n    typeof WINDOW.window !== 'undefined' && (WINDOW as typeof WINDOW & ExtensionProperties);\n  if (!windowWithMaybeExtension) {\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 extensionKey = windowWithMaybeExtension.chrome ? 'chrome' : 'browser';\n  const extensionObject = windowWithMaybeExtension[extensionKey];\n\n  const runtimeId = extensionObject && extensionObject.runtime && extensionObject.runtime.id;\n  const href = (WINDOW.location && WINDOW.location.href) || '';\n\n  const extensionProtocols = ['chrome-extension:', 'moz-extension:', 'ms-browser-extension:', 'safari-web-extension:'];\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    !!runtimeId && WINDOW === WINDOW.top && extensionProtocols.some(protocol => href.startsWith(`${protocol}//`));\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  const isNWjs = typeof windowWithMaybeExtension.nw !== 'undefined';\n\n  return !!runtimeId && !isDedicatedExtensionPage && !isNWjs;\n}\n\n/**\n * A magic string that build tooling can leverage in order to inject a release value into the SDK.\n */\ndeclare const __SENTRY_RELEASE__: string | undefined;\n\n/**\n * The Sentry Browser SDK Client.\n *\n * To use this SDK, call the {@link init} function as early as possible when\n * loading the web page. To set context information or send manual events, use\n * the provided methods.\n *\n * @example\n *\n * ```\n *\n * import { init } from '@sentry/browser';\n *\n * init({\n *   dsn: '__DSN__',\n *   // ...\n * });\n * ```\n *\n * @example\n * ```\n *\n * import { addBreadcrumb } from '@sentry/browser';\n * addBreadcrumb({\n *   message: 'My Breadcrumb',\n *   // ...\n * });\n * ```\n *\n * @example\n *\n * ```\n *\n * import * as Sentry from '@sentry/browser';\n * Sentry.captureMessage('Hello, world!');\n * Sentry.captureException(new Error('Good bye'));\n * Sentry.captureEvent({\n *   message: 'Manual',\n *   stacktrace: [\n *     // ...\n *   ],\n * });\n * ```\n *\n * @see {@link BrowserOptions} for documentation on configuration options.\n */\nexport function init(browserOptions: BrowserOptions = {}): Client | undefined {\n  const options = applyDefaultOptions(browserOptions);\n\n  if (shouldShowBrowserExtensionError()) {\n    consoleSandbox(() => {\n      // eslint-disable-next-line no-console\n      console.error(\n        '[Sentry] You cannot run Sentry this way in a browser extension, check: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/',\n      );\n    });\n    return;\n  }\n\n  if (DEBUG_BUILD) {\n    if (!supportsFetch()) {\n      logger.warn(\n        'No Fetch API detected. The Sentry SDK requires a Fetch API compatible environment to send events. Please add a Fetch API polyfill.',\n      );\n    }\n  }\n  const clientOptions: BrowserClientOptions = {\n    ...options,\n    stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n    integrations: getIntegrationsToSetup(options),\n    transport: options.transport || makeFetchTransport,\n  };\n\n  const client = initAndBind(BrowserClient, clientOptions);\n\n  if (options.autoSessionTracking) {\n    startSessionTracking();\n  }\n\n  return client;\n}\n\n/**\n * All properties the report dialog supports\n */\nexport interface ReportDialogOptions {\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  [key: string]: any;\n  eventId?: string;\n  dsn?: DsnLike;\n  user?: {\n    email?: string;\n    name?: string;\n  };\n  lang?: string;\n  title?: string;\n  subtitle?: string;\n  subtitle2?: string;\n  labelName?: string;\n  labelEmail?: string;\n  labelComments?: string;\n  labelClose?: string;\n  labelSubmit?: string;\n  errorGeneric?: string;\n  errorFormEntry?: string;\n  successMessage?: string;\n  /** Callback after reportDialog showed up */\n  onLoad?(this: void): void;\n  /** Callback after reportDialog closed */\n  onClose?(this: void): void;\n}\n\n/**\n * Present the user with a report dialog.\n *\n * @param options Everything is optional, we try to fetch all info need from the global scope.\n */\nexport function showReportDialog(options: ReportDialogOptions = {}): void {\n  // doesn't work without a document (React Native)\n  if (!WINDOW.document) {\n    DEBUG_BUILD && logger.error('Global document not defined in showReportDialog call');\n    return;\n  }\n\n  const scope = getCurrentScope();\n  const client = scope.getClient();\n  const dsn = client && client.getDsn();\n\n  if (!dsn) {\n    DEBUG_BUILD && logger.error('DSN not configured for showReportDialog call');\n    return;\n  }\n\n  if (scope) {\n    options.user = {\n      ...scope.getUser(),\n      ...options.user,\n    };\n  }\n\n  if (!options.eventId) {\n    const eventId = lastEventId();\n    if (eventId) {\n      options.eventId = eventId;\n    }\n  }\n\n  const script = WINDOW.document.createElement('script');\n  script.async = true;\n  script.crossOrigin = 'anonymous';\n  script.src = getReportDialogEndpoint(dsn, options);\n\n  if (options.onLoad) {\n    script.onload = options.onLoad;\n  }\n\n  const { onClose } = options;\n  if (onClose) {\n    const reportDialogClosedMessageHandler = (event: MessageEvent): void => {\n      if (event.data === '__sentry_reportdialog_closed__') {\n        try {\n          onClose();\n        } finally {\n          WINDOW.removeEventListener('message', reportDialogClosedMessageHandler);\n        }\n      }\n    };\n    WINDOW.addEventListener('message', reportDialogClosedMessageHandler);\n  }\n\n  const injectionPoint = WINDOW.document.head || WINDOW.document.body;\n  if (injectionPoint) {\n    injectionPoint.appendChild(script);\n  } else {\n    DEBUG_BUILD && logger.error('Not injecting report dialog. No injection point found in HTML');\n  }\n}\n\n/**\n * This function is here to be API compatible with the loader.\n * @hidden\n */\nexport function forceLoad(): void {\n  // Noop\n}\n\n/**\n * This function is here to be API compatible with the loader.\n * @hidden\n */\nexport function onLoad(callback: () => void): void {\n  callback();\n}\n\n/**\n * Enable automatic Session Tracking for the initial page load.\n */\nfunction startSessionTracking(): void {\n  if (typeof WINDOW.document === 'undefined') {\n    DEBUG_BUILD && logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');\n    return;\n  }\n\n  // The session duration for browser sessions does not track a meaningful\n  // concept that can be used as a metric.\n  // Automatically captured sessions are akin to page views, and thus we\n  // discard their duration.\n  startSession({ ignoreDuration: true });\n  captureSession();\n\n  // We want to create a session for every navigation as well\n  addHistoryInstrumentationHandler(({ from, to }) => {\n    // Don't create an additional session for the initial route or if the location did not change\n    if (from !== undefined && from !== to) {\n      startSession({ ignoreDuration: true });\n      captureSession();\n    }\n  });\n}\n\n/**\n * Captures user feedback and sends it to Sentry.\n *\n * @deprecated Use `captureFeedback` instead.\n */\nexport function captureUserFeedback(feedback: UserFeedback): void {\n  const client = getClient();\n  if (client) {\n    // eslint-disable-next-line deprecation/deprecation\n    client.captureUserFeedback(feedback);\n  }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AA4BA;AACO,SAAS,sBAAsB,CAAC,QAAQ,EAA0B;AACzE;AACA;AACA;AACA;AACA,EAAE,OAAO;AACT,IAAI,yBAAyB,EAAE;AAC/B,IAAI,2BAA2B,EAAE;AACjC,IAAI,2BAA2B,EAAE;AACjC,IAAI,sBAAsB,EAAE;AAC5B,IAAI,yBAAyB,EAAE;AAC/B,IAAI,uBAAuB,EAAE;AAC7B,IAAI,iBAAiB,EAAE;AACvB,IAAI,sBAAsB,EAAE;AAC5B,GAAG,CAAA;AACH,CAAA;AACA;AACA,SAAS,mBAAmB,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