Home > Software design >  How can i wait for chrome.tabs.executeScript?
How can i wait for chrome.tabs.executeScript?

Time:01-26

At the moment i'm using a timeout like this:

function injectScript() {
  chrome.tabs.executeScript({
    file: "inject.js"
  });
}

chrome.pageAction.onClicked.addListener((tab) => {
  injectScript();
  setTimeout(() => {
    doSomething(tab)
  }, 1000);
});

I want to replace the setTimeout to a better alternative.

CodePudding user response:

function injectScript() {
  chrome.tabs.executeScript({
    file: "inject.js"
  },
  ()=>{
   doSomething(tab)
  });
}
  •  Tags:  
  • Related