0

I'm calling a function from my background.js in the extension.js but it seems it is executed several (three) times instead of once. From my console messages it looks like that the backgound only sends its message once, but the addListener executes three times. Any ideas to avoid this?

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?
        }
});
Wienel
  • 3
  • 3
  • I'm working in Chrome if that matters – Wienel Jan 19 '15 at 19:00
  • I tested the code provided in Chrome/Win8.1 and I received the message only once. Do you have the run in iframes feature on? If so and there are 2 iframes on the page you are testing, the message will be received 3 times. Alternatively, provide the extension id and I'll check it for you [**Disclosure**: I am a Crossrider employee] – Shlomo Jan 20 '15 at 09:50
  • Yes, thanks, problem solved. I had to disable the 'run in iframes' feature. – Wienel Jan 24 '15 at 15:00

0 Answers0