views:

90

answers:

1

I would like to use the Web Worker facility introduced in Firefox 3.5 to enhance a Greasemonkey script I'm working on.

Is this even possible?

I've done some experimentation, but I can't get past the issue of loading a worker script from an arbitrary domain.

For example, this does not work:

var myWorker = new Worker("http://dl.getdropbox.com/u/93604/js/worker.js");

This code generates an error message in my Firebug console:

Failed to load script: http://dl.getdropbox.com/u/93604/js/worker.js (nsresult = 0x805303f4)

Apparently there's a limitation that does not allow you to start a worker from a URL that's not relative to the base URL of the calling script. You can load a worker script at a relative URL like this just fine:

var myWorker = new Worker("worker.js");

But there's no way for me to get the worker script on the user's filesystem so that it could be at a path relative to the calling script.

Am I screwed here? Should I give up on trying to use workers within my Greasemonkey script?

+1  A: 

See:

http://stackoverflow.com/questions/1549614/can-i-load-a-web-worker-script-from-an-absolute-url

Zac Bowling
The context of Greasemonkey makes it unique, in my opinion. Greasemonkey is known to enable scenarios that aren't generally possible, like cross-domain Ajax requests. Maybe other Greasemonkey users are aware of tricks that could help me.
mattblodgett
There are some hacks people wrote for the Gears WorkerPool code (Check out the cross origin flag: http://code.google.com/apis/gears/api_workerpool.html#cross_origin ) . Greasemonkey also runs in the domain of an extension in Firefox so the guide on Workers inside Extensions on the MDC archive might help. Might be able to load a JS via the chrome:: url.
Zac Bowling
The only way greasemonkey can make it unique is if greasemonkey adds code for it to be unique. The greasemonkey script is only going to be able to load scripts from the same origin, which is why it's failing.
sdwilsh