Content Scripts and Web Workers

1,664 views
Skip to first unread message

Dogan Narinc

unread,
Dec 4, 2010, 11:06:23 AM12/4/10
to Chromium-extensions
Hi all,

I have been trying to create Web Workers from within Content Scripts
but was unsuccessful. Does anyone know if this is as expected?

If as expected the obvious alternative would be to delegate that to
the Background Page, which comes at the cost of adding a message-
passing layer... Any thoughts on other ways to achieve this?

Cheers,

Dogan

Arne Roomann-Kurrik

unread,
Dec 6, 2010, 3:34:45 PM12/6/10
to Dogan Narinc, Chromium-extensions
What exactly is the issue you're seeing?

~Arne



--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Dogan Narinc

unread,
Dec 6, 2010, 6:31:54 PM12/6/10
to Chromium-extensions
Hi Arne,

I have the following simple web worker.

[code file="web_worker.js"]
postMessage("Hello World!");
[/code]

I am running the following code in both my content script and
background page. I can see the Hello World message in the background
page only.

[code]
var workerURL = chrome.extension.getURL("web_worker.js");
var worker = new Worker(workerURL);

worker.onmessage = function(event) {
console.log('Web worker says: ' + event.data);
};
worker.onerror = function(event) {
console.error('Web worker says: ' + event.data);
};
[/code]

If that helps, when I debug the code above in my content script the
execution stops just after the line "var worker = new
Worker(workerURL);", while it goes through the rest in the background
page.

I have Chrome 8.0.552.215 beta on installed on Fedora.

Dogan

On Dec 6, 8:34 pm, Arne Roomann-Kurrik <kur...@chromium.org> wrote:
> What exactly is the issue you're seeing?
>
> ~Arne
>
>
>
>
>
>
>
> On Sat, Dec 4, 2010 at 8:06 AM, Dogan Narinc <dogan.nar...@gmail.com> wrote:
> > Hi all,
>
> > I have been trying to create Web Workers from within Content Scripts
> > but was unsuccessful. Does anyone know if this is as expected?
>
> > If as expected the obvious alternative would be to delegate that to
> > the Background Page, which comes at the cost of adding a message-
> > passing layer... Any thoughts on other ways to achieve this?
>
> > Cheers,
>
> > Dogan
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
> > .

Mohamed Mansour

unread,
Dec 6, 2010, 8:41:55 PM12/6/10
to Dogan Narinc, Chromium-extensions
Hi Dogan,

I believe it is similar to this bug: http://crbug.com/45382

If you add a try catch block when you load a Worker within a Content Script, you will see a SECURITY_ERR. That might be related to that bug because it is somehow treating extension URLs not being part of the same extension.

-
Mohamed Mansour



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Dogan Narinc

unread,
Dec 7, 2010, 3:38:13 PM12/7/10
to Chromium-extensions
Hi Mohamed,

Thanks for your answer! I have added a comment on the page you
mentioned with an updated version of the test case I've sent here. I
hope it can get fixed soon as Web Workers seem to be a very nice
feature to have in Content Scripts.

I guess we'll have to live with creating them in the Background Page
for now...

Dogan
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
Reply all
Reply to author
Forward
0 new messages