import { BaseClient, applySdkMetadata } from '@sentry/core'; import { getSDKSource, logger, createClientReportEnvelope, dsnToString } from '@sentry/utils'; import { DEBUG_BUILD } from './debug-build.js'; import { eventFromException, eventFromMessage } from './eventbuilder.js'; import { WINDOW } from './helpers.js'; import { createUserFeedbackEnvelope } from './userfeedback.js'; /** * Configuration options for the Sentry Browser SDK. * @see @sentry/types Options for more information. */ /** * The Sentry Browser SDK Client. * * @see BrowserOptions for documentation on configuration options. * @see SentryClient for usage documentation. */ class BrowserClient extends BaseClient { /** * Creates a new Browser SDK instance. * * @param options Configuration options for this SDK. */ constructor(options) { const sdkSource = WINDOW.SENTRY_SDK_SOURCE || getSDKSource(); applySdkMetadata(options, 'browser', ['browser'], sdkSource); super(options); if (options.sendClientReports && WINDOW.document) { WINDOW.document.addEventListener('visibilitychange', () => { if (WINDOW.document.visibilityState === 'hidden') { this._flushOutcomes(); } }); } } /** * @inheritDoc */ eventFromException(exception, hint) { return eventFromException(this._options.stackParser, exception, hint, this._options.attachStacktrace); } /** * @inheritDoc */ eventFromMessage( message, // eslint-disable-next-line deprecation/deprecation level = 'info', hint, ) { return eventFromMessage(this._options.stackParser, message, level, hint, this._options.attachStacktrace); } /** * Sends user feedback to Sentry. */ captureUserFeedback(feedback) { if (!this._isEnabled()) { DEBUG_BUILD && logger.warn('SDK not enabled, will not capture user feedback.'); return; } const envelope = createUserFeedbackEnvelope(feedback, { metadata: this.getSdkMetadata(), dsn: this.getDsn(), tunnel: this.getOptions().tunnel, }); // _sendEnvelope should not throw // eslint-disable-next-line @typescript-eslint/no-floating-promises this._sendEnvelope(envelope); } /** * @inheritDoc */ _prepareEvent(event, hint, scope) { event.platform = event.platform || 'javascript'; return super._prepareEvent(event, hint, scope); } /** * Sends client reports as an envelope. */ _flushOutcomes() { const outcomes = this._clearOutcomes(); if (outcomes.length === 0) { DEBUG_BUILD && logger.log('No outcomes to send'); return; } // This is really the only place where we want to check for a DSN and only send outcomes then if (!this._dsn) { DEBUG_BUILD && logger.log('No dsn provided, will not send outcomes'); return; } DEBUG_BUILD && logger.log('Sending outcomes:', outcomes); const envelope = createClientReportEnvelope(outcomes, this._options.tunnel && dsnToString(this._dsn)); // _sendEnvelope should not throw // eslint-disable-next-line @typescript-eslint/no-floating-promises this._sendEnvelope(envelope); } } export { BrowserClient }; //# sourceMappingURL=client.js.map