Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
window.onload doesn't work in Firefox addon unless developer console is open

I'm creating an add-on on Firefox Dev Edition (v100.0b7) and the background script script.js doesn't invoke window.onload. It only works when the developer console is open in Inspect Element and I see the message it prints to console. The onload function is meant to start a listener as soon as the page loads, so the add-on popup (when clicking on icon in top-right) can send a request for DOM content. (afaik, popup has its own DOM so can't access page's DOM directly). I can tell it's not working when dev console is closed because the popup doesn't show any data fetched from page DOM

Here's the script files. The rest are HTML/CSS which work as expected:

manifest.json

{
    "manifest_version": 2,
    "name": "Extension",
    "version": "1.0",
    "content_scripts": [
        {
            "matches": [
                "https://example.com"
            ],
            "js": [
                "script.js"
            ]
        }
    ],
    "permissions": [
        "storage",
        "activeTab"
    ],
    "browser_action": {
        "default_title": "Extension",
        "default_icon": "icon.png",
        "default_popup": "index.html"
    },
    "browser_specific_settings": {
        "gecko": {
            "id": "example@example.com"
        }
    }
}

script.js

// This script should run immediately when window finishes loading

window.onload = function () {
    console.log("Loaded successfully");
    browser.runtime.onMessage.addListener(messageHandler);
};

addon-popup-window/script.js

// This script only runs when the popup is opened (user clicks top-right icon)

window.onload = function () {
    browser.tabs.query({ currentWindow: true, active: true })
    .then((tabs) => {
        for (const tab of tabs) {
            browser.tabs.sendMessage(tab.id, "message request")
            .then(responseHandler);
        }
    });
};
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!