Web Worker URL

33 views
Skip to first unread message

James Mclellan

unread,
Jun 26, 2024, 8:37:33 AM (7 days ago) Jun 26
to TiddlyWiki
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 (https://developer.mozilla.org/en-US/docs/Web/API/Worker)

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(..)

Scott Sauyet

unread,
Jun 26, 2024, 9:20:28 AM (7 days ago) Jun 26
to TiddlyWiki
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

PMario

unread,
Jun 26, 2024, 9:31:55 AM (7 days ago) Jun 26
to TiddlyWiki
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.

Jeremy Ruston

unread,
Jun 26, 2024, 5:31:17 PM (6 days ago) Jun 26
to TiddlyWiki
Hi James

Besides the discussion group at https://talk.tiddlywiki.org, there are more developer-oriented discussions at https://github.com/Jermolene/TiddlyWiki5 

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

Reply all
Reply to author
Forward
0 new messages