0

I hope implement following code:

//background.js
chrome.webRequest.onBeforeRequest.addListener(function (details) {
  var allTabUrls
  // use chrome.tabs
  getAllTabUrls(function(urls)) {
    allTabUrls = urls
  }
  handleUrls(allTabUrls)
}, {urls: ["<all_urls>"]})

I find all chrome callback is run in asynchronize, so my code will first run handleUrls(allTabUrls) before allTabUrls = urls, how to wait async function finish and then run handleUrls(allTabUrls)

anzeaucha
  • 157
  • 6

1 Answers1

0

Is the code below your expected it?

//background.js
chrome.webRequest.onBeforeRequest.addListener(function (details) {
  // use chrome.tabs
  getAllTabUrls(function(urls) {
    handleUrls(urls);
  });
}, {urls: ["<all_urls>"]});
Yoichiro Tanaka
  • 835
  • 7
  • 14