Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7443541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:20:47+00:00 2026-05-29T11:20:47+00:00

As I was writing a Firefox add-on using the Add-on SDK , I noticed

  • 0

As I was writing a Firefox add-on using the Add-on SDK, I noticed that the add-on code and the content script code block the execution of each other. Furthermore, the add-on code seems even to block the interaction with other Firefox windows (not just tabs).

What is the concurrency/process model of Firefox add-ons?

Is it possible to run add-on code and content script code concurrently without cooperative multithreading (a la timers)?

How many times is the add-on code loaded? Once per window? Once per tab? Once?

The documentation states:

The Mozilla platform is moving towards a model in which it uses
separate processes to display the UI, handle web content, and execute
add-ons. The main add-on code will run in the add-on process and will
not have direct access to any web content.

So I hope that in the future that they are indeed separate processes that will not interfere with each other, but that doesn’t seem to be the case now.


Update:

I have tried using a page-worker from the add-on code, but unfortunately that still blocks the content script (as well as all other javascript). I also tried using a web worker in the page-worker, but I get the following error when calling the web worker’s postMessage function.

TypeError: worker.postMessage is not a function

I also tried creating an iframe in the page-worker and then creating a web worker in the iframe, but unfortunately I cannot use window.addEventListener from the page-worker. I get the following error:

TypeError: window.addEventMessage is not a function

Finally, I tried to inject script (via script element) into the page-worker page to create a web worker which does seem to work. Unfortunately, I cannot communicate with this web worker because I can only send messages to it via document.defaultView.postMessage.

Oh the tangled webs I am weaving…

content-script -> add-on -> page-worker -> iframe -> web worker -> my code


I have included a simple example:

package.json

{
    "name": "test", 
    "author": "me", 
    "version": "0.1", 
    "fullName": "My Test Extension", 
    "homepage": "http://example.com", 
    "id": "jid1-FmgBxScAABzB2g", 
    "description": "My test extension"
}

lib/main.js

var data = require("self").data;
var pageMod = require("page-mod");

pageMod.PageMod({
    include: ["http://*", "https://*"],
    contentScriptWhen: "start",
    contentScriptFile: [data.url("content.js")],
    onAttach: function (worker) {
        worker.port.on("message", function (data) {
            // simulate an expensive operation with a busy loop
            var start = new Date();
            while (new Date() - start < data.time);
            worker.port.emit("message", { text: 'done!' });
        });
    }
});

data/content.js

self.port.on("message", function (response) {
    alert(response.text);
});

// call a very expensive operation in the add-on code
self.port.emit("message", { time: 10000 });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:20:48+00:00Added an answer on May 29, 2026 at 11:20 am

    The messaging system has been designed with a multi-process environment in mind. However, this environment didn’t emerge and it looks like it won’t happen in near future either. So what you really have is both the add-on and the content script running in the same process on the main thread (UI thread). And that means that only one of them is running at a time, as you already noticed there is no concurrency.

    Is it possible to run add-on code and content script code concurrently without cooperative multithreading (a la timers)?

    Yes, you use web workers (that have nothing to do with the page-worker module despite a similar name). This would be generally recommendable for expensive operations – you don’t want your add-on to stop responding to messages while it is doing something. Unfortunately, the Add-on SDK doesn’t expose web workers properly so I had to use the work-around suggested here:

    worker.port.on("message", function (message) {
        // Get the worker class from a JavaScript module and unload it immediately
        var {Cu} = require("chrome");
        var {Worker} = Cu.import(data.url("dummy.jsm"));
        Cu.unload(data.url("dummy.jsm"));
    
        var webWorker = new Worker(data.url("expensiveOperation.js"));
        webWorker.addEventListener("message", function(event)
        {
          if (event.data == "done")
            worker.port.emit("message", { text: 'done!' });
        }, false);
    });
    

    The JavaScript module data/dummy.jsm only contains a single line:

    var EXPORTED_SYMBOLS=["Worker"];
    

    How many times is the add-on code loaded? Once per window? Once per tab? Once?

    If you are asking about add-on code: it is loaded only once and stays around as long as the add-on is active. As to content scripts, there is a separate instance for each document where the script is injected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just writing some simple code and I noticed that using document.writeln doesn't
I am writing a FireFox add-on that displays webpages from my server as control
I'm writing a Firefox add-on that do something after the webpage is completely loaded.
I'm writing some JavaScript that interacts with a browser plugin (add-on in Firefox, ActiveX
I am writing a Firefox add-on that adds little icons next to all the
Hi: I'm writing a firefox extension (my first) that among other things, gets an
I'm writing some scripts that are using the HTML 5 file API in FireFox
I'm writing a Greasemonkey script that has a fair few user settings (just using
I'm writing a Firefox extension that needs to know what the username of the
I'm writing a Firefox extension that's to be used in house. Basically, I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.