Google chrome chrome.tabs.onUpdate.addListener会多次触发
我观察到Chrome中tabs API的未更新侦听器确实会多次触发Google chrome chrome.tabs.onUpdate.addListener会多次触发,google-chrome,google-chrome-extension,Google Chrome,Google Chrome Extension,我观察到Chrome中tabs API的未更新侦听器确实会多次触发 当我刷新现有选项卡时,警报会弹出3次 当我加载不同的URL时,警报会弹出4次 在警报弹出窗口中,我还看到似乎有“中间”标题标签 我如何避免这种情况并将操作减少到最终更新 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { /* Multiple Tasks: 1. Check whether title tag matche
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
/*
Multiple Tasks:
1. Check whether title tag matches the CPD Teamcenter title and custom success tab does not exist
2. If yes, trigger three actions:
a. move tab to new Chrome window
b. call external application to hide the window with the isolated tab
c. add custom success tag to identify that this was already processed
*/
const COMPARESTRING = "My Tab Title"
var title = tab.title;
alert(title) // this alert pops up 3 or 5 times!
/* if (title == COMPARESTRING) {
return "Match. :-)";
} else {
return "No match. :-(";
} */
});
对于许多子事件,都会调用onUpdate,因此请添加一个类似于
if(changeInfo.title)
的检查,或者您可以检查changeInfo.status==“complete”