-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(worker): delay Blob URL revocation to ensure webkit compatibility #19565
base: main
Are you sure you want to change the base?
Conversation
worker.addEventListener("error", () => { | ||
worker.addEventListener("message", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should call revokeObjectURL
if an error happened regardless of whether a message has been received because an error may happen before a message is received (or the user may not send any messages).
We need to append revokeObjectURL
call to the script so it is called even if the user didn't send any messages (for ESM it's done above in the declaration of blob
variable).
@sapphi-red Thanks for the feedback! To ensure
Would this approach work? Let me know if you have any suggestions! 🙌 |
I think that approach would work.
I think the message event handler can be removed. If the |
This reverts commit 2a4e8da.
@sapphi-red
However, I'm facing a linting issue because
Would it be better to conditionally check the Node.js version before calling it? |
Hi @sapphi-red,
However, while reviewing the CI failures, I noticed that the failing tests are not related to this change.
This issue seems independent of this PR and affects CI across multiple Node.js versions. So, I wanted to check:
Let me know what you think! Thanks as always for your guidance. |
It's because you are calling
I don't see those failures in the CI. The worker related tests are failing due to incorrect syntax. |
- Ensures proper cleanup by appending revokeObjectURL to the worker script - Fixes WebKit compatibility issues by managing Blob URL lifecycle - Maintains SharedWorker functionality using data URLs - Moves URL.revokeObjectURL call to runtime execution
Hi @sapphi-red, just an update! All CI checks have now passed successfully. I’ve fully implemented your feedback, including:
Let me know if there's anything else you'd like me to adjust. Thanks again for your feedback. |
const worker = new ${workerConstructor}(objURL, ${workerTypeOption}); | ||
worker.addEventListener("error", () => { | ||
(self.URL || self.webkitURL).revokeObjectURL(objURL); | ||
}); | ||
return worker; | ||
// Append cleanup code to the worker script to ensure revokeObjectURL is called | ||
const originalCode = jsContent; | ||
const cleanupCode = ';(function(){const cleanup=function(){(self.URL||self.webkitURL).revokeObjectURL("'+objURL+'")};self.addEventListener("error",cleanup);})();'; | ||
const finalCode = originalCode + cleanupCode; | ||
const cleanupBlob = new Blob([finalCode], { type: "text/javascript;charset=utf-8" }); | ||
const cleanupURL = (self.URL || self.webkitURL).createObjectURL(cleanupBlob); | ||
return new ${workerConstructor}(cleanupURL, ${workerTypeOption}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to create two Workers.
Description
URL.createObjectURL
.revokeObjectURL
is called only after the worker has successfully initialized, preventing WebKit from invalidating the Blob URL too early.Issue Reference
Fix Details
revokeObjectURL(objURL)
: Now executed inside aworker.addEventListener("message", ...)
instead of immediately.data:text/javascript;charset=utf-8, ...
instead of a Blob URL to ensure proper behavior.Testing
Playwright WebKit Test Results
Tests executed successfully using Playwright WebKit: