1 | Object.defineProperty(exports, '__esModule', { value: true });
|
2 |
|
3 | const core = require('@sentry/core');
|
4 | const utils = require('@sentry/utils');
|
5 | const eventbuilder = require('./eventbuilder.js');
|
6 | const helpers = require('./helpers.js');
|
7 | const breadcrumbs = require('./integrations/breadcrumbs.js');
|
8 | const userfeedback = require('./userfeedback.js');
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | class BrowserClient extends core.BaseClient {
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 | constructor(options) {
|
28 | const sdkSource = helpers.WINDOW.SENTRY_SDK_SOURCE || utils.getSDKSource();
|
29 |
|
30 | options._metadata = options._metadata || {};
|
31 | options._metadata.sdk = options._metadata.sdk || {
|
32 | name: 'sentry.javascript.browser',
|
33 | packages: [
|
34 | {
|
35 | name: `${sdkSource}:@sentry/browser`,
|
36 | version: core.SDK_VERSION,
|
37 | },
|
38 | ],
|
39 | version: core.SDK_VERSION,
|
40 | };
|
41 |
|
42 | super(options);
|
43 |
|
44 | if (options.sendClientReports && helpers.WINDOW.document) {
|
45 | helpers.WINDOW.document.addEventListener('visibilitychange', () => {
|
46 | if (helpers.WINDOW.document.visibilityState === 'hidden') {
|
47 | this._flushOutcomes();
|
48 | }
|
49 | });
|
50 | }
|
51 | }
|
52 |
|
53 | |
54 |
|
55 |
|
56 | eventFromException(exception, hint) {
|
57 | return eventbuilder.eventFromException(this._options.stackParser, exception, hint, this._options.attachStacktrace);
|
58 | }
|
59 |
|
60 | |
61 |
|
62 |
|
63 | eventFromMessage(
|
64 | message,
|
65 |
|
66 | level = 'info',
|
67 | hint,
|
68 | ) {
|
69 | return eventbuilder.eventFromMessage(this._options.stackParser, message, level, hint, this._options.attachStacktrace);
|
70 | }
|
71 |
|
72 | |
73 |
|
74 |
|
75 | sendEvent(event, hint) {
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | const breadcrumbIntegration = this.getIntegrationById(breadcrumbs.BREADCRUMB_INTEGRATION_ID) ;
|
83 |
|
84 |
|
85 | if (breadcrumbIntegration && breadcrumbIntegration.addSentryBreadcrumb) {
|
86 | breadcrumbIntegration.addSentryBreadcrumb(event);
|
87 | }
|
88 |
|
89 | super.sendEvent(event, hint);
|
90 | }
|
91 |
|
92 | |
93 |
|
94 |
|
95 | captureUserFeedback(feedback) {
|
96 | if (!this._isEnabled()) {
|
97 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.warn('SDK not enabled, will not capture user feedback.');
|
98 | return;
|
99 | }
|
100 |
|
101 | const envelope = userfeedback.createUserFeedbackEnvelope(feedback, {
|
102 | metadata: this.getSdkMetadata(),
|
103 | dsn: this.getDsn(),
|
104 | tunnel: this.getOptions().tunnel,
|
105 | });
|
106 | void this._sendEnvelope(envelope);
|
107 | }
|
108 |
|
109 | |
110 |
|
111 |
|
112 | _prepareEvent(event, hint, scope) {
|
113 | event.platform = event.platform || 'javascript';
|
114 | return super._prepareEvent(event, hint, scope);
|
115 | }
|
116 |
|
117 | |
118 |
|
119 |
|
120 | _flushOutcomes() {
|
121 | const outcomes = this._clearOutcomes();
|
122 |
|
123 | if (outcomes.length === 0) {
|
124 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('No outcomes to send');
|
125 | return;
|
126 | }
|
127 |
|
128 | if (!this._dsn) {
|
129 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('No dsn provided, will not send outcomes');
|
130 | return;
|
131 | }
|
132 |
|
133 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.log('Sending outcomes:', outcomes);
|
134 |
|
135 | const envelope = utils.createClientReportEnvelope(outcomes, this._options.tunnel && utils.dsnToString(this._dsn));
|
136 | void this._sendEnvelope(envelope);
|
137 | }
|
138 | }
|
139 |
|
140 | exports.BrowserClient = BrowserClient;
|
141 |
|