background.js content.js.
chrome.tabs.sendMessage(tabId, {}, function() { ... });
in the background to send messages to the content script that is entered on each web page that opens when the extension is installed and enabled. On content.js script use
chrome.runtime.onMessage.addListener(function(req, sender, callback) {
< here use condition to find out when this exetnsion popup.html should be opened and call the callback function which was passed in the argument list intially >
callback("something");
});
Here the callback function is defined in background.js and passed to content.js - this is the code to open a new extension window, such as
var panel_props = {
type: 'panel',
'width': width,
'height': height,
'left': left,
'top': top,
url: "chrome-extension://" + <extensionid>+ "/index.html"
}
chrome.windows.create(panel_props ,function (newWindow) {
vid = newWindow.id;
});
source
share