You can do so by using ChromeWorker instead of the standard Worker
object. It works exactly like a standard Worker
, except that it has access to js-ctypes via a global ctypes object available in the global scope of the worker
Obsolete since Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
nsIWorkerFactory
interface has been removed
Starting in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1), you can use workers in JavaScript code modules (JSMs). This lets you run code in a separate thread from your JSM. To create a ChromeWorker for this purpose, you need to use the nsIWorkerFactory
interface:
var workerFactory = Components.classes['@mozilla.org/threads/workerfactory;1'] .createInstance(Components.interfaces.nsIWorkerFactory); var worker = workerFactory.newChromeWorker('script_url.js');
This will create a new chrome worker that will immediately begin to run the script at the specified URL (in this case, "script_url.js"). For example, "script_url.js" can be "chrome://extension_name/content/script.js".