Skip to content

Commit e26cd1d

Browse files
committed
fix(browser): Handle data urls in errors caught by globalHandlersIntegration
1 parent 8f4d56f commit e26cd1d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function _enhanceEventWithInitialFrame(
171171

172172
const colno = column;
173173
const lineno = line;
174-
const filename = isString(url) && url.length > 0 ? url : getLocationHref();
174+
const filename = getFilenameFromUrl(url) ?? getLocationHref();
175175

176176
// event.exception.values[0].stacktrace.frames
177177
if (ev0sf.length === 0) {
@@ -199,3 +199,20 @@ function getOptions(): { stackParser: StackParser; attachStacktrace?: boolean }
199199
};
200200
return options;
201201
}
202+
203+
function getFilenameFromUrl(url: string | undefined): string | undefined {
204+
if (!isString(url) || url.length === 0) {
205+
return undefined;
206+
}
207+
208+
// stack frame urls can be data urls, for example when initializing a Worker with a base64 encoded script
209+
// in this case we just show the data prefix and mime type to avoid too long raw data urls
210+
if (url.startsWith('data:')) {
211+
const match = url.match(/^data:([^;]+)/);
212+
const mimeType = match ? match[1] : 'text/javascript';
213+
const isBase64 = url.includes('base64,');
214+
return `<data:${mimeType}${isBase64 ? ',base64' : ''}>`;
215+
}
216+
217+
return url.slice(0, 1024);
218+
}

0 commit comments

Comments
 (0)