Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda