如何在另一个chrome事件中获取所有标签网址

时间:2016-02-09 15:34:41

标签: javascript google-chrome google-chrome-extension

我希望实现以下代码:

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

我发现所有chrome回调都是在异步中运行的,所以我的代码将首先在handleUrls(allTabUrls)之前运行allTabUrls = urls,如何等待异步函数完成然后运行handleUrls(allTabUrls)

1 个答案:

答案 0 :(得分:0)

代码是否低于预期值?

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