Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Firefox ChromeWorker not loading script

44 views
Skip to first unread message

mack...@gmail.com

unread,
Jul 22, 2012, 3:10:21 PM7/22/12
to
I have a requirement where I need to communicate with native code to perform some operations. I have been successful by using JS-Ctypes and things are panning out as expected. Since the communication from my web application with the native code takes some time, thus blocking the main JS thread consequently freezing the UI.

Thus I need to create a separate thread to be delegated with the communication with the native code and post back results to the main thread which will give the appropriate feedback to the user. Firefox [ChromeWorker](https://developer.mozilla.org/en/DOM/ChromeWorker) are exactly what I need to use, since they are independent threads with access to JS-Ctypes.

My problem is that for the life of me, I can't seem to load a script using that approach. This is what I currently have:

main.js

netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
Components.utils.import("resource://gre/modules/Services.jsm");

var worker = new ChromeWorker("js/fpman/myworker.js");
worker.onmessage = function(e){
console.log(e.data);
};

worker.postMessage('start');

myworker.js

self.onmessage = function(e){
var sum = 1 + 1;
postMessage("Sum is " + sum);
};

When that code runs in the main JS, I get this error on firebug console

Failed to load script: http://localhost:8080/myapp/js/fpman/myworker.js (nsresult = 0x805303f4)

Point to note, when I use a normal worker thread i.e

var worker = new Worker("js/fpman/myworker.js");

the js file (myworker.js) is loaded fine and I get the expected result, but of course that doesn't suffice my needs since a normal worker doesn't have access to JS-Ctypes. So it seems the problem is how am creating the ChromeWorker. Could someone please enlighten me on how to appropriately instantiate and use the ChromeWorker Object from an application. I have seen a lot of reference of usage of ChromeWorker in extensions, but that is not what I want, I want to use the ChromeWorker in my web application.

Thanks.

Boris Zbarsky

unread,
Jul 22, 2012, 4:40:35 PM7/22/12
to
On 7/22/12 3:10 PM, mack...@gmail.com wrote:
> Failed to load script: http://localhost:8080/myapp/js/fpman/myworker.js (nsresult = 0x805303f4)

I believe we disallow privileged code from loading unprivileged code in
a ChromeWorker, since that would be exploitable. Loading a chrome://
URI should work fine.

-Boris

mackelkin

unread,
Jul 23, 2012, 3:22:36 PM7/23/12
to
On Sunday, July 22, 2012 11:40:35 PM UTC+3, Boris Zbarsky wrote:
> On 7/22/12 3:10 PM, mackelkin wrote:
> > Failed to load script: http://localhost:8080/myapp/js/fpman/myworker.js (nsresult = 0x805303f4)
>
> I believe we disallow privileged code from loading unprivileged code in
> a ChromeWorker, since that would be exploitable. Loading a chrome://
> URI should work fine.
>
> -Boris

Boris -

Any pointer on how to achieve what you have suggested? A quick read reveals that chrome URLs are usually used to load XUL files which are delegated with creation and manipulation of elements. As for me, I just want to load javascript code that will communicate with my native code.

Thanks in advance.
0 new messages