@@ -44,19 +44,13 @@ const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
4444 _sentryRelease ?: string ;
4545 _experimentalThirdPartyOriginStackFrames ?: string ;
4646 _sentrySpotlight ?: string ;
47- _sentrySpotlightManual ?: string ; // Debug: manually set by user in instrumentation-client.ts
4847} ;
4948
5049// Treeshakable guard to remove all code related to tracing
5150declare const __SENTRY_TRACING__ : boolean ;
5251
5352/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
5453export function init ( options : BrowserOptions ) : Client | undefined {
55- // Debug marker to verify this init() is being called (for e2e tests)
56- if ( typeof globalThis !== 'undefined' ) {
57- ( globalThis as Record < string , unknown > ) . _sentryNextjsInitCalled = true ;
58- }
59-
6054 if ( clientIsInitialized ) {
6155 consoleSandbox ( ( ) => {
6256 // eslint-disable-next-line no-console
@@ -153,55 +147,28 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] {
153147 // The value is injected at build time:
154148 // - Webpack: via DefinePlugin which replaces process.env._sentrySpotlight
155149 // - Turbopack: via valueInjectionLoader which sets globalThis._sentrySpotlight
156- // - Manual: user can set globalThis._sentrySpotlightManual in instrumentation-client.ts
150+ // - Manual: user can set window._sentrySpotlight in instrumentation-client.ts
157151 const processEnvSpotlight = process . env . _sentrySpotlight ;
158152 const globalSpotlight = globalWithInjectedValues . _sentrySpotlight ;
159- const manualSpotlight = globalWithInjectedValues . _sentrySpotlightManual ;
160- // Also check raw globalThis directly in case GLOBAL_OBJ differs
161- const rawGlobalThis = typeof globalThis !== 'undefined' ? globalThis : undefined ;
162- const rawManualSpotlightRaw = rawGlobalThis ? ( rawGlobalThis as Record < string , unknown > ) . _sentrySpotlightManual : undefined ;
163- const rawManualSpotlight = typeof rawManualSpotlightRaw === 'string' ? rawManualSpotlightRaw : undefined ;
164- const spotlightEnvValue : string | undefined =
165- processEnvSpotlight || globalSpotlight || manualSpotlight || rawManualSpotlight ;
166-
167- // Expose debug info on globalThis for test verification
168- if ( rawGlobalThis ) {
169- ( rawGlobalThis as Record < string , unknown > ) . _sentrySpotlightDebug = {
170- processEnvSpotlight,
171- globalSpotlight,
172- manualSpotlight,
173- rawManualSpotlightRaw,
174- rawManualSpotlight,
175- spotlightEnvValue,
176- optionsSpotlight : options . spotlight ,
177- GLOBAL_OBJ_keys : Object . keys ( GLOBAL_OBJ ) ,
178- } ;
179- }
180153
181- // eslint-disable-next-line no-console
182- console . log ( '[Sentry Next.js DEBUG] Spotlight detection:' , {
183- 'process.env._sentrySpotlight' : processEnvSpotlight ,
184- 'globalThis._sentrySpotlight' : globalSpotlight ,
185- 'globalThis._sentrySpotlightManual' : manualSpotlight ,
186- 'rawGlobalThis._sentrySpotlightManual (raw)' : rawManualSpotlightRaw ,
187- 'rawGlobalThis._sentrySpotlightManual' : rawManualSpotlight ,
188- resolved : spotlightEnvValue ,
189- 'options.spotlight' : options . spotlight ,
190- } ) ;
154+ // Check window directly for manual setting (most reliable in browser)
155+ // This is set in instrumentation-client.ts before Sentry.init()
156+ const windowObj = typeof window !== 'undefined' ? window : undefined ;
157+ const windowSpotlight = windowObj ? ( windowObj as unknown as Record < string , unknown > ) . _sentrySpotlight : undefined ;
158+
159+ const spotlightEnvValue : string | undefined =
160+ processEnvSpotlight ||
161+ globalSpotlight ||
162+ ( typeof windowSpotlight === 'string' ? windowSpotlight : undefined ) ;
191163
192164 if ( spotlightEnvValue !== undefined && options . spotlight === undefined ) {
193165 const boolValue = envToBool ( spotlightEnvValue , { strict : true } ) ;
194166 const spotlightConfig = boolValue !== null ? boolValue : spotlightEnvValue ;
195167 const spotlightValue = resolveSpotlightOptions ( undefined , spotlightConfig ) ;
196168
197- // eslint-disable-next-line no-console
198- console . log ( '[Sentry Next.js DEBUG] Spotlight resolved:' , { boolValue, spotlightConfig, spotlightValue } ) ;
199-
200169 if ( spotlightValue ) {
201170 const spotlightArgs = typeof spotlightValue === 'string' ? { sidecarUrl : spotlightValue } : undefined ;
202171 customDefaultIntegrations . push ( spotlightBrowserIntegration ( spotlightArgs ) ) ;
203- // eslint-disable-next-line no-console
204- console . log ( '[Sentry Next.js DEBUG] Spotlight integration ADDED' ) ;
205172 }
206173 }
207174
0 commit comments