我希望实现以下代码:
//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)
答案 0 :(得分:0)
代码是否低于预期值?
//background.js
chrome.webRequest.onBeforeRequest.addListener(function (details) {
// use chrome.tabs
getAllTabUrls(function(urls) {
handleUrls(urls);
});
}, {urls: ["<all_urls>"]});