Chrome extension, javascript: Why is this firing twice?
问题 I have a very very simple bit of code in my (test) Chrome extension: function test() { alert("In test!"); } chrome.tabs.onUpdated.addListener(function(tabid, changeinfo, tab) { var url = tab.url; if (url !== undefined) { test(); } }); My question is, why is test() firing twice? And more importantly, how do I make it fire just once? 回答1: Have a look at what the different states are when the event is dispatched. I presume, that it is getting dispatched once when the state is "loading" or when