Question

My Firefox extension is parsing big chunks of data. I would usually use WebWorkers to do this, however in XPCOM I seems that this is not an option. The ChromeWorker, https://developer.mozilla.org/en-US/docs/Web/API/ChromeWorker, seems to be obsolete and "discouraged in new projects".

Are there any options to use workers in a Firefox extension?

Was it helpful?

Solution

Short version: no, you cannot access XPCOM from a different thread. But that doesn't mean that you cannot use chrome workers.

Long version: Firefox used to allow accessing XPCOM from other threads, e.g. via ChromeWorker. This led to all kinds of issues like weird crashes or just plain inconsistent behavior. In the end Mozilla decided that supporting multithreaded XPCOM access was too complicated and error-prone, as was documenting its limitations and stopping people from shooting themselves in the feet.

With current Firefox versions, accessing XPCOM from ChromeWorker is no longer possible. ChromeWorker itself however isn't deprecated however even though the MDN comment can be easily misread as a general deprecation statement. The idea is that you would use ChromeWorker in combination with js-ctypes which will allow you to use native libraries (the ones provided by the operating system, libraries included in Firefox like NSS and libraries distributed with your extension) on a different thread.

Depending on what you are trying to achieve, this might work for you. E.g., if you need XPCOM for file access then you don't even need to use js-ctypes directly - OS.File API will do that for you. However, XPCOM access is limited to the main thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top