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

287
Vistas
Chrome Extension Tabs onUpdated with status === 'complete' works too early

background.js

// create a new tab when alarmed
chrome.alarms.onAlarm.addListener(function(alarm) {
  if (alarm.name === 'myAlarm') {
    let tabId = 0;
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
      const url = 'https://www.vk.com/feed';
      chrome.tabs.create({ url }, (tab) => {
        tabId = tab.id!;
      });
    });
  }
});

// wait till the new tab will load completely to do the stuff with DOM in the new tab from content.js
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
      if (tab.url!.indexOf('https://www.vk.com/feed') != -1 && changeInfo.status == 'complete') {
      // setTimeout
        chrome.tabs.sendMessage(tabId, {
          from: Sender.React,
          message: 'GET_COOKIES'
        });
      }
    });

I've tried this code above, but it doesn't work I am getting status === 'complete' and sending messages to my content.js too early when DOM is not ready (content.js can't find an element and doesn't do anything when it's getting 'GET_COOKIES' message) When I add setTimeout, with, for example, 3000ms for sending messages - that's works fine! But I don't want to do this, because some users can have an unstable connection and they will need more than 3 seconds, and some will need less than 3 seconds with more good connection I've tried 'onHistoryStateUpdated' with 'webNavigation' - but it seems doesn't work too

How should I resolve this? Please, help...

about 4 years ago · Juan Pablo Isaza
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