Can plugins use Web Worker?

I have been searching on the internet and found some old plugins that was able to use Web Workers. But when I tried to run it myself, I got error of Worker is not a constructor.

Plugin in question: GitHub - RyotaUshio/obsidian-web-worker-example

Is this feature deprecated? Or this is not available at all? I would love to be able to host WASM-based code in a web worker so it doesn’t block the UI when it is running.

Plugins can use web worker, it would help if you could share your code.

Hey @joethei , This is the plugin I am trying and the web worker example plugin is not working.

Meanwhile I am building my own plugin wanting to put Transformers.js into the plugin, and it is using WASM via onnxruntime-web. Since running neural net models are very compute intensive, I had to turn on the worker builds, and it is not working. For now I reverted to a branch that is working but not using web workers, it will halt the entire UI for a few seconds when the inferenceSession is running.

Interesting, the web worker sample worked on a vault suddenly. I am going to keep experiment with it then.

@joethei Hey Johannes, I have put together a branch that has loading issue with wasm. Here is the code:

Error message I am getting:

This might not have anything to do with web worker, but I don’t have a way to verify because bundled code is obfuscated. Will continue to investigate.

@joethei I finally arrived in the Worker is not a constructor error. Using Webpack to build this time (pnpm webpack in the project) and it gives me the following error:

Branch in question:

Also did a thread in the Transformers.js repository: [Question] Using transformers.js inside an Obsidian Plugin · Issue #291 · xenova/transformers.js · GitHub

Please do not ping multiple time moderators and team members, it’s against the code of conduct.

@lhr0909 maybe this issue can help, at least with your first error message.