Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module IIFE Crash in Web Worker (Brave/Chromium) #560

Open
justin0mcateer opened this issue Jul 28, 2022 · 0 comments
Open

Module IIFE Crash in Web Worker (Brave/Chromium) #560

justin0mcateer opened this issue Jul 28, 2022 · 0 comments

Comments

@justin0mcateer
Copy link

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch chance@1.1.8 for the project I'm working on.

I am using chance (via chance-generators) in a Web Worker environment (in Brave/Chromium 103). The module appears to take some special action if the environment appears to be a Web Worker. However, Chromium immediately crashes the IIFE on a undefined reference for 'chance'. I tried creating a variable with 'var chance;' in the main Web Worker script, but this had no impact.

I merely added a 'let' keyword before the assignment below and everything is now working fine.

Here is the diff that solved my problem:

diff --git a/node_modules/chance/chance.js b/node_modules/chance/chance.js
index 2b68a0a..5f483af 100644
--- a/node_modules/chance/chance.js
+++ b/node_modules/chance/chance.js
@@ -7889,7 +7889,7 @@ options,
     // if there is a importsScrips object define chance for worker
     // allows worker to use full Chance functionality with seed
     if (typeof importScripts !== 'undefined') {
-        chance = new Chance();
+        let chance = new Chance();
         self.Chance = Chance;
     }
 

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant