是否可以将选项卡切换排队,并让后台脚本知道何时可以处理下一个选项卡切换?
例如content.js
chrome.runtime.sendMessage("Do something", function(resp) {
doSomethingFor3Seocnds().then(function(resp) {
// now it's OK to go to the next tab
})
}
background.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
chrome.tabs.update(sender.tab.id, {"active": true}, function(tab){
// only run if OK to go to next tab
return sendResponse(tab)
});
});