diff --git a/CHANGELOG.md b/CHANGELOG.md index b588cf99ab66..e13bfdfbd13b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Work in this release was contributed by @PeterWadie and @akshitsinha. Thank you The SvelteKit SDK now supports SvelteKit 3, including client-side pageload and navigation tracing and server-side native tracing, alongside continued SvelteKit 2 support. No Sentry-specific setup changes are required. The SDK detects your SvelteKit version and picks the right implementation automatically. +### Other Changes + +- fix(replay): Set `text/javascript` MIME type on the compression worker Blob ([#22377](https://github.com/getsentry/sentry-javascript/pull/22377)) + ## 10.66.0 - chore(node-core): Deprecate `@sentry/node-core` package ([#22285](https://github.com/getsentry/sentry-javascript/pull/22285)) diff --git a/packages/replay-worker/src/index.ts b/packages/replay-worker/src/index.ts index 103568d7a8d4..f038e687c778 100644 --- a/packages/replay-worker/src/index.ts +++ b/packages/replay-worker/src/index.ts @@ -4,6 +4,12 @@ import workerString from './worker'; * Get the URL for a web worker. */ export function getWorkerURL(): string { - const workerBlob = new Blob([workerString]); + // Safari (particularly on iOS) validates the MIME type of a Blob before it + // will execute it as a classic Worker script. A Blob created without an + // explicit `type` defaults to an empty string, which WebKit may reject, + // firing a bare `error` event with no message. Blink/Gecko are lenient here, + // so this only manifests on Safari. Set an explicit JavaScript MIME type so + // the worker loads across browsers. + const workerBlob = new Blob([workerString], { type: 'text/javascript' }); return URL.createObjectURL(workerBlob); } diff --git a/packages/replay-worker/test/unit/getWorkerURL.test.ts b/packages/replay-worker/test/unit/getWorkerURL.test.ts new file mode 100644 index 000000000000..7429b92584c5 --- /dev/null +++ b/packages/replay-worker/test/unit/getWorkerURL.test.ts @@ -0,0 +1,25 @@ +/** + * @vitest-environment jsdom + */ + +import { describe, expect, it, vi } from 'vitest'; +import { getWorkerURL } from '../../src'; + +describe('getWorkerURL', () => { + // Safari (esp. iOS) rejects executing a Blob worker without a JavaScript MIME + // type, firing a bare `error` event. The Blob must be tagged `text/javascript` + // so the worker loads across browsers. + it('creates the worker Blob with a JavaScript MIME type', () => { + // jsdom does not implement `URL.createObjectURL`, so stub it and capture the Blob. + const createObjectURL = vi.fn<(blob: Blob) => string>().mockReturnValue('blob:mock'); + URL.createObjectURL = createObjectURL as unknown as typeof URL.createObjectURL; + + const url = getWorkerURL(); + + expect(url).toBe('blob:mock'); + expect(createObjectURL).toHaveBeenCalledTimes(1); + const blob = createObjectURL.mock.calls[0]![0]; + expect(blob).toBeInstanceOf(Blob); + expect(blob.type).toBe('text/javascript'); + }); +});