Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
How to send message to newly created window tab using chrome.windows.create

I created a new chrome window tab via extension but I can't send message to its content script, the event never fired

background.js

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
    if (request.action == "run") {
        chrome.tabs.create({
            url: 'https://vnexpress.net/',
            active: false
        }, function (tab) {
            chrome.windows.create({
                tabId: tab.id,
                type: 'popup',
                focused: true
            }, function (win) {
                chrome.tabs.sendMessage(win.tabId, { action: "scrape" });
            });
        });
    }

    sendResponse();
})

content_script.js

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
    if (request.action == "scrape") {
        alert("Scraping!!!");
        console.log("Scraping")
        //This never run
    }
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The logic seems to be correct, but probably sendMessage is being called before content_script.js is run.

To verify this, use console.log(new Date) before the sendMessage line and another one in the content script. You can then compare the dates.

If that's the issue, you could have the content script message the background script when it loads instead, so there's no race condition.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda