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

283
Views
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
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!