我正在使用 onUpdate 事件侦听器,但在加载完成之前和之后获得不同的 tabId:
chrome.tabs.onCreated.addListener(function(tab){
var i=ta.length;
ta[i]=new Array(5);
chrome.tabs.onUpdated.addListener(function(tid, changeInfo, tabO){
console.log(tid + " " + changeInfo.status);
console.log(tab.id + " " + tabO.title); //tab.id is form onCreated event
if( tid == tab.id && changeInfo.status === "complete" && tabO.title !== "New Tab") {
console.log(tabO.title+"******"+tabO.url);//then do stuff
}
}
}
控制台日志
>200 loading script_new.js:12
>200 stackoverflow.com/questions/ask script_new.js:13
>200 undefined script_new.js:12
>194 stackoverflow.com/questions/ask script_new.js:13
>200 undefined script_new.js:12
>198 stackoverflow.com/questions/ask script_new.js:13
>200 undefined script_new.js:12
>200 stackoverflow.com/questions/ask script_new.js:13
>200 complete script_new.js:12
>194 Ask a Question - Stack Overflow