@@ -314,7 +314,7 @@ export function generateGlobalInjectorCode({
314
314
} ) : string {
315
315
// The code below is mostly ternary operators because it saves bundle size.
316
316
// The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
317
- let code = `!function(){var e="undefined"!=typeof window? window: "undefined"!=typeof global? global: "undefined"!=typeof globalThis? globalThis: "undefined"!=typeof self? self: {};` ;
317
+ let code = `!function(){try{ var e=( "undefined"!=typeof window&& window)||( "undefined"!=typeof global&& global)||( "undefined"!=typeof globalThis&& globalThis)||( "undefined"!=typeof self&& self)|| {};` ;
318
318
319
319
code += `e.SENTRY_RELEASE={id:${ JSON . stringify ( release ) } };` ;
320
320
@@ -324,7 +324,7 @@ export function generateGlobalInjectorCode({
324
324
code += `e.SENTRY_BUILD_INFO=${ JSON . stringify ( buildInfo ) } ;` ;
325
325
}
326
326
327
- code += "}();" ;
327
+ code += "}catch(e){}} ();" ;
328
328
329
329
return code ;
330
330
}
@@ -334,9 +334,10 @@ export function generateModuleMetadataInjectorCode(metadata: any): string {
334
334
// The code below is mostly ternary operators because it saves bundle size.
335
335
// The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
336
336
// We are merging the metadata objects in case modules are bundled twice with the plugin
337
- return `!function(){var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],${ JSON . stringify (
337
+ // Use try-catch to avoid issues when bundlers rename global variables like 'window' to 'k'
338
+ return `!function(){try{var e=("undefined"!=typeof window&&window)||("undefined"!=typeof global&&global)||("undefined"!=typeof globalThis&&globalThis)||("undefined"!=typeof self&&self)||{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],${ JSON . stringify (
338
339
metadata
339
- ) } )}();`;
340
+ ) } )}catch(e){}} ();`;
340
341
}
341
342
342
343
export function getBuildInformation ( ) : {
0 commit comments