I found numerous ways to send data from contents TO background.js actively.
However, it there any active way to notify or send message FROM background.js TO contents script?
Seems like the usual mean to achieve message passing is addListener in background, and passing message from contents and get return value as call back.
Since the port keeps changing as I open new pages, opening port seems not an option.
I need way around : sending message from background and contents has listner.
In details of my use case is ..
I have Cookie change listener in background.js (chrome.cookies.onChanged.addListener)
and I’d like to notify to contents script every time cookies has changed/updated.
in background.js
function cookieUpdate(info) {
// need to notify to contents script
};
chrome.cookies.onChanged.addListener(cookieUpdate);
Have a try on chrome.tabs.sendRequest(tabId, {}, callback);