Closed Tronic closed 4 years ago
For anyone else who wants to run this in a Web Worker, try doing what I did:
In the worker script, import the script using importScripts
importScripts("/node_modules/argon2-browser/lib/argon2.js");
Now open lib/argon2.js and scroll down to the function 'loadWasmModule'
Change:
return import('/node_modules/argon2-browser/dist/argon2.js');
To:
return importScripts('/node_modules/argon2-browser/dist/argon2.js');
When running the actual worker, remember to include '{type: "module"}'
var worker = new Worker("worker.js", { type: "module" });
FWIW, I got it working in https://arcyph.zi.fi/ and that solution may be freely forked by anyone who is interested (view source).
@littalthiefu Thank you very much. Your comment saved me a lot of time and headache.
In my case, I had the luxury of having webpack available which makes it super simple to run this in a webworker, in what I consider to be a very maintanable way.
npm i --save-dev worker-loader
.src
just as you would any other js, no need to worry about importscripts... don't even have to change your webpack config, can just do an inlined import of your worker.I built a wrapper module so you can easily use this module as a webworker in a webpack (or other project). Argon2-browser is loaded inline (no import scripts which don't get SRI!!), so you can easily use it in any project.
yarn add argon2-webworker
https://github.com/etesync/argon2-webworker
I haven't implemented all of the API, but the API is identical to this module, so using it is exactly the same.
I see that the demo page runs in a worker thread but this code isn't included in the Node distribution and from what I can see from the demo page, it is quite complicated. I can't get the normal version loading because of
Are you planning to include proper worker support & code in the distribution as well? Otherwise, is there any simple way to get it working?