[tw5] Web Worker URL

Good morning all.

I have a CPU-intensive data operation that I’m trying to spread across multiple CPUs in TiddlyWiki using a Web Worker (Worker - Web APIs | MDN)

I have created a server-side library module and a client-side library module. The client-side constructor of the worker is supposed to contain a URL to the server library

var w = new Worker("$:/core/modules/libraries/webworker-server.js");

However, this generates an error “Security Error: Content at file:///home/james/Desktop/Crunchy%20RPG/experiment.html may not load data from file:///home/james/Desktop/Crunchy%20RPG/$:/core/modules/libraries/webworker-server.js.”

Not sure how to reference the server library internal to the TiddlyWiki. This works fine for require(…)

I don’t have any answers, but I would suggest that you post this instead at https://talk.tiddlywiki.org/. Most community activity happens there.

(Note that threads from Google Groups are included there, but are read-only.)

– Scott

Hi,

From your description I’m not really sure how your code looks like, but the Security Error, says file://.. With modern browsers we are not allowed to require() code from a file-url, due to security concerns. So the best way is, to also add the library to the client as a plugin. Then you should be able to use the same require with the server and the client.

But as I wrote a bit more code context will be needed.

Hi James

Besides the discussion group at https://talk.tiddlywiki.org, there are more developer-oriented discussions at GitHub - Jermolene/TiddlyWiki5: A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.

To answer your question, you’ll need to make a Blob Url of the content of the tiddler. The closest example in the core code is probably here where we a Blob Url is used to load a binary Wasm tiddler. In your case, the tiddler is plain text so the blob construction will be simpler.

Best wishes

Jeremy