Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome chrome.tabs.onUpdate.addListener会多次触发_Google Chrome_Google Chrome Extension - Fatal编程技术网

Google chrome chrome.tabs.onUpdate.addListener会多次触发

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 API的未更新侦听器确实会多次触发

  • 当我刷新现有选项卡时,警报会弹出3次
  • 当我加载不同的URL时,警报会弹出4次
  • 在警报弹出窗口中,我还看到似乎有“中间”标题标签

    我如何避免这种情况并将操作减少到最终更新

    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”