Reputation: 2637
I'm making a google chrome extension to give the specific information (via ajax with server side) for different url (tab).
I use chrome.tabs.onUpdated
and chrome.tabs.onActivated
event listener in background.js
to detect whether the url of the active tab is changed, and then send an ajax request to change the icon using chrome.browserAction.setIcon
. (Yes, I would like to use browser action instead of page action because I wanna show some overall information of the extension in popup page, like Adblock Plus does)
However, what I can't figure out is:
chrome.tabs.sendMessage()
and chrome.runtime.onMessage
to communicate between background and the content scripts, but how could I communicate between the former and the popup script? I can't see that I need content scripts to modify the content of the page. Any idea? Thanks in advance!
Upvotes: 1
Views: 3582
Reputation: 10897
For question #1, since the background page and popup page both live in extension process, they can communicate with each other directly like setting variables or calling functions. You could check the following two posts:
As for question #2,
persistent: true
in manifest.json
, it will ensure the background page lives through the whole extension life.Upvotes: 3