paulocoutinhox / pdfium-lib

PDFium - Project to compile PDFium library to multiple platforms.
https://pdfviewer.github.io/
MIT License
915 stars 86 forks source link

Passing the wasm module into a web-worker #100

Closed inzanez closed 11 months ago

inzanez commented 12 months ago

Hi

did anyone succeed passing that WASM module into a web worker? I tried different techniques so far, but up until now always failed.

Priestch commented 12 months ago

@inzanez If you only want to use the wasm in a web worker, you should create and use the module in the web worker.

Passing data from the main thread to a worker thread has restrictions due to transferable objects and the structured clone algorithm. You can read more about transferable objects and structured clone to figure out why it not gona work.

inzanez commented 12 months ago

@Priestch I see. Yeah, I just never managed to create the wasm module in the worker because the standard 'js' file is not a module, and therefore I would need to use importScripts which does not exist in a module worker. So I had to manually patch the emscripten generated 'js' file.

Priestch commented 12 months ago

@inzanez You can try to use some bundler tool to bundle the wasm js file to the worker js file, then you hopefully can use the worker like before.

inzanez commented 11 months ago

@Priestch Yes, that seems to work out! Thanks