1
- import type { Client , Integration , Options , ReportDialogOptions } from '@sentry/core' ;
1
+ import { Client , Integration , Options , ReportDialogOptions , getClient } from '@sentry/core' ;
2
2
import {
3
3
consoleSandbox ,
4
4
dedupeIntegration ,
@@ -12,7 +12,6 @@ import {
12
12
lastEventId ,
13
13
logger ,
14
14
stackParserFromStackParserOptions ,
15
- supportsFetch ,
16
15
} from '@sentry/core' ;
17
16
import type { BrowserClientOptions , BrowserOptions } from './client' ;
18
17
import { BrowserClient } from './client' ;
@@ -27,6 +26,22 @@ import { linkedErrorsIntegration } from './integrations/linkederrors';
27
26
import { defaultStackParser } from './stack-parsers' ;
28
27
import { makeFetchTransport } from './transports/fetch' ;
29
28
29
+ type ExtensionProperties = {
30
+ chrome ?: Runtime ;
31
+ browser ?: Runtime ;
32
+ nw ?: unknown ;
33
+ } ;
34
+ type Runtime = {
35
+ runtime ?: {
36
+ id ?: string ;
37
+ } ;
38
+ } ;
39
+
40
+ /**
41
+ * A magic string that build tooling can leverage in order to inject a release value into the SDK.
42
+ */
43
+ declare const __SENTRY_RELEASE__ : string | undefined ;
44
+
30
45
/** Get the default integrations for the browser SDK. */
31
46
export function getDefaultIntegrations ( _options : Options ) : Integration [ ] {
32
47
/**
@@ -64,22 +79,6 @@ export function applyDefaultOptions(optionsArg: BrowserOptions): BrowserOptions
64
79
} ;
65
80
}
66
81
67
- type ExtensionProperties = {
68
- chrome ?: Runtime ;
69
- browser ?: Runtime ;
70
- nw ?: unknown ;
71
- } ;
72
- type Runtime = {
73
- runtime ?: {
74
- id ?: string ;
75
- } ;
76
- } ;
77
-
78
- /**
79
- * A magic string that build tooling can leverage in order to inject a release value into the SDK.
80
- */
81
- declare const __SENTRY_RELEASE__ : string | undefined ;
82
-
83
82
/**
84
83
* The Sentry Browser SDK Client.
85
84
*
@@ -127,7 +126,7 @@ declare const __SENTRY_RELEASE__: string | undefined;
127
126
* @see {@link BrowserOptions } for documentation on configuration options.
128
127
*/
129
128
export function init ( browserOptions : BrowserOptions = { } ) : Client | undefined {
130
- if ( _checkBailForBrowserExtension ( browserOptions ) ) {
129
+ if ( ! browserOptions . skipBrowserExtensionCheck && _checkForBrowserExtension ( ) ) {
131
130
return ;
132
131
}
133
132
return _init ( browserOptions , getDefaultIntegrations ( browserOptions ) ) ;
@@ -145,7 +144,7 @@ export function initWithDefaultIntegrations(
145
144
browserOptions : BrowserOptions = { } ,
146
145
getDefaultIntegrationsImpl : ( options : BrowserOptions ) => Integration [ ] ,
147
146
) : BrowserClient | undefined {
148
- if ( _checkBailForBrowserExtension ( browserOptions ) ) {
147
+ if ( ! browserOptions . skipBrowserExtensionCheck && _checkForBrowserExtension ( ) ) {
149
148
return ;
150
149
}
151
150
@@ -174,32 +173,31 @@ export function showReportDialog(options: ReportDialogOptions = {}): void {
174
173
}
175
174
176
175
const scope = getCurrentScope ( ) ;
177
- const client = scope . getClient ( ) ;
176
+ const client = getClient ( ) ;
178
177
const dsn = client ?. getDsn ( ) ;
179
178
180
179
if ( ! dsn ) {
181
180
DEBUG_BUILD && logger . error ( 'DSN not configured for showReportDialog call' ) ;
182
181
return ;
183
182
}
184
183
185
- if ( scope ) {
186
- options . user = {
184
+ options . user = {
185
+ ...scope . getUser ( ) ,
186
+ ...options . user ,
187
+ } ;
188
+
189
+ const mergedOptions = {
190
+ user : {
187
191
...scope . getUser ( ) ,
188
192
...options . user ,
189
- } ;
190
- }
191
-
192
- if ( ! options . eventId ) {
193
- const eventId = lastEventId ( ) ;
194
- if ( eventId ) {
195
- options . eventId = eventId ;
196
- }
197
- }
193
+ } ,
194
+ eventId : options . eventId || lastEventId ( ) ,
195
+ } ;
198
196
199
197
const script = WINDOW . document . createElement ( 'script' ) ;
200
198
script . async = true ;
201
199
script . crossOrigin = 'anonymous' ;
202
- script . src = getReportDialogEndpoint ( dsn , options ) ;
200
+ script . src = getReportDialogEndpoint ( dsn , mergedOptions ) ;
203
201
204
202
if ( options . onLoad ) {
205
203
script . onload = options . onLoad ;
@@ -243,7 +241,7 @@ export function onLoad(callback: () => void): void {
243
241
callback ( ) ;
244
242
}
245
243
246
- function shouldShowBrowserExtensionError ( ) : boolean {
244
+ function _isEmbeddedBrowserExtension ( ) : boolean {
247
245
if ( typeof WINDOW . window === 'undefined' ) {
248
246
// No need to show the error if we're not in a browser window environment (e.g. service workers)
249
247
return false ;
@@ -273,15 +271,13 @@ function shouldShowBrowserExtensionError(): boolean {
273
271
return ! isDedicatedExtensionPage ;
274
272
}
275
273
276
- function _checkBailForBrowserExtension ( options : BrowserOptions ) : true | void {
277
- const isBrowserExtension = ! options . skipBrowserExtensionCheck && shouldShowBrowserExtensionError ( ) ;
278
-
279
- if ( isBrowserExtension ) {
274
+ function _checkForBrowserExtension ( ) : true | void {
275
+ if ( _isEmbeddedBrowserExtension ( ) ) {
280
276
if ( DEBUG_BUILD ) {
281
277
consoleSandbox ( ( ) => {
282
278
// eslint-disable-next-line no-console
283
279
console . error (
284
- '[Sentry] You cannot run Sentry this way in a browser extension, check : https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/' ,
280
+ '[Sentry] You cannot use Sentry.init() in a browser extension, see : https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/' ,
285
281
) ;
286
282
} ) ;
287
283
}
0 commit comments