This repository has been archived by the owner on Feb 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
CSP unsafe-eval
in Web Worker in Chrome Browser which is always strict mode
#450
Comments
The dirty hack I currently use to workaround this issue:
|
@benjamn Would you accept a PR to do something like this? try {
regeneratorRuntime = runtime;
} catch (accidentalStrictMode) {
if (typeof globalThis === "object") {
globalThis.regeneratorRuntime = runtime;
} else {
// This module should not be running in strict mode, so the above
// assignment should always work unless something is misconfigured. Just
// in case runtime.js accidentally runs in strict mode, we can escape
// strict mode using a global Function call. This could conceivably fail
// if a Content Security Policy forbids using Function, but in that case
// the proper solution is to fix the accidental strict mode problem. If
// you've misconfigured your bundler to force strict mode and applied a
// CSP to forbid Function, and you're not willing to fix either of those
// problems, please detail your unique predicament in a GitHub issue.
Function("r", "regeneratorRuntime = r")(runtime);
}
} The problem only happens in modern browsers, and they support A proper configuration solution would be to completely avoid regenerator in modern browsers, but many people have a single build and not multiple targets (and some libraries on npm rely on |
This was referenced Jul 19, 2021
Closed
@nicolo-ribaudo Yes, I'd be happy with that! |
Awesome, I'll prepare a PR by tomorrow! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
regenerator/packages/runtime/runtime.js
Lines 736 to 749 in dbbddd9
Web workers in latest Chrome stable enforces strict mode (not sure when it started to enforce), there is no way to turn it off.
Using regenerator under CSP will cause web worker to stop due to
unsafe-eval
.Setup described in #378 are somewhat configuration issue. However, now since there is no way to turn off strict mode in Web Workers in Chrome, it is no longer a configuration issue, and need to be properly fixed.
The text was updated successfully, but these errors were encountered: