我的扩展名是针对Facebook的。它会在第一次加载时正确记录选项卡状态更改,但是如果我通过当前页面上的链接导航到另一页面,则单击后立即报告changeinfo.status =='complete'。
我找不到任何提示我犯了错误的信息
chrome.tabs.onUpdated.addListener(check);
function check(tab_id, changeinfo, tab){
console.log("tab change: " + changeinfo.status);
// make sure the page is done loading
if ( !(tab.url !== undefined && changeinfo.status == "complete")) {
return;
}
if(tab.url.match(/facebook.com\/[^\/]*$/)){ //if the url of the tab matches a certain website
chrome.pageAction.show(tab_id); //show the icon (by default it is not shown).
console.log("accepted state: " + changeinfo.status);
}
}
最佳答案
如果适合您,可以尝试webNavigation API
表现
"permissions": ["webNavigation"]
后台脚本
chrome.webNavigation.onCompleted.addListener(function(details) {
if (details.url.startsWith('https://www.facebook.com/')) {
chrome.pageAction.show(details.tabId);
}
});
关于javascript - chrome.tabs.onUpdated.addListener-立即报告changeInfo.status =='complete',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31922683/