While troubleshooting my extension, I have discovered that a content script is executed repeatedly so having
chrome.runtime.onMessage.addListener(function(message, sender, sendResponseFn){ ...}
in it will install the listener repeatedly and will thus lead to multiple invocations of the listener. I haven't however seen this mentioned in the docs and can see that
sample extensions do exactly this, i.e. have addListener at top level of the content script.
I work around the problem by using
var initialized;
if (typpeof initialized === 'undefined') {
initialized = true;
chrome.runtime.onMessage.addListener(function(message, sender, sendResponseFn){ ...}
}
but I would like to understand if this is some error on my part or of the docs are outdated or what is going on.
I am using Chrome 33.0.1750.154 m
thank you!