I'm working on a Chrome extension that will use content_script
to inject an iframe that will be a container of the popup.html. Everything is working fine, however, when testing it on a PDF viewer it does not correctly show on the PDF viewer as shown below.
On my codes, this is what I'm doing.
content_script.js
chrome.runtime.onMessage.addListener((request) => {
const contentScript = new ContentScript();
switch (request.action) {
case "browser_action_click":
contentScript.injectIframe();
break;
// remove codes from brevity
}
return true;
})
export class ContentScript {
injectIframe() {
const iframe = document.createElement("iframe");
iframe.setAttribute("id", "popup-iframe");
iframe.src = chrome.runtime.getURL("index.html");
// inject
if (document.body) {
document.body.insertBefore(iframe, document.body.lastChild);
}
iframe.onload = () => {
iframe.style.height = "428px";
}
}
}
content_script.css
#popup-iframe {
position: fixed;
top: 14px;
right: 20px;
width: 330px;
border: 0;
padding: 0;
box-sizing: border-box;
z-index: 2147483647;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14);
}
I also check on other extension and they were able to show their extension view correctly like the Evernote as shown below.
How do they correctly inject the iframe?