I'm using the code from this thread (How to make side panel in chrome extension?) to inject a side panel instead of the default popup window and its working fine but my content scripts dont have access to any of the iframe's children.
I can search the DOM for the iframe, but doing iframe.children returns null even though they exist. And calling iframe.children in the google chrome console works as expected. I suspect it might be a security feature which restricts communication between content script and iframe contents, is there anyway to circumvent this? I need to add an event listener to a button in the iframe.
//Listening for background.js message that extension was pressed
chrome.runtime.onMessage.addListener(function (msg, sender) {
if (msg == "toggle") {
console.log("message received");
toggle();
}
});
//creates the iframe that will be the canvas for the panel
var iframe = document.createElement('iframe');
iframe.style.background = "black";
iframe.style.borderRadius = "15";
iframe.style.height = "90%";
iframe.style.width = "0px";
iframe.style.position = "fixed";
iframe.style.top = "0px";
iframe.style.right = "0px";
iframe.style.zIndex = "9000000000000000000";
iframe.style.border = "0px";
iframe.src = chrome.runtime.getURL("popup.html")
document.body.appendChild(iframe);
//this returns null for all elements in the popup.html that is placed on the iframe
console.log(document.querySelector("some element present in popup.html"));
edit: I forgot to say that inline code has been banned since manifest-v3 so i cant write any javascript code directly into the popup.html