views:

516

answers:

1

Hi,

Is threaded behaviour for Firefox extension possible?

I mean to have a "thread" running per Firefox tab.

Just finished an extension that does something to a page in a Firefox window, but figured out that it would require some major restructuring to get the extension working if I wanted to run the extension logic in every tab.

Methinks I would have to schedule processing of every tab content in a round robin fashion besides keeping a track of the context of each tab so that once I pause processing a tab and go to another one, the context of the previous tab is saved when I once again come back to it.

Yes - I would have to turn my extension into a process scheduler!

I would rather offload that job to Firefox or the OS.

While I can spawn a new window for every page I process so that the extension has to work only on a single page, I would rather use tabs.

Altough I have started coding a GM script so that I get the "threading" for free, I was wondering if any one had a better idea?

Something like spawning a thread from the extension for every tab created so that each thread is localized and dedicated to each tab?

+2  A: 

Sorry, my previous answer was wrong (because I've developed extensions long time ago, for Firefox 2). Now it looks like it is possible to use Javascript threads in extensions:

But it is unsafe to access DOM or UI from threads.

Also, you don't really need threads to be able to access several tabs. All tabs are equal to Firefox extension.

Eugene Morozov
Even with FF 3.1, worker threads?
EFraim
sorry, already noticed this.
Eugene Morozov
The point is to do exactly the SAME processing in all tabs concurrently
PoorLuzer
Again this depends. You can attach event handlers to tabs (for example to fire when document is loaded in the tab), or you can use generators to implement coroutines: https://developer.mozilla.org/en/New_in_JavaScript_1.7
Eugene Morozov