addListener多次执行

时间:2015-01-19 19:00:07

标签: crossrider

我在extension.js中从我的background.js调用一个函数,但它似乎执行了几次(三次)而不是一次。从我的控制台消息看起来,背景只发送一次消息,但addListener执行三次。有什么想法可以避免这种情况吗?

Background.js:

appAPI.tabs.getActive(function(tabInfo) {
            console.log(1); // only once
            tabUrl = tabInfo.tabUrl;
            appAPI.message.toActiveTab({type:'clickedItem', url:tabUrl});
});

Extension.js:

appAPI.message.addListener(function(msg) {
        if (msg.type === 'clickedItem') {
            console.log(msg.url); // why three times?
        }
});

0 个答案:

没有答案