I write little addon and point is in creating little block all thime when tab created or updated. I want to controll position of this block in browser popup.
So I created background script and included this function for connecting with content script:
// background.js:
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
function createOverlay() {
chrome.tabs.executeScript(null, {
file: "/content_scripts/content-script.js"
});
chrome.runtime.sendMessage({message: 'Add block'});
}
chrome.tabs.onCreated.addListener(createOverlay);
chrome.tabs.onUpdated.addListener(createOverlay);
});
…and nothing in content script:
// content-script.js:
function createOverlayElem(request, sender, sendResponse) {
console.log(request);
}
chrome.runtime.onMessage.addListener(createOverlayElem);
But I can’t get any messages in content script while my popup was not opened… So I can’t get access to DOM tree of current tab where I want include my HTML.
Help please who know how can I always paste the same HTML code for all created or updated browser tabs?