Is there an error in the way I'm implementing this? I'm opening a new tab and then sending a message to that tab, but then all other tabs that have a listener on them also receive the message.
In background.js:
chrome.tabs.create({url:chrome.extension.getURL("placement.html")},function(tab){
chrome.tabs.sendMessage(tab.id, {
"name":"name",
"payload":payload
});
});
In placement.js (run when placement.html is loaded):
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.name == "name") {
payload = request.payload;
}
});
I'm seeing that whenever a new tab gets created, the payload is sent to all tabs that have this onMessage listener. This code is relatively old, so I'm not sure if maybe something changed recently that affects the way chrome.tabs.sendMessage interprets "tab.id". Any help is appreciated!