I have Opera sidebar extension
and when extension is fired (sb opened), I need to inject some code with message listener in active tab
code works fine, the problem is that if I close sidebar and open it again, I'll get another listener injected (console will log two times when message is send)...and on another reopen +1..and so on.
I tried to fix this with removing listener, but it doesn't work.
I'm still getting +1 on console for every new extension start (injecting).
And I can't place addListener in removeListener callback. Doesn't work at all
(I guess it doesn't support it in this form)
here is the code I've bee injecting:
chrome.tabs.executeScript({code:
"chrome.runtime.onMessage.removeListener(msgL);\
chrome.runtime.onMessage.addListener(msgL);\
function msgL(msg) {\
if (msg.test) console.log('aaaaaaaaaaaaaaaaaaaaaaaaa');\
}"
}, function(result) {
if (!result) console.log(chrome.runtime.lastError);
});
How can I clear previous listener when injecting new one?