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

286
Visualizações
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 à 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