It is possible for a content script to talk to the background page using
chrome.extension.sendRequest
It is possible for the background page to talk to the content script using
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {}, function(response) {
// do something with response here
})
})
It is possible for a page_action popup to talk to the background page using
chrome.extension.sendRequest
So, is there a way for the background page to talk to the popup?
The use case is one where
-
the popup is open and wants to get some information from the page
-
so it sends a request to the background page
-
the background page now sends a request to the content script
-
and the content script sends a response back to the background page.
-
So now the background script needs to send this to the popup !!
How does that happen?
You can, using
chrome.extension.sendRequest, as long as popup remains open.But looking at your workflow, why not just skip background page and send request to a content script directly from a popup? Then you can just use
sendResponse()to return the data back to popup.