-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
Describe the bug
The current implementation of inline workers generated by Vite is not compatible with Playwright’s WebKit browser. Specifically, the WorkerWrapper
code fails when trying to create workers using a Blob URL in WebKit, leading to errors during tests.
The code in question is as follows:
function WorkerWrapper(options) {
let objURL;
try {
objURL = blob && (self.URL || self.webkitURL).createObjectURL(blob);
if (!objURL) throw "";
const worker = new Worker(objURL, {
name: options == null ? void 0 : options.name
});
worker.addEventListener("error", () => {
(self.URL || self.webkitURL).revokeObjectURL(objURL);
});
return worker;
} catch (e) {
return new Worker(
"data:text/javascript;base64," + encodedJs,
{
name: options == null ? void 0 : options.name
}
);
} finally {
objURL && (self.URL || self.webkitURL).revokeObjectURL(objURL);
}
}
The issue arises because the code attempts to immediately revoke the Blob URL in the finally
block:
objURL && (self.URL || self.webkitURL).revokeObjectURL(objURL);
This behavior invalidates the Blob URL before the worker can properly utilize it. Playwright’s WebKit (and likely other WebKit browsers) require the Blob URL to remain valid for the worker’s lifecycle, and prematurely revoking it causes failures. microsoft/playwright#33794 (comment)
What do you think, should it be fixed on the Vite side?
Reproduction
https://github.com/lozinsky/vite-inline-worker-playwright-webkit
Steps to reproduce
No response
System Info
System:
OS: macOS 15.2
CPU: (8) arm64 Apple M1 Pro
Memory: 189.03 MB / 16.00 GB
Shell: 3.7.1 - /opt/homebrew/bin/fish
Binaries:
Node: 20.12.2
npm: 10.5.0
Browsers:
Chrome: 131.0.6778.265
Safari: 18.2
npmPackages:
vite: 6.0.8 => 6.0.8
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.