Add html to new tab

I have a web-page with injected Content Script (CS). The Background Script (BS) sends message to create new tab. When the tab is created I send message to CS where id of the new tab is contained. Then In the CS when the message is intercepted, I send message to the tab just been created (Page Script - PS). The message adds styles to head and some PS is executed to add html… Here I add a break point. When I debug it the debugger stopped on the PS in the function which adds the html to webpage and everything is fine. If I remove the break point then the html is not added to the new tab. The tab is opened and the html is not added. I suspect the message was send before the DOM is loaded. It is not clear to me how to solve the problem.

I think nothing can be injected into privelaged pages like about:blank, about:newtab, etc. Do you think this is the issue that is affecting you?

No, there is just an empty tab using the addon address. I can add html there but the message comes earlier before the DOM is completed or before the javascript listener is started.

I think I will need to improve messaging, make a ready-test request, which will make it a bit more complicated but only solution.

Oh instead of that you can wait till its completley loaded. You can either inject your content script which is wrapped in a window.addEventListener of load (or DOMContentReady). Or you can change the run_at attribute of the content script in manifest.json to be at a latter stage, like document_end.

IHello,
I have the same problem " calling js with Background "
I tried window.addEventListener of load, and it does not work for Firefox 48

Sorry, really sorry for the begin of this post, if I use this, it is a well done :
function load() {
var el = document.getElementById(“t”);
el.addEventListener(“click”, lecjoa, false);
}

document.addEventListener(“DOMContentLoaded”, function(event) {
load();
});

cordially

Currently I am occupied with a work on different stuff so I cannot test it. But later I would try. Thanks