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:
// 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?
I write little addon and point is in creating little block all thime when tab created or updated.
You want to insert an HTML element into every page? If so, then all you need is a "content_script" defined in the manifest.json. You don’t need to do anything in the background script for that.
I want to controll position of this block in browser popup.
You want to be able to move that element in the current tab / in all tabs with controlls that you have in the popup of the "browser_action"? If so, then your popup needs to send messages to that / those tabs.
Something like: