Chrome extension, [removed] Why is this firing twice?

后端 未结 6 1817
南旧
南旧 2020-12-29 08:15

I have a very very simple bit of code in my (test) Chrome extension:

    function test()
    {
    alert(\"In test!\");
    }

   chrome.tabs.onUpdated.addLi         


        
6条回答
  •  既然无缘
    2020-12-29 08:54

    When you write the following code:

    chrome.tabs.onUpdated.addListener(function(tabid, changeinfo, tab) {
        var url = tab.url;
            if (url !== undefined) {
    
            test();
        }
    });
    

    You're calling addListener and telling it to call test() not immediately but rather whenever the tab is updated. Tab update events are broadcast by the Chrome browser itself, which in turn, causes your test() code to run.

提交回复
热议问题