1- import type { Client , Integration , Options , ReportDialogOptions } from '@sentry/core' ;
1+ import { Client , Integration , Options , ReportDialogOptions , getClient } from '@sentry/core' ;
22import {
33 consoleSandbox ,
44 dedupeIntegration ,
@@ -12,7 +12,6 @@ import {
1212 lastEventId ,
1313 logger ,
1414 stackParserFromStackParserOptions ,
15- supportsFetch ,
1615} from '@sentry/core' ;
1716import type { BrowserClientOptions , BrowserOptions } from './client' ;
1817import { BrowserClient } from './client' ;
@@ -27,6 +26,22 @@ import { linkedErrorsIntegration } from './integrations/linkederrors';
2726import { defaultStackParser } from './stack-parsers' ;
2827import { makeFetchTransport } from './transports/fetch' ;
2928
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+
3045/** Get the default integrations for the browser SDK. */
3146export function getDefaultIntegrations ( _options : Options ) : Integration [ ] {
3247 /**
@@ -64,22 +79,6 @@ export function applyDefaultOptions(optionsArg: BrowserOptions): BrowserOptions
6479 } ;
6580}
6681
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-
8382/**
8483 * The Sentry Browser SDK Client.
8584 *
@@ -127,7 +126,7 @@ declare const __SENTRY_RELEASE__: string | undefined;
127126 * @see {@link BrowserOptions } for documentation on configuration options.
128127 */
129128export function init ( browserOptions : BrowserOptions = { } ) : Client | undefined {
130- if ( _checkBailForBrowserExtension ( browserOptions ) ) {
129+ if ( ! browserOptions . skipBrowserExtensionCheck && _checkForBrowserExtension ( ) ) {
131130 return ;
132131 }
133132 return _init ( browserOptions , getDefaultIntegrations ( browserOptions ) ) ;
@@ -145,7 +144,7 @@ export function initWithDefaultIntegrations(
145144 browserOptions : BrowserOptions = { } ,
146145 getDefaultIntegrationsImpl : ( options : BrowserOptions ) => Integration [ ] ,
147146) : BrowserClient | undefined {
148- if ( _checkBailForBrowserExtension ( browserOptions ) ) {
147+ if ( ! browserOptions . skipBrowserExtensionCheck && _checkForBrowserExtension ( ) ) {
149148 return ;
150149 }
151150
@@ -174,32 +173,31 @@ export function showReportDialog(options: ReportDialogOptions = {}): void {
174173 }
175174
176175 const scope = getCurrentScope ( ) ;
177- const client = scope . getClient ( ) ;
176+ const client = getClient ( ) ;
178177 const dsn = client ?. getDsn ( ) ;
179178
180179 if ( ! dsn ) {
181180 DEBUG_BUILD && logger . error ( 'DSN not configured for showReportDialog call' ) ;
182181 return ;
183182 }
184183
185- if ( scope ) {
186- options . user = {
184+ options . user = {
185+ ...scope . getUser ( ) ,
186+ ...options . user ,
187+ } ;
188+
189+ const mergedOptions = {
190+ user : {
187191 ...scope . getUser ( ) ,
188192 ...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+ } ;
198196
199197 const script = WINDOW . document . createElement ( 'script' ) ;
200198 script . async = true ;
201199 script . crossOrigin = 'anonymous' ;
202- script . src = getReportDialogEndpoint ( dsn , options ) ;
200+ script . src = getReportDialogEndpoint ( dsn , mergedOptions ) ;
203201
204202 if ( options . onLoad ) {
205203 script . onload = options . onLoad ;
@@ -243,7 +241,7 @@ export function onLoad(callback: () => void): void {
243241 callback ( ) ;
244242}
245243
246- function shouldShowBrowserExtensionError ( ) : boolean {
244+ function _isEmbeddedBrowserExtension ( ) : boolean {
247245 if ( typeof WINDOW . window === 'undefined' ) {
248246 // No need to show the error if we're not in a browser window environment (e.g. service workers)
249247 return false ;
@@ -273,15 +271,13 @@ function shouldShowBrowserExtensionError(): boolean {
273271 return ! isDedicatedExtensionPage ;
274272}
275273
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 ( ) ) {
280276 if ( DEBUG_BUILD ) {
281277 consoleSandbox ( ( ) => {
282278 // eslint-disable-next-line no-console
283279 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/' ,
285281 ) ;
286282 } ) ;
287283 }
0 commit comments