@sentry/wasm 11.0.0-alpha.1 → 11.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ const _wasmIntegration = ((options = {}) => {
11
11
  return {
12
12
  name: INTEGRATION_NAME,
13
13
  setupOnce() {
14
- patchWebAssembly.patchWebAssembly();
14
+ patchWebAssembly.patchWebAssembly(registry.registerModule);
15
15
  },
16
16
  processEvent(event) {
17
17
  let hasAtLeastOneWasmFrameWithImage = false;
@@ -19,7 +19,7 @@ const _wasmIntegration = ((options = {}) => {
19
19
  if (event.exception?.values) {
20
20
  event.exception.values.forEach((exception) => {
21
21
  if (exception.stacktrace?.frames) {
22
- hasAtLeastOneWasmFrameWithImage = hasAtLeastOneWasmFrameWithImage || patchFrames(exception.stacktrace.frames, options.applicationKey, existingImagesCount);
22
+ hasAtLeastOneWasmFrameWithImage = patchFrames(exception.stacktrace.frames, options.applicationKey, existingImagesCount) || hasAtLeastOneWasmFrameWithImage;
23
23
  }
24
24
  });
25
25
  }
@@ -78,44 +78,15 @@ function getWorkerImage(url) {
78
78
  });
79
79
  }
80
80
  function registerWebWorkerWasm({ self }) {
81
- patchWebAssemblyWithForwarding(self);
82
- }
83
- function patchWebAssemblyWithForwarding(workerSelf) {
84
- if ("instantiateStreaming" in WebAssembly) {
85
- const origInstantiateStreaming = WebAssembly.instantiateStreaming;
86
- WebAssembly.instantiateStreaming = function instantiateStreaming(response, importObject) {
87
- return Promise.resolve(response).then((response2) => {
88
- return origInstantiateStreaming(response2, importObject).then((rv) => {
89
- if (response2.url) {
90
- registerModuleAndForward(rv.module, response2.url, workerSelf);
91
- }
92
- return rv;
93
- });
81
+ patchWebAssembly.patchWebAssembly((module, url) => {
82
+ const image = registry.registerModule(module, url);
83
+ if (image) {
84
+ self.postMessage({
85
+ _sentryMessage: true,
86
+ _sentryWasmImages: [image]
94
87
  });
95
- };
96
- }
97
- if ("compileStreaming" in WebAssembly) {
98
- const origCompileStreaming = WebAssembly.compileStreaming;
99
- WebAssembly.compileStreaming = function compileStreaming(source) {
100
- return Promise.resolve(source).then((response) => {
101
- return origCompileStreaming(response).then((module) => {
102
- if (response.url) {
103
- registerModuleAndForward(module, response.url, workerSelf);
104
- }
105
- return module;
106
- });
107
- });
108
- };
109
- }
110
- }
111
- function registerModuleAndForward(module, url, workerSelf) {
112
- const image = registry.registerModule(module, url);
113
- if (image) {
114
- workerSelf.postMessage({
115
- _sentryMessage: true,
116
- _sentryWasmImages: [image]
117
- });
118
- }
88
+ }
89
+ });
119
90
  }
120
91
 
121
92
  exports.patchFrames = patchFrames;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":["import type { DebugImage, Event, IntegrationFn, StackFrame } from '@sentry/core';\nimport { defineIntegration, GLOBAL_OBJ } from '@sentry/core';\nimport { patchWebAssembly } from './patchWebAssembly';\nimport { getImage, getImages, registerModule } from './registry';\n\nconst INTEGRATION_NAME = 'Wasm';\n\n// We use the same prefix as bundler plugins so that thirdPartyErrorFilterIntegration\n// recognizes WASM frames as first-party code without needing modifications.\nconst BUNDLER_PLUGIN_APP_KEY_PREFIX = '_sentryBundlerPluginAppKey:';\n\n/**\n * Minimal interface for DedicatedWorkerGlobalScope.\n * We can't use the actual type because it breaks everyone who doesn't have {\"lib\": [\"WebWorker\"]}\n */\ninterface MinimalDedicatedWorkerGlobalScope {\n postMessage: (message: unknown) => void;\n}\n\ninterface RegisterWebWorkerWasmOptions {\n self: MinimalDedicatedWorkerGlobalScope;\n}\n\ninterface WasmIntegrationOptions {\n /**\n * Key to identify this application for third-party error filtering.\n * This key should match one of the keys provided to the `filterKeys` option\n * of the `thirdPartyErrorFilterIntegration`.\n */\n applicationKey?: string;\n}\n\n// Access WINDOW with proper typing for _sentryWasmImages\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n _sentryWasmImages?: Array<DebugImage>;\n};\n\nconst _wasmIntegration = ((options: WasmIntegrationOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n patchWebAssembly();\n },\n processEvent(event: Event): Event {\n let hasAtLeastOneWasmFrameWithImage = false;\n\n const existingImagesCount = event.debug_meta?.images?.length || 0;\n\n if (event.exception?.values) {\n event.exception.values.forEach(exception => {\n if (exception.stacktrace?.frames) {\n hasAtLeastOneWasmFrameWithImage =\n hasAtLeastOneWasmFrameWithImage ||\n patchFrames(exception.stacktrace.frames, options.applicationKey, existingImagesCount);\n }\n });\n }\n\n if (hasAtLeastOneWasmFrameWithImage) {\n event.debug_meta = event.debug_meta || {};\n const mainThreadImages = getImages();\n const workerImages = WINDOW._sentryWasmImages || [];\n event.debug_meta.images = [...(event.debug_meta.images || []), ...mainThreadImages, ...workerImages];\n }\n\n return event;\n },\n };\n}) satisfies IntegrationFn;\n\nexport const wasmIntegration = defineIntegration(_wasmIntegration);\n\nconst PARSER_REGEX = /^(.*?):wasm-function\\[\\d+\\]:(0x[a-fA-F0-9]+)$/;\n\n/**\n * Patches a list of stackframes with wasm data needed for server-side symbolication\n * if applicable. Returns true if the provided list of stack frames had at least one\n * matching registered image.\n *\n * @param frames - Stack frames to patch\n * @param applicationKey - Optional key for third-party error filtering\n * @param existingImagesOffset - Number of existing debug images that will be prepended\n * to the final images array (used to calculate correct addr_mode indices)\n */\n// Only exported for tests\nexport function patchFrames(\n frames: Array<StackFrame>,\n applicationKey?: string,\n existingImagesOffset: number = 0,\n): boolean {\n let hasAtLeastOneWasmFrameWithImage = false;\n frames.forEach(frame => {\n if (!frame.filename) {\n return;\n }\n\n const split = frame.filename.split('(');\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const lastSplit = split[split.length - 1]!;\n\n // Let's call this first match a \"messy match\".\n // The browser stacktrace parser spits out frames that have a filename like this: \"int) const (http://localhost:8001/main.wasm:wasm-function[190]:0x5aeb\"\n // It contains some leftover mess because wasm stack frames are more complicated than our parser can handle: \"at MyClass::bar(int) const (http://localhost:8001/main.wasm:wasm-function[190]:0x5aeb)\"\n // This first match simply tries to mitigate the mess up until the first opening parens.\n // The match afterwards is a sensible fallback\n let match = lastSplit.match(PARSER_REGEX) as null | [string, string, string];\n\n if (!match) {\n match = frame.filename.match(PARSER_REGEX) as null | [string, string, string];\n }\n\n if (match) {\n const index = getImage(match[1]);\n const workerImageIndex = getWorkerImage(match[1]);\n frame.instruction_addr = match[2];\n frame.filename = match[1];\n frame.platform = 'native';\n\n if (applicationKey) {\n frame.module_metadata = {\n ...frame.module_metadata,\n [`${BUNDLER_PLUGIN_APP_KEY_PREFIX}${applicationKey}`]: true,\n };\n }\n\n if (index >= 0) {\n frame.addr_mode = `rel:${existingImagesOffset + index}`;\n hasAtLeastOneWasmFrameWithImage = true;\n } else if (workerImageIndex >= 0) {\n const mainThreadImagesCount = getImages().length;\n frame.addr_mode = `rel:${existingImagesOffset + mainThreadImagesCount + workerImageIndex}`;\n hasAtLeastOneWasmFrameWithImage = true;\n }\n }\n });\n\n return hasAtLeastOneWasmFrameWithImage;\n}\n\n/**\n * Looks up an image by URL in worker images.\n */\nfunction getWorkerImage(url: string): number {\n const workerImages = WINDOW._sentryWasmImages || [];\n return workerImages.findIndex(image => {\n return image.type === 'wasm' && image.code_file === url;\n });\n}\n\n/**\n * Use this function to register WASM support in a web worker.\n *\n * This function will:\n * - Patch WebAssembly.instantiateStreaming and WebAssembly.compileStreaming in the worker\n * - Forward WASM debug images to the parent thread for symbolication\n *\n * @param options {RegisterWebWorkerWasmOptions} Options:\n * - `self`: The worker's global scope (self).\n */\nexport function registerWebWorkerWasm({ self }: RegisterWebWorkerWasmOptions): void {\n patchWebAssemblyWithForwarding(self);\n}\n\n/**\n * Patches the WebAssembly object in the worker scope and forwards\n * registered modules to the parent thread.\n */\nfunction patchWebAssemblyWithForwarding(workerSelf: MinimalDedicatedWorkerGlobalScope): void {\n if ('instantiateStreaming' in WebAssembly) {\n const origInstantiateStreaming = WebAssembly.instantiateStreaming;\n WebAssembly.instantiateStreaming = function instantiateStreaming(\n response: Response | PromiseLike<Response>,\n importObject: WebAssembly.Imports,\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(response).then(response => {\n return origInstantiateStreaming(response, importObject).then(rv => {\n if (response.url) {\n registerModuleAndForward(rv.module, response.url, workerSelf);\n }\n return rv;\n });\n });\n } as typeof WebAssembly.instantiateStreaming;\n }\n\n if ('compileStreaming' in WebAssembly) {\n const origCompileStreaming = WebAssembly.compileStreaming;\n WebAssembly.compileStreaming = function compileStreaming(\n source: Response | Promise<Response>,\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(source).then(response => {\n return origCompileStreaming(response).then(module => {\n if (response.url) {\n registerModuleAndForward(module, response.url, workerSelf);\n }\n return module;\n });\n });\n } as typeof WebAssembly.compileStreaming;\n }\n}\n\n/**\n * Registers a WASM module and forwards its debug image to the parent thread.\n */\nfunction registerModuleAndForward(\n module: WebAssembly.Module,\n url: string,\n workerSelf: MinimalDedicatedWorkerGlobalScope,\n): void {\n const image = registerModule(module, url);\n\n if (image) {\n workerSelf.postMessage({\n _sentryMessage: true,\n _sentryWasmImages: [image],\n });\n }\n}\n"],"names":["GLOBAL_OBJ","patchWebAssembly","getImages","defineIntegration","getImage","response","registerModule"],"mappings":";;;;;;AAKA,MAAM,gBAAA,GAAmB,MAAA;AAIzB,MAAM,6BAAA,GAAgC,6BAAA;AAwBtC,MAAM,MAAA,GAASA,eAAA;AAIf,MAAM,gBAAA,IAAoB,CAAC,OAAA,GAAkC,EAAC,KAAM;AAClE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAAC,iCAAA,EAAiB;AAAA,IACnB,CAAA;AAAA,IACA,aAAa,KAAA,EAAqB;AAChC,MAAA,IAAI,+BAAA,GAAkC,KAAA;AAEtC,MAAA,MAAM,mBAAA,GAAsB,KAAA,CAAM,UAAA,EAAY,MAAA,EAAQ,MAAA,IAAU,CAAA;AAEhE,MAAA,IA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D,UAAA,IAAI,SAAS,GAAA,EAAK;AAChB,YAAA,wBAAA,CAAyB,MAAA,EAAQ,QAAA,CAAS,GAAA,EAAK,UAAU,CAAA;AAAA,UAC3D;AACA,UAAA,OAAO,MAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AACF;AAKA,SAAS,wBAAA,CACP,MAAA,EACA,GAAA,EACA,UAAA,EACM;AACN,EAAA,MAAM,KAAA,GAAQC,uBAAA,CAAe,MAAA,EAAQ,GAAG,CAAA;AAExC,EAAA,IAAI,KAAA,EAAO;AACT,IAAA,UAAA,CAAW,WAAA,CAAY;AAAA,MACrB,cAAA,EAAgB,IAAA;AAAA,MAChB,iBAAA,EAAmB,CAAC,KAAK;AAAA,KAC1B,CAAA;AAAA,EACH;AACF;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":["import type { DebugImage, Event, IntegrationFn, StackFrame } from '@sentry/core';\nimport { defineIntegration, GLOBAL_OBJ } from '@sentry/core';\nimport { patchWebAssembly } from './patchWebAssembly';\nimport { getImage, getImages, registerModule } from './registry';\n\nconst INTEGRATION_NAME = 'Wasm';\n\n// We use the same prefix as bundler plugins so that thirdPartyErrorFilterIntegration\n// recognizes WASM frames as first-party code without needing modifications.\nconst BUNDLER_PLUGIN_APP_KEY_PREFIX = '_sentryBundlerPluginAppKey:';\n\n/**\n * Minimal interface for DedicatedWorkerGlobalScope.\n * We can't use the actual type because it breaks everyone who doesn't have {\"lib\": [\"WebWorker\"]}\n */\ninterface MinimalDedicatedWorkerGlobalScope {\n postMessage: (message: unknown) => void;\n}\n\ninterface RegisterWebWorkerWasmOptions {\n self: MinimalDedicatedWorkerGlobalScope;\n}\n\ninterface WasmIntegrationOptions {\n /**\n * Key to identify this application for third-party error filtering.\n * This key should match one of the keys provided to the `filterKeys` option\n * of the `thirdPartyErrorFilterIntegration`.\n */\n applicationKey?: string;\n}\n\n// Access WINDOW with proper typing for _sentryWasmImages\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n _sentryWasmImages?: Array<DebugImage>;\n};\n\nconst _wasmIntegration = ((options: WasmIntegrationOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n patchWebAssembly(registerModule);\n },\n processEvent(event: Event): Event {\n let hasAtLeastOneWasmFrameWithImage = false;\n\n const existingImagesCount = event.debug_meta?.images?.length || 0;\n\n if (event.exception?.values) {\n event.exception.values.forEach(exception => {\n if (exception.stacktrace?.frames) {\n hasAtLeastOneWasmFrameWithImage =\n patchFrames(exception.stacktrace.frames, options.applicationKey, existingImagesCount) ||\n hasAtLeastOneWasmFrameWithImage;\n }\n });\n }\n\n if (hasAtLeastOneWasmFrameWithImage) {\n event.debug_meta = event.debug_meta || {};\n const mainThreadImages = getImages();\n const workerImages = WINDOW._sentryWasmImages || [];\n event.debug_meta.images = [...(event.debug_meta.images || []), ...mainThreadImages, ...workerImages];\n }\n\n return event;\n },\n };\n}) satisfies IntegrationFn;\n\nexport const wasmIntegration = defineIntegration(_wasmIntegration);\n\nconst PARSER_REGEX = /^(.*?):wasm-function\\[\\d+\\]:(0x[a-fA-F0-9]+)$/;\n\n/**\n * Patches a list of stackframes with wasm data needed for server-side symbolication\n * if applicable. Returns true if the provided list of stack frames had at least one\n * matching registered image.\n *\n * @param frames - Stack frames to patch\n * @param applicationKey - Optional key for third-party error filtering\n * @param existingImagesOffset - Number of existing debug images that will be prepended\n * to the final images array (used to calculate correct addr_mode indices)\n */\n// Only exported for tests\nexport function patchFrames(\n frames: Array<StackFrame>,\n applicationKey?: string,\n existingImagesOffset: number = 0,\n): boolean {\n let hasAtLeastOneWasmFrameWithImage = false;\n frames.forEach(frame => {\n if (!frame.filename) {\n return;\n }\n\n const split = frame.filename.split('(');\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const lastSplit = split[split.length - 1]!;\n\n // Let's call this first match a \"messy match\".\n // The browser stacktrace parser spits out frames that have a filename like this: \"int) const (http://localhost:8001/main.wasm:wasm-function[190]:0x5aeb\"\n // It contains some leftover mess because wasm stack frames are more complicated than our parser can handle: \"at MyClass::bar(int) const (http://localhost:8001/main.wasm:wasm-function[190]:0x5aeb)\"\n // This first match simply tries to mitigate the mess up until the first opening parens.\n // The match afterwards is a sensible fallback\n let match = lastSplit.match(PARSER_REGEX) as null | [string, string, string];\n\n if (!match) {\n match = frame.filename.match(PARSER_REGEX) as null | [string, string, string];\n }\n\n if (match) {\n const index = getImage(match[1]);\n const workerImageIndex = getWorkerImage(match[1]);\n frame.instruction_addr = match[2];\n frame.filename = match[1];\n frame.platform = 'native';\n\n if (applicationKey) {\n frame.module_metadata = {\n ...frame.module_metadata,\n [`${BUNDLER_PLUGIN_APP_KEY_PREFIX}${applicationKey}`]: true,\n };\n }\n\n if (index >= 0) {\n frame.addr_mode = `rel:${existingImagesOffset + index}`;\n hasAtLeastOneWasmFrameWithImage = true;\n } else if (workerImageIndex >= 0) {\n const mainThreadImagesCount = getImages().length;\n frame.addr_mode = `rel:${existingImagesOffset + mainThreadImagesCount + workerImageIndex}`;\n hasAtLeastOneWasmFrameWithImage = true;\n }\n }\n });\n\n return hasAtLeastOneWasmFrameWithImage;\n}\n\n/**\n * Looks up an image by URL in worker images.\n */\nfunction getWorkerImage(url: string): number {\n const workerImages = WINDOW._sentryWasmImages || [];\n return workerImages.findIndex(image => {\n return image.type === 'wasm' && image.code_file === url;\n });\n}\n\n/**\n * Use this function to register WASM support in a web worker.\n *\n * This function will:\n * - Patch WebAssembly.instantiateStreaming and WebAssembly.compileStreaming in the worker\n * - Forward WASM debug images to the parent thread for symbolication\n *\n * @param options {RegisterWebWorkerWasmOptions} Options:\n * - `self`: The worker's global scope (self).\n */\nexport function registerWebWorkerWasm({ self }: RegisterWebWorkerWasmOptions): void {\n patchWebAssembly((module, url) => {\n const image = registerModule(module, url);\n\n if (image) {\n self.postMessage({\n _sentryMessage: true,\n _sentryWasmImages: [image],\n });\n }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F;AAEA,MAAA,IAAI,SAAS,CAAA,EAAG;AACd,QAAA,KAAA,CAAM,SAAA,GAAY,CAAA,IAAA,EAAO,oBAAA,GAAuB,KAAK,CAAA,CAAA;AACrD,QAAA,+BAAA,GAAkC,IAAA;AAAA,MACpC,CAAA,MAAA,IAAW,oBAAoB,CAAA,EAAG;AAChC,QAAA,MAAM,qBAAA,GAAwBF,oBAAU,CAAE,MAAA;AAC1C,QAAA,KAAA,CAAM,SAAA,GAAY,CAAA,IAAA,EAAO,oBAAA,GAAuB,qBAAA,GAAwB,gBAAgB,CAAA,CAAA;AACxF,QAAA,+BAAA,GAAkC,IAAA;AAAA,MACpC;AAAA,IACF;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,+BAAA;AACT;AAKA,SAAS,eAAe,GAAA,EAAqB;AAC3C,EAAA,MAAM,YAAA,GAAe,MAAA,CAAO,iBAAA,IAAqB,EAAC;AAClD,EAAA,OAAO,YAAA,CAAa,UAAU,CAAA,KAAA,KAAS;AACrC,IAAA,OAAO,KAAA,CAAM,IAAA,KAAS,MAAA,IAAU,KAAA,CAAM,SAAA,KAAc,GAAA;AAAA,EACtD,CAAC,CAAA;AACH;AAYO,SAAS,qBAAA,CAAsB,EAAE,IAAA,EAAK,EAAuC;AAClF,EAAAF,iCAAA,CAAiB,CAAC,QAAQ,GAAA,KAAQ;AAChC,IAAA,MAAM,KAAA,GAAQC,uBAAA,CAAe,MAAA,EAAQ,GAAG,CAAA;AAExC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,IAAA,CAAK,WAAA,CAAY;AAAA,QACf,cAAA,EAAgB,IAAA;AAAA,QAChB,iBAAA,EAAmB,CAAC,KAAK;AAAA,OAC1B,CAAA;AAAA,IACH;AAAA,EACF,CAAC,CAAA;AACH;;;;;;"}
@@ -1,15 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const registry = require('./registry.js');
4
-
5
- function patchWebAssembly() {
3
+ function patchWebAssembly(registerModule) {
6
4
  if ("instantiateStreaming" in WebAssembly) {
7
5
  const origInstantiateStreaming = WebAssembly.instantiateStreaming;
8
- WebAssembly.instantiateStreaming = function instantiateStreaming(response, importObject) {
6
+ WebAssembly.instantiateStreaming = function instantiateStreaming(response, ...rest) {
9
7
  return Promise.resolve(response).then((response2) => {
10
- return origInstantiateStreaming(response2, importObject).then((rv) => {
8
+ return origInstantiateStreaming(response2, ...rest).then((rv) => {
11
9
  if (response2.url) {
12
- registry.registerModule(rv.module, response2.url);
10
+ registerSafely(registerModule, rv.module, response2.url);
13
11
  }
14
12
  return rv;
15
13
  });
@@ -18,11 +16,11 @@ function patchWebAssembly() {
18
16
  }
19
17
  if ("compileStreaming" in WebAssembly) {
20
18
  const origCompileStreaming = WebAssembly.compileStreaming;
21
- WebAssembly.compileStreaming = function compileStreaming(source) {
19
+ WebAssembly.compileStreaming = function compileStreaming(source, ...rest) {
22
20
  return Promise.resolve(source).then((response) => {
23
- return origCompileStreaming(response).then((module) => {
21
+ return origCompileStreaming(response, ...rest).then((module) => {
24
22
  if (response.url) {
25
- registry.registerModule(module, response.url);
23
+ registerSafely(registerModule, module, response.url);
26
24
  }
27
25
  return module;
28
26
  });
@@ -30,6 +28,12 @@ function patchWebAssembly() {
30
28
  };
31
29
  }
32
30
  }
31
+ function registerSafely(registerModule, module, url) {
32
+ try {
33
+ registerModule(module, url);
34
+ } catch {
35
+ }
36
+ }
33
37
 
34
38
  exports.patchWebAssembly = patchWebAssembly;
35
39
  //# sourceMappingURL=patchWebAssembly.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"patchWebAssembly.js","sources":["../../../src/patchWebAssembly.ts"],"sourcesContent":["import { registerModule } from './registry';\n\n/**\n * Patches the web assembly runtime.\n */\nexport function patchWebAssembly(): void {\n if ('instantiateStreaming' in WebAssembly) {\n const origInstantiateStreaming = WebAssembly.instantiateStreaming;\n WebAssembly.instantiateStreaming = function instantiateStreaming(\n response: Response | PromiseLike<Response>,\n importObject: WebAssembly.Imports,\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(response).then(response => {\n return origInstantiateStreaming(response, importObject).then(rv => {\n if (response.url) {\n registerModule(rv.module, response.url);\n }\n return rv;\n });\n });\n } as typeof WebAssembly.instantiateStreaming;\n }\n\n if ('compileStreaming' in WebAssembly) {\n const origCompileStreaming = WebAssembly.compileStreaming;\n WebAssembly.compileStreaming = function compileStreaming(\n source: Response | Promise<Response>,\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(source).then(response => {\n return origCompileStreaming(response).then(module => {\n if (response.url) {\n registerModule(module, response.url);\n }\n return module;\n });\n });\n } as typeof WebAssembly.compileStreaming;\n }\n}\n"],"names":["response","registerModule"],"mappings":";;;;AAKO,SAAS,gBAAA,GAAyB;AACvC,EAAA,IAAI,0BAA0B,WAAA,EAAa;AACzC,IAAA,MAAM,2BAA2B,WAAA,CAAY,oBAAA;AAC7C,IAAA,WAAA,CAAY,oBAAA,GAAuB,SAAS,oBAAA,CAC1C,QAAA,EACA,YAAA,EAC6B;AAC7B,MAAA,OAAO,QAAQ,OAAA,CAAQ,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAAA,SAAAA,KAAY;AAChD,QAAA,OAAO,wBAAA,CAAyBA,SAAAA,EAAU,YAAY,CAAA,CAAE,KAAK,CAAA,EAAA,KAAM;AACjE,UAAA,IAAIA,UAAS,GAAA,EAAK;AAChB,YAAAC,uBAAA,CAAe,EAAA,CAAG,MAAA,EAAQD,SAAAA,CAAS,GAAG,CAAA;AAAA,UACxC;AACA,UAAA,OAAO,EAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AAEA,EAAA,IAAI,sBAAsB,WAAA,EAAa;AACrC,IAAA,MAAM,uBAAuB,WAAA,CAAY,gBAAA;AACzC,IAAA,WAAA,CAAY,gBAAA,GAAmB,SAAS,gBAAA,CACtC,MAAA,EAC6B;AAC7B,MAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,MAAM,CAAA,CAAE,KAAK,CAAA,QAAA,KAAY;AAC9C,QAAA,OAAO,oBAAA,CAAqB,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAA,MAAA,KAAU;AACnD,UAAA,IAAI,SAAS,GAAA,EAAK;AAChB,YAAAC,uBAAA,CAAe,MAAA,EAAQ,SAAS,GAAG,CAAA;AAAA,UACrC;AACA,UAAA,OAAO,MAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AACF;;;;"}
1
+ {"version":3,"file":"patchWebAssembly.js","sources":["../../../src/patchWebAssembly.ts"],"sourcesContent":["export type RegisterModuleCallback = (module: WebAssembly.Module, url: string) => void;\n\n/**\n * Patches the WebAssembly streaming APIs so that every compiled module gets\n * registered as a debug image under the URL of the response it was compiled\n * from.\n *\n * @param registerModule callback invoked for every successfully compiled module\n */\nexport function patchWebAssembly(registerModule: RegisterModuleCallback): void {\n if ('instantiateStreaming' in WebAssembly) {\n const origInstantiateStreaming = WebAssembly.instantiateStreaming as (\n response: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.WebAssemblyInstantiatedSource>;\n WebAssembly.instantiateStreaming = function instantiateStreaming(\n response: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.WebAssemblyInstantiatedSource> {\n return Promise.resolve(response).then(response => {\n return origInstantiateStreaming(response, ...rest).then(rv => {\n if (response.url) {\n registerSafely(registerModule, rv.module, response.url);\n }\n return rv;\n });\n });\n };\n }\n\n if ('compileStreaming' in WebAssembly) {\n const origCompileStreaming = WebAssembly.compileStreaming as (\n source: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.Module>;\n WebAssembly.compileStreaming = function compileStreaming(\n source: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(source).then(response => {\n return origCompileStreaming(response, ...rest).then(module => {\n if (response.url) {\n registerSafely(registerModule, module, response.url);\n }\n return module;\n });\n });\n };\n }\n}\n\nfunction registerSafely(registerModule: RegisterModuleCallback, module: WebAssembly.Module, url: string): void {\n try {\n registerModule(module, url);\n } catch {\n // a registration failure must never break the user's WebAssembly call\n }\n}\n"],"names":["response"],"mappings":";;AASO,SAAS,iBAAiB,cAAA,EAA8C;AAC7E,EAAA,IAAI,0BAA0B,WAAA,EAAa;AACzC,IAAA,MAAM,2BAA2B,WAAA,CAAY,oBAAA;AAI7C,IAAA,WAAA,CAAY,oBAAA,GAAuB,SAAS,oBAAA,CAC1C,QAAA,EAAA,GACG,IAAA,EACiD;AACpD,MAAA,OAAO,QAAQ,OAAA,CAAQ,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAAA,SAAAA,KAAY;AAChD,QAAA,OAAO,yBAAyBA,SAAAA,EAAU,GAAG,IAAI,CAAA,CAAE,KAAK,CAAA,EAAA,KAAM;AAC5D,UAAA,IAAIA,UAAS,GAAA,EAAK;AAChB,YAAA,cAAA,CAAe,cAAA,EAAgB,EAAA,CAAG,MAAA,EAAQA,SAAAA,CAAS,GAAG,CAAA;AAAA,UACxD;AACA,UAAA,OAAO,EAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AAEA,EAAA,IAAI,sBAAsB,WAAA,EAAa;AACrC,IAAA,MAAM,uBAAuB,WAAA,CAAY,gBAAA;AAIzC,IAAA,WAAA,CAAY,gBAAA,GAAmB,SAAS,gBAAA,CACtC,MAAA,EAAA,GACG,IAAA,EAC0B;AAC7B,MAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,MAAM,CAAA,CAAE,KAAK,CAAA,QAAA,KAAY;AAC9C,QAAA,OAAO,qBAAqB,QAAA,EAAU,GAAG,IAAI,CAAA,CAAE,KAAK,CAAA,MAAA,KAAU;AAC5D,UAAA,IAAI,SAAS,GAAA,EAAK;AAChB,YAAA,cAAA,CAAe,cAAA,EAAgB,MAAA,EAAQ,QAAA,CAAS,GAAG,CAAA;AAAA,UACrD;AACA,UAAA,OAAO,MAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AACF;AAEA,SAAS,cAAA,CAAe,cAAA,EAAwC,MAAA,EAA4B,GAAA,EAAmB;AAC7G,EAAA,IAAI;AACF,IAAA,cAAA,CAAe,QAAQ,GAAG,CAAA;AAAA,EAC5B,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;;;;"}
@@ -9,7 +9,7 @@ const _wasmIntegration = ((options = {}) => {
9
9
  return {
10
10
  name: INTEGRATION_NAME,
11
11
  setupOnce() {
12
- patchWebAssembly();
12
+ patchWebAssembly(registerModule);
13
13
  },
14
14
  processEvent(event) {
15
15
  let hasAtLeastOneWasmFrameWithImage = false;
@@ -17,7 +17,7 @@ const _wasmIntegration = ((options = {}) => {
17
17
  if (event.exception?.values) {
18
18
  event.exception.values.forEach((exception) => {
19
19
  if (exception.stacktrace?.frames) {
20
- hasAtLeastOneWasmFrameWithImage = hasAtLeastOneWasmFrameWithImage || patchFrames(exception.stacktrace.frames, options.applicationKey, existingImagesCount);
20
+ hasAtLeastOneWasmFrameWithImage = patchFrames(exception.stacktrace.frames, options.applicationKey, existingImagesCount) || hasAtLeastOneWasmFrameWithImage;
21
21
  }
22
22
  });
23
23
  }
@@ -76,44 +76,15 @@ function getWorkerImage(url) {
76
76
  });
77
77
  }
78
78
  function registerWebWorkerWasm({ self }) {
79
- patchWebAssemblyWithForwarding(self);
80
- }
81
- function patchWebAssemblyWithForwarding(workerSelf) {
82
- if ("instantiateStreaming" in WebAssembly) {
83
- const origInstantiateStreaming = WebAssembly.instantiateStreaming;
84
- WebAssembly.instantiateStreaming = function instantiateStreaming(response, importObject) {
85
- return Promise.resolve(response).then((response2) => {
86
- return origInstantiateStreaming(response2, importObject).then((rv) => {
87
- if (response2.url) {
88
- registerModuleAndForward(rv.module, response2.url, workerSelf);
89
- }
90
- return rv;
91
- });
79
+ patchWebAssembly((module, url) => {
80
+ const image = registerModule(module, url);
81
+ if (image) {
82
+ self.postMessage({
83
+ _sentryMessage: true,
84
+ _sentryWasmImages: [image]
92
85
  });
93
- };
94
- }
95
- if ("compileStreaming" in WebAssembly) {
96
- const origCompileStreaming = WebAssembly.compileStreaming;
97
- WebAssembly.compileStreaming = function compileStreaming(source) {
98
- return Promise.resolve(source).then((response) => {
99
- return origCompileStreaming(response).then((module) => {
100
- if (response.url) {
101
- registerModuleAndForward(module, response.url, workerSelf);
102
- }
103
- return module;
104
- });
105
- });
106
- };
107
- }
108
- }
109
- function registerModuleAndForward(module, url, workerSelf) {
110
- const image = registerModule(module, url);
111
- if (image) {
112
- workerSelf.postMessage({
113
- _sentryMessage: true,
114
- _sentryWasmImages: [image]
115
- });
116
- }
86
+ }
87
+ });
117
88
  }
118
89
 
119
90
  export { patchFrames, registerWebWorkerWasm, wasmIntegration };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":["import type { DebugImage, Event, IntegrationFn, StackFrame } from '@sentry/core';\nimport { defineIntegration, GLOBAL_OBJ } from '@sentry/core';\nimport { patchWebAssembly } from './patchWebAssembly';\nimport { getImage, getImages, registerModule } from './registry';\n\nconst INTEGRATION_NAME = 'Wasm';\n\n// We use the same prefix as bundler plugins so that thirdPartyErrorFilterIntegration\n// recognizes WASM frames as first-party code without needing modifications.\nconst BUNDLER_PLUGIN_APP_KEY_PREFIX = '_sentryBundlerPluginAppKey:';\n\n/**\n * Minimal interface for DedicatedWorkerGlobalScope.\n * We can't use the actual type because it breaks everyone who doesn't have {\"lib\": [\"WebWorker\"]}\n */\ninterface MinimalDedicatedWorkerGlobalScope {\n postMessage: (message: unknown) => void;\n}\n\ninterface RegisterWebWorkerWasmOptions {\n self: MinimalDedicatedWorkerGlobalScope;\n}\n\ninterface WasmIntegrationOptions {\n /**\n * Key to identify this application for third-party error filtering.\n * This key should match one of the keys provided to the `filterKeys` option\n * of the `thirdPartyErrorFilterIntegration`.\n */\n applicationKey?: string;\n}\n\n// Access WINDOW with proper typing for _sentryWasmImages\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n _sentryWasmImages?: Array<DebugImage>;\n};\n\nconst _wasmIntegration = ((options: WasmIntegrationOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n patchWebAssembly();\n },\n processEvent(event: Event): Event {\n let hasAtLeastOneWasmFrameWithImage = false;\n\n const existingImagesCount = event.debug_meta?.images?.length || 0;\n\n if (event.exception?.values) {\n event.exception.values.forEach(exception => {\n if (exception.stacktrace?.frames) {\n hasAtLeastOneWasmFrameWithImage =\n hasAtLeastOneWasmFrameWithImage ||\n patchFrames(exception.stacktrace.frames, options.applicationKey, existingImagesCount);\n }\n });\n }\n\n if (hasAtLeastOneWasmFrameWithImage) {\n event.debug_meta = event.debug_meta || {};\n const mainThreadImages = getImages();\n const workerImages = WINDOW._sentryWasmImages || [];\n event.debug_meta.images = [...(event.debug_meta.images || []), ...mainThreadImages, ...workerImages];\n }\n\n return event;\n },\n };\n}) satisfies IntegrationFn;\n\nexport const wasmIntegration = defineIntegration(_wasmIntegration);\n\nconst PARSER_REGEX = /^(.*?):wasm-function\\[\\d+\\]:(0x[a-fA-F0-9]+)$/;\n\n/**\n * Patches a list of stackframes with wasm data needed for server-side symbolication\n * if applicable. Returns true if the provided list of stack frames had at least one\n * matching registered image.\n *\n * @param frames - Stack frames to patch\n * @param applicationKey - Optional key for third-party error filtering\n * @param existingImagesOffset - Number of existing debug images that will be prepended\n * to the final images array (used to calculate correct addr_mode indices)\n */\n// Only exported for tests\nexport function patchFrames(\n frames: Array<StackFrame>,\n applicationKey?: string,\n existingImagesOffset: number = 0,\n): boolean {\n let hasAtLeastOneWasmFrameWithImage = false;\n frames.forEach(frame => {\n if (!frame.filename) {\n return;\n }\n\n const split = frame.filename.split('(');\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const lastSplit = split[split.length - 1]!;\n\n // Let's call this first match a \"messy match\".\n // The browser stacktrace parser spits out frames that have a filename like this: \"int) const (http://localhost:8001/main.wasm:wasm-function[190]:0x5aeb\"\n // It contains some leftover mess because wasm stack frames are more complicated than our parser can handle: \"at MyClass::bar(int) const (http://localhost:8001/main.wasm:wasm-function[190]:0x5aeb)\"\n // This first match simply tries to mitigate the mess up until the first opening parens.\n // The match afterwards is a sensible fallback\n let match = lastSplit.match(PARSER_REGEX) as null | [string, string, string];\n\n if (!match) {\n match = frame.filename.match(PARSER_REGEX) as null | [string, string, string];\n }\n\n if (match) {\n const index = getImage(match[1]);\n const workerImageIndex = getWorkerImage(match[1]);\n frame.instruction_addr = match[2];\n frame.filename = match[1];\n frame.platform = 'native';\n\n if (applicationKey) {\n frame.module_metadata = {\n ...frame.module_metadata,\n [`${BUNDLER_PLUGIN_APP_KEY_PREFIX}${applicationKey}`]: true,\n };\n }\n\n if (index >= 0) {\n frame.addr_mode = `rel:${existingImagesOffset + index}`;\n hasAtLeastOneWasmFrameWithImage = true;\n } else if (workerImageIndex >= 0) {\n const mainThreadImagesCount = getImages().length;\n frame.addr_mode = `rel:${existingImagesOffset + mainThreadImagesCount + workerImageIndex}`;\n hasAtLeastOneWasmFrameWithImage = true;\n }\n }\n });\n\n return hasAtLeastOneWasmFrameWithImage;\n}\n\n/**\n * Looks up an image by URL in worker images.\n */\nfunction getWorkerImage(url: string): number {\n const workerImages = WINDOW._sentryWasmImages || [];\n return workerImages.findIndex(image => {\n return image.type === 'wasm' && image.code_file === url;\n });\n}\n\n/**\n * Use this function to register WASM support in a web worker.\n *\n * This function will:\n * - Patch WebAssembly.instantiateStreaming and WebAssembly.compileStreaming in the worker\n * - Forward WASM debug images to the parent thread for symbolication\n *\n * @param options {RegisterWebWorkerWasmOptions} Options:\n * - `self`: The worker's global scope (self).\n */\nexport function registerWebWorkerWasm({ self }: RegisterWebWorkerWasmOptions): void {\n patchWebAssemblyWithForwarding(self);\n}\n\n/**\n * Patches the WebAssembly object in the worker scope and forwards\n * registered modules to the parent thread.\n */\nfunction patchWebAssemblyWithForwarding(workerSelf: MinimalDedicatedWorkerGlobalScope): void {\n if ('instantiateStreaming' in WebAssembly) {\n const origInstantiateStreaming = WebAssembly.instantiateStreaming;\n WebAssembly.instantiateStreaming = function instantiateStreaming(\n response: Response | PromiseLike<Response>,\n importObject: WebAssembly.Imports,\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(response).then(response => {\n return origInstantiateStreaming(response, importObject).then(rv => {\n if (response.url) {\n registerModuleAndForward(rv.module, response.url, workerSelf);\n }\n return rv;\n });\n });\n } as typeof WebAssembly.instantiateStreaming;\n }\n\n if ('compileStreaming' in WebAssembly) {\n const origCompileStreaming = WebAssembly.compileStreaming;\n WebAssembly.compileStreaming = function compileStreaming(\n source: Response | Promise<Response>,\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(source).then(response => {\n return origCompileStreaming(response).then(module => {\n if (response.url) {\n registerModuleAndForward(module, response.url, workerSelf);\n }\n return module;\n });\n });\n } as typeof WebAssembly.compileStreaming;\n }\n}\n\n/**\n * Registers a WASM module and forwards its debug image to the parent thread.\n */\nfunction registerModuleAndForward(\n module: WebAssembly.Module,\n url: string,\n workerSelf: MinimalDedicatedWorkerGlobalScope,\n): void {\n const image = registerModule(module, url);\n\n if (image) {\n workerSelf.postMessage({\n _sentryMessage: true,\n _sentryWasmImages: [image],\n });\n }\n}\n"],"names":["response"],"mappings":";;;;AAKA,MAAM,gBAAA,GAAmB,MAAA;AAIzB,MAAM,6BAAA,GAAgC,6BAAA;AAwBtC,MAAM,MAAA,GAAS,UAAA;AAIf,MAAM,gBAAA,IAAoB,CAAC,OAAA,GAAkC,EAAC,KAAM;AAClE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,gBAAA,EAAiB;AAAA,IACnB,CAAA;AAAA,IACA,aAAa,KAAA,EAAqB;AAChC,MAAA,IAAI,+BAAA,GA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AK,CAAA,QAAA,KAAY;AAC9C,QAAA,OAAO,oBAAA,CAAqB,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAA,MAAA,KAAU;AACnD,UAAA,IAAI,SAAS,GAAA,EAAK;AAChB,YAAA,wBAAA,CAAyB,MAAA,EAAQ,QAAA,CAAS,GAAA,EAAK,UAAU,CAAA;AAAA,UAC3D;AACA,UAAA,OAAO,MAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AACF;AAKA,SAAS,wBAAA,CACP,MAAA,EACA,GAAA,EACA,UAAA,EACM;AACN,EAAA,MAAM,KAAA,GAAQ,cAAA,CAAe,MAAA,EAAQ,GAAG,CAAA;AAExC,EAAA,IAAI,KAAA,EAAO;AACT,IAAA,UAAA,CAAW,WAAA,CAAY;AAAA,MACrB,cAAA,EAAgB,IAAA;AAAA,MAChB,iBAAA,EAAmB,CAAC,KAAK;AAAA,KAC1B,CAAA;AAAA,EACH;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":["import type { DebugImage, Event, IntegrationFn, StackFrame } from '@sentry/core';\nimport { defineIntegration, GLOBAL_OBJ } from '@sentry/core';\nimport { patchWebAssembly } from './patchWebAssembly';\nimport { getImage, getImages, registerModule } from './registry';\n\nconst INTEGRATION_NAME = 'Wasm';\n\n// We use the same prefix as bundler plugins so that thirdPartyErrorFilterIntegration\n// recognizes WASM frames as first-party code without needing modifications.\nconst BUNDLER_PLUGIN_APP_KEY_PREFIX = '_sentryBundlerPluginAppKey:';\n\n/**\n * Minimal interface for DedicatedWorkerGlobalScope.\n * We can't use the actual type because it breaks everyone who doesn't have {\"lib\": [\"WebWorker\"]}\n */\ninterface MinimalDedicatedWorkerGlobalScope {\n postMessage: (message: unknown) => void;\n}\n\ninterface RegisterWebWorkerWasmOptions {\n self: MinimalDedicatedWorkerGlobalScope;\n}\n\ninterface WasmIntegrationOptions {\n /**\n * Key to identify this application for third-party error filtering.\n * This key should match one of the keys provided to the `filterKeys` option\n * of the `thirdPartyErrorFilterIntegration`.\n */\n applicationKey?: string;\n}\n\n// Access WINDOW with proper typing for _sentryWasmImages\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n _sentryWasmImages?: Array<DebugImage>;\n};\n\nconst _wasmIntegration = ((options: WasmIntegrationOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n patchWebAssembly(registerModule);\n },\n processEvent(event: Event): Event {\n let hasAtLeastOneWasmFrameWithImage = false;\n\n const existingImagesCount = event.debug_meta?.images?.length || 0;\n\n if (event.exception?.values) {\n event.exception.values.forEach(exception => {\n if (exception.stacktrace?.frames) {\n hasAtLeastOneWasmFrameWithImage =\n patchFrames(exception.stacktrace.frames, options.applicationKey, existingImagesCount) ||\n hasAtLeastOneWasmFrameWithImage;\n }\n });\n }\n\n if (hasAtLeastOneWasmFrameWithImage) {\n event.debug_meta = event.debug_meta || {};\n const mainThreadImages = getImages();\n const workerImages = WINDOW._sentryWasmImages || [];\n event.debug_meta.images = [...(event.debug_meta.images || []), ...mainThreadImages, ...workerImages];\n }\n\n return event;\n },\n };\n}) satisfies IntegrationFn;\n\nexport const wasmIntegration = defineIntegration(_wasmIntegration);\n\nconst PARSER_REGEX = /^(.*?):wasm-function\\[\\d+\\]:(0x[a-fA-F0-9]+)$/;\n\n/**\n * Patches a list of stackframes with wasm data needed for server-side symbolication\n * if applicable. Returns true if the provided list of stack frames had at least one\n * matching registered image.\n *\n * @param frames - Stack frames to patch\n * @param applicationKey - Optional key for third-party error filtering\n * @param existingImagesOffset - Number of existing debug images that will be prepended\n * to the final images array (used to calculate correct addr_mode indices)\n */\n// Only exported for tests\nexport function patchFrames(\n frames: Array<StackFrame>,\n applicationKey?: string,\n existingImagesOffset: number = 0,\n): boolean {\n let hasAtLeastOneWasmFrameWithImage = false;\n frames.forEach(frame => {\n if (!frame.filename) {\n return;\n }\n\n const split = frame.filename.split('(');\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const lastSplit = split[split.length - 1]!;\n\n // Let's call this first match a \"messy match\".\n // The browser stacktrace parser spits out frames that have a filename like this: \"int) const (http://localhost:8001/main.wasm:wasm-function[190]:0x5aeb\"\n // It contains some leftover mess because wasm stack frames are more complicated than our parser can handle: \"at MyClass::bar(int) const (http://localhost:8001/main.wasm:wasm-function[190]:0x5aeb)\"\n // This first match simply tries to mitigate the mess up until the first opening parens.\n // The match afterwards is a sensible fallback\n let match = lastSplit.match(PARSER_REGEX) as null | [string, string, string];\n\n if (!match) {\n match = frame.filename.match(PARSER_REGEX) as null | [string, string, string];\n }\n\n if (match) {\n const index = getImage(match[1]);\n const workerImageIndex = getWorkerImage(match[1]);\n frame.instruction_addr = match[2];\n frame.filename = match[1];\n frame.platform = 'native';\n\n if (applicationKey) {\n frame.module_metadata = {\n ...frame.module_metadata,\n [`${BUNDLER_PLUGIN_APP_KEY_PREFIX}${applicationKey}`]: true,\n };\n }\n\n if (index >= 0) {\n frame.addr_mode = `rel:${existingImagesOffset + index}`;\n hasAtLeastOneWasmFrameWithImage = true;\n } else if (workerImageIndex >= 0) {\n const mainThreadImagesCount = getImages().length;\n frame.addr_mode = `rel:${existingImagesOffset + mainThreadImagesCount + workerImageIndex}`;\n hasAtLeastOneWasmFrameWithImage = true;\n }\n }\n });\n\n return hasAtLeastOneWasmFrameWithImage;\n}\n\n/**\n * Looks up an image by URL in worker images.\n */\nfunction getWorkerImage(url: string): number {\n const workerImages = WINDOW._sentryWasmImages || [];\n return workerImages.findIndex(image => {\n return image.type === 'wasm' && image.code_file === url;\n });\n}\n\n/**\n * Use this function to register WASM support in a web worker.\n *\n * This function will:\n * - Patch WebAssembly.instantiateStreaming and WebAssembly.compileStreaming in the worker\n * - Forward WASM debug images to the parent thread for symbolication\n *\n * @param options {RegisterWebWorkerWasmOptions} Options:\n * - `self`: The worker's global scope (self).\n */\nexport function registerWebWorkerWasm({ self }: RegisterWebWorkerWasmOptions): void {\n patchWebAssembly((module, url) => {\n const image = registerModule(module, url);\n\n if (image) {\n self.postMessage({\n _sentryMessage: true,\n _sentryWasmImages: [image],\n });\n }\n });\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,gBAAA,GAAmB,MAAA;AAIzB,MAAM,6BAAA,GAAgC,6BAAA;AAwBtC,MAAM,MAAA,GAAS,UAAA;AAIf,MAAM,gBAAA,IAAoB,CAAC,OAAA,GAAkC,EAAC,KAAM;AAClE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,gBAAA,CAAiB,cAAc,CAAA;AAAA,IACjC,CAAA;AAAA,IACA,aAAa,KAAA,EAAqB;AAChC,MAAA,IAAI,+BAAA,GAAkC,KAAA;AAEtC,MAAA,MAAM,mBAAA,GAAsB,KAAA,CAAM,UAAA,EAAY,MAAA,EAAQ,MAAA,IAAU,CAAA;AAEhE,MAAA,IAAI,KAAA,CAAM,WAAW,MAAA,EAAQ;AAC3B,QAAA,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,OAAA,CAAQ,CAAA,SAAA,KAAa;AAC1C,UAAA,IAAI,SAAA,CAAU,YAAY,MAAA,EAAQ;AAChC,YAAA,+BAAA,GACE,YAAY,SAAA,CAAU,UAAA,CAAW,QAAQ,OAAA,CAAQ,cAAA,EAAgB,mBAAmB,CAAA,IACpF,+BAAA;AAAA,UACJ;AAAA,QACF,CAAC,CAAA;AAAA,MACH;AAEA,MAAA,IAAI,+BAAA,EAAiC;AACnC,QAAA,KAAA,CAAM,UAAA,GAAa,KAAA,CAAM,UAAA,IAAc,EAAC;AACxC,QAAA,MAAM,mBAAmB,SAAA,EAAU;AACnC,QAAA,MAAM,YAAA,GAAe,MAAA,CAAO,iBAAA,IAAqB,EAAC;AAClD,QAAA,KAAA,CAAM,UAAA,CAAW,MAAA,GAAS,CAAC,GAAI,KAAA,CAAM,UAAA,CAAW,MAAA,IAAU,EAAC,EAAI,GAAG,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","sideEffects":false}
@@ -1,13 +1,11 @@
1
- import { registerModule } from './registry.js';
2
-
3
- function patchWebAssembly() {
1
+ function patchWebAssembly(registerModule) {
4
2
  if ("instantiateStreaming" in WebAssembly) {
5
3
  const origInstantiateStreaming = WebAssembly.instantiateStreaming;
6
- WebAssembly.instantiateStreaming = function instantiateStreaming(response, importObject) {
4
+ WebAssembly.instantiateStreaming = function instantiateStreaming(response, ...rest) {
7
5
  return Promise.resolve(response).then((response2) => {
8
- return origInstantiateStreaming(response2, importObject).then((rv) => {
6
+ return origInstantiateStreaming(response2, ...rest).then((rv) => {
9
7
  if (response2.url) {
10
- registerModule(rv.module, response2.url);
8
+ registerSafely(registerModule, rv.module, response2.url);
11
9
  }
12
10
  return rv;
13
11
  });
@@ -16,11 +14,11 @@ function patchWebAssembly() {
16
14
  }
17
15
  if ("compileStreaming" in WebAssembly) {
18
16
  const origCompileStreaming = WebAssembly.compileStreaming;
19
- WebAssembly.compileStreaming = function compileStreaming(source) {
17
+ WebAssembly.compileStreaming = function compileStreaming(source, ...rest) {
20
18
  return Promise.resolve(source).then((response) => {
21
- return origCompileStreaming(response).then((module) => {
19
+ return origCompileStreaming(response, ...rest).then((module) => {
22
20
  if (response.url) {
23
- registerModule(module, response.url);
21
+ registerSafely(registerModule, module, response.url);
24
22
  }
25
23
  return module;
26
24
  });
@@ -28,6 +26,12 @@ function patchWebAssembly() {
28
26
  };
29
27
  }
30
28
  }
29
+ function registerSafely(registerModule, module, url) {
30
+ try {
31
+ registerModule(module, url);
32
+ } catch {
33
+ }
34
+ }
31
35
 
32
36
  export { patchWebAssembly };
33
37
  //# sourceMappingURL=patchWebAssembly.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"patchWebAssembly.js","sources":["../../../src/patchWebAssembly.ts"],"sourcesContent":["import { registerModule } from './registry';\n\n/**\n * Patches the web assembly runtime.\n */\nexport function patchWebAssembly(): void {\n if ('instantiateStreaming' in WebAssembly) {\n const origInstantiateStreaming = WebAssembly.instantiateStreaming;\n WebAssembly.instantiateStreaming = function instantiateStreaming(\n response: Response | PromiseLike<Response>,\n importObject: WebAssembly.Imports,\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(response).then(response => {\n return origInstantiateStreaming(response, importObject).then(rv => {\n if (response.url) {\n registerModule(rv.module, response.url);\n }\n return rv;\n });\n });\n } as typeof WebAssembly.instantiateStreaming;\n }\n\n if ('compileStreaming' in WebAssembly) {\n const origCompileStreaming = WebAssembly.compileStreaming;\n WebAssembly.compileStreaming = function compileStreaming(\n source: Response | Promise<Response>,\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(source).then(response => {\n return origCompileStreaming(response).then(module => {\n if (response.url) {\n registerModule(module, response.url);\n }\n return module;\n });\n });\n } as typeof WebAssembly.compileStreaming;\n }\n}\n"],"names":["response"],"mappings":";;AAKO,SAAS,gBAAA,GAAyB;AACvC,EAAA,IAAI,0BAA0B,WAAA,EAAa;AACzC,IAAA,MAAM,2BAA2B,WAAA,CAAY,oBAAA;AAC7C,IAAA,WAAA,CAAY,oBAAA,GAAuB,SAAS,oBAAA,CAC1C,QAAA,EACA,YAAA,EAC6B;AAC7B,MAAA,OAAO,QAAQ,OAAA,CAAQ,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAAA,SAAAA,KAAY;AAChD,QAAA,OAAO,wBAAA,CAAyBA,SAAAA,EAAU,YAAY,CAAA,CAAE,KAAK,CAAA,EAAA,KAAM;AACjE,UAAA,IAAIA,UAAS,GAAA,EAAK;AAChB,YAAA,cAAA,CAAe,EAAA,CAAG,MAAA,EAAQA,SAAAA,CAAS,GAAG,CAAA;AAAA,UACxC;AACA,UAAA,OAAO,EAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AAEA,EAAA,IAAI,sBAAsB,WAAA,EAAa;AACrC,IAAA,MAAM,uBAAuB,WAAA,CAAY,gBAAA;AACzC,IAAA,WAAA,CAAY,gBAAA,GAAmB,SAAS,gBAAA,CACtC,MAAA,EAC6B;AAC7B,MAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,MAAM,CAAA,CAAE,KAAK,CAAA,QAAA,KAAY;AAC9C,QAAA,OAAO,oBAAA,CAAqB,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAA,MAAA,KAAU;AACnD,UAAA,IAAI,SAAS,GAAA,EAAK;AAChB,YAAA,cAAA,CAAe,MAAA,EAAQ,SAAS,GAAG,CAAA;AAAA,UACrC;AACA,UAAA,OAAO,MAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AACF;;;;"}
1
+ {"version":3,"file":"patchWebAssembly.js","sources":["../../../src/patchWebAssembly.ts"],"sourcesContent":["export type RegisterModuleCallback = (module: WebAssembly.Module, url: string) => void;\n\n/**\n * Patches the WebAssembly streaming APIs so that every compiled module gets\n * registered as a debug image under the URL of the response it was compiled\n * from.\n *\n * @param registerModule callback invoked for every successfully compiled module\n */\nexport function patchWebAssembly(registerModule: RegisterModuleCallback): void {\n if ('instantiateStreaming' in WebAssembly) {\n const origInstantiateStreaming = WebAssembly.instantiateStreaming as (\n response: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.WebAssemblyInstantiatedSource>;\n WebAssembly.instantiateStreaming = function instantiateStreaming(\n response: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.WebAssemblyInstantiatedSource> {\n return Promise.resolve(response).then(response => {\n return origInstantiateStreaming(response, ...rest).then(rv => {\n if (response.url) {\n registerSafely(registerModule, rv.module, response.url);\n }\n return rv;\n });\n });\n };\n }\n\n if ('compileStreaming' in WebAssembly) {\n const origCompileStreaming = WebAssembly.compileStreaming as (\n source: unknown,\n ...rest: unknown[]\n ) => Promise<WebAssembly.Module>;\n WebAssembly.compileStreaming = function compileStreaming(\n source: Response | PromiseLike<Response>,\n ...rest: unknown[]\n ): Promise<WebAssembly.Module> {\n return Promise.resolve(source).then(response => {\n return origCompileStreaming(response, ...rest).then(module => {\n if (response.url) {\n registerSafely(registerModule, module, response.url);\n }\n return module;\n });\n });\n };\n }\n}\n\nfunction registerSafely(registerModule: RegisterModuleCallback, module: WebAssembly.Module, url: string): void {\n try {\n registerModule(module, url);\n } catch {\n // a registration failure must never break the user's WebAssembly call\n }\n}\n"],"names":["response"],"mappings":"AASO,SAAS,iBAAiB,cAAA,EAA8C;AAC7E,EAAA,IAAI,0BAA0B,WAAA,EAAa;AACzC,IAAA,MAAM,2BAA2B,WAAA,CAAY,oBAAA;AAI7C,IAAA,WAAA,CAAY,oBAAA,GAAuB,SAAS,oBAAA,CAC1C,QAAA,EAAA,GACG,IAAA,EACiD;AACpD,MAAA,OAAO,QAAQ,OAAA,CAAQ,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAAA,SAAAA,KAAY;AAChD,QAAA,OAAO,yBAAyBA,SAAAA,EAAU,GAAG,IAAI,CAAA,CAAE,KAAK,CAAA,EAAA,KAAM;AAC5D,UAAA,IAAIA,UAAS,GAAA,EAAK;AAChB,YAAA,cAAA,CAAe,cAAA,EAAgB,EAAA,CAAG,MAAA,EAAQA,SAAAA,CAAS,GAAG,CAAA;AAAA,UACxD;AACA,UAAA,OAAO,EAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AAEA,EAAA,IAAI,sBAAsB,WAAA,EAAa;AACrC,IAAA,MAAM,uBAAuB,WAAA,CAAY,gBAAA;AAIzC,IAAA,WAAA,CAAY,gBAAA,GAAmB,SAAS,gBAAA,CACtC,MAAA,EAAA,GACG,IAAA,EAC0B;AAC7B,MAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,MAAM,CAAA,CAAE,KAAK,CAAA,QAAA,KAAY;AAC9C,QAAA,OAAO,qBAAqB,QAAA,EAAU,GAAG,IAAI,CAAA,CAAE,KAAK,CAAA,MAAA,KAAU;AAC5D,UAAA,IAAI,SAAS,GAAA,EAAK;AAChB,YAAA,cAAA,CAAe,cAAA,EAAgB,MAAA,EAAQ,QAAA,CAAS,GAAG,CAAA;AAAA,UACrD;AACA,UAAA,OAAO,MAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,EACF;AACF;AAEA,SAAS,cAAA,CAAe,cAAA,EAAwC,MAAA,EAA4B,GAAA,EAAmB;AAC7G,EAAA,IAAI;AACF,IAAA,cAAA,CAAe,QAAQ,GAAG,CAAA;AAAA,EAC5B,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoC,UAAU,EAAE,MAAM,cAAc,CAAC;AAWjF;;;GAGG;AACH,UAAU,iCAAiC;IACzC,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACzC;AAED,UAAU,4BAA4B;IACpC,IAAI,EAAE,iCAAiC,CAAC;CACzC;AAED,UAAU,sBAAsB;IAC9B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAwCD,eAAO,MAAM,eAAe;;CAAsC,CAAC;AAInE;;;;;;;;;GASG;AAEH,wBAAgB,WAAW,CACzB,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,EACzB,cAAc,CAAC,EAAE,MAAM,EACvB,oBAAoB,GAAE,MAAU,GAC/B,OAAO,CAgDT;AAYD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,IAAI,EAAE,EAAE,4BAA4B,GAAG,IAAI,CAElF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoC,UAAU,EAAE,MAAM,cAAc,CAAC;AAWjF;;;GAGG;AACH,UAAU,iCAAiC;IACzC,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACzC;AAED,UAAU,4BAA4B;IACpC,IAAI,EAAE,iCAAiC,CAAC;CACzC;AAED,UAAU,sBAAsB;IAC9B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAwCD,eAAO,MAAM,eAAe;;CAAsC,CAAC;AAInE;;;;;;;;;GASG;AAEH,wBAAgB,WAAW,CACzB,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,EACzB,cAAc,CAAC,EAAE,MAAM,EACvB,oBAAoB,GAAE,MAAU,GAC/B,OAAO,CAgDT;AAYD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,IAAI,EAAE,EAAE,4BAA4B,GAAG,IAAI,CAWlF"}
@@ -1,5 +1,10 @@
1
+ export type RegisterModuleCallback = (module: WebAssembly.Module, url: string) => void;
1
2
  /**
2
- * Patches the web assembly runtime.
3
+ * Patches the WebAssembly streaming APIs so that every compiled module gets
4
+ * registered as a debug image under the URL of the response it was compiled
5
+ * from.
6
+ *
7
+ * @param registerModule callback invoked for every successfully compiled module
3
8
  */
4
- export declare function patchWebAssembly(): void;
9
+ export declare function patchWebAssembly(registerModule: RegisterModuleCallback): void;
5
10
  //# sourceMappingURL=patchWebAssembly.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"patchWebAssembly.d.ts","sourceRoot":"","sources":["../../../src/patchWebAssembly.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAiCvC"}
1
+ {"version":3,"file":"patchWebAssembly.d.ts","sourceRoot":"","sources":["../../../src/patchWebAssembly.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;AAEvF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,sBAAsB,GAAG,IAAI,CAwC7E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/wasm",
3
- "version": "11.0.0-alpha.1",
3
+ "version": "11.0.0-beta.0",
4
4
  "description": "Support for WASM.",
5
5
  "repository": "git://github.com/getsentry/sentry-javascript.git",
6
6
  "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/wasm",
@@ -32,8 +32,8 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
- "@sentry/browser": "11.0.0-alpha.1",
36
- "@sentry/core": "11.0.0-alpha.1"
35
+ "@sentry/browser": "11.0.0-beta.0",
36
+ "@sentry/core": "11.0.0-beta.0"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "run-p build:transpile build:bundle build:types",
@@ -52,6 +52,7 @@
52
52
  "clean": "rimraf build coverage sentry-wasm-*.tgz",
53
53
  "lint:fix": "oxlint . --fix --type-aware",
54
54
  "lint": "oxlint . --type-aware",
55
+ "lint:types": "oxlint src --type-aware --type-check",
55
56
  "lint:es-compatibility": "es-check es2020 ./build/{bundles,npm/cjs}/*.js && es-check es2020 ./build/npm/esm/*.js --module",
56
57
  "yalc:publish": "yalc publish --push --sig"
57
58
  },