chrome.tabs.onUpdated.addListener triggers multiple times

自古美人都是妖i 提交于 2020-01-06 08:05:53

问题


I observe that the onUpdated listener for the tabs API in Chrome does trigger multiple times.

  1. When I refresh the existing tab, the alert pops up 3 times
  2. When I load a different URL, the alert pops up 4 times

In the alert popup, I also see that there seem to be "intermediate" title tags.

How can I avoid this and reduce action to the final update?

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. :-(";
} */

});

来源:https://stackoverflow.com/questions/59504452/chrome-tabs-onupdated-addlistener-triggers-multiple-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!