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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working in web worker #127

Closed
julenwang opened this issue Dec 17, 2023 · 3 comments · Fixed by dlemstra/Magick.Native#36
Closed

Not working in web worker #127

julenwang opened this issue Dec 17, 2023 · 3 comments · Fixed by dlemstra/Magick.Native#36
Milestone

Comments

@julenwang
Copy link

magick-wasm version

0.0.26

Description

Not working in web worker context

I cannot find this code in repo, I guess it generated by compiler

Sorry, My English is bad

Steps to Reproduce

use @imagemagick/magick-wasm in web worker

Images

image image image
@julenwang
Copy link
Author

I fixed it use patch-package, It is working well

diff --git a/node_modules/@imagemagick/magick-wasm/dist/index.mjs b/node_modules/@imagemagick/magick-wasm/dist/index.mjs
index 2a43ef4..2ef32fb 100644
--- a/node_modules/@imagemagick/magick-wasm/dist/index.mjs
+++ b/node_modules/@imagemagick/magick-wasm/dist/index.mjs
@@ -95,9 +95,19 @@ class Hi {
    */
   message;
 }
+
 var Fi = (() => {
   var t = typeof document < "u" && document.currentScript ? document.currentScript.src : void 0;
   return function(a = {}) {
+
+    // hack in worker
+    if(typeof window === "undefined"){
+      var window = {
+        crypto,
+        prompt: console.log
+      }
+    }
+
     var e = a, l, m;
     e.ready = new Promise((n, r) => {
       l = n, m = r;

@nathan-nusign
Copy link

I can confirm that this patch fixes the issue. It would be great to get this merged soon!

@dlemstra
Copy link
Owner

@Peeterush created a PR to resolve this. But I also wonder if we could add an extra check to test if the code can be executed in a webworker and maybe also inside a web browser?

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

Successfully merging a pull request may close this issue.

3 participants