1 | initial version |
One method to transfer information from a popup to the main content in a Chrome extension is through message passing using the chrome.runtime.sendMessage
and chrome.runtime.onMessage
API.
chrome.runtime.sendMessage
:chrome.runtime.sendMessage({data: info});
chrome.runtime.onMessage
:chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.data) {
// use the information from the message
}
});
chrome.runtime
API by including it in the permissions
section of the extension's manifest file:"permissions": [
"tabs",
"activeTab",
"storage",
"http://*/",
"https://*/",
"chrome://favicon/",
"chrome://extensions/",
"chrome://resources/"
]