I am able to add HTML/CSS dynamically into the page using a content script. But I tried adding an iframe tag, and ran into a little bit of trouble.
Here is my code:
const myIFrame = `
<iframe src="${modalIFrameURL}"></iframe>
`;
let div = document.createElement('div');
div.style.zIndex = 9999999;
div.innerHTML = myIFrame;
document.body.insertBefore(div, document.body.firstChild);
note the modalIFrameURL value is:
chrome-extension://omelijcoklpokoeobkpepoipjpbakoeo/modal-iframe.html
This is what I get at the top left of the page:
If I hover over the gray fail box, it says:
Requests to the server have been blocked by an extension.
Does anyone know how to load an iframe from a content-script? What I am looking to do is load an HTML file from my Chrome Extension codebase into that iframe.
I am able to add HTML/CSS dynamically into the page using a content script. But I tried adding an iframe tag, and ran into a little bit of trouble.
Here is my code:
const myIFrame = `
<iframe src="${modalIFrameURL}"></iframe>
`;
let div = document.createElement('div');
div.style.zIndex = 9999999;
div.innerHTML = myIFrame;
document.body.insertBefore(div, document.body.firstChild);
note the modalIFrameURL value is:
chrome-extension://omelijcoklpokoeobkpepoipjpbakoeo/modal-iframe.html
This is what I get at the top left of the page:
If I hover over the gray fail box, it says:
Requests to the server have been blocked by an extension.
Does anyone know how to load an iframe from a content-script? What I am looking to do is load an HTML file from my Chrome Extension codebase into that iframe.
Share Improve this question asked Feb 4, 2018 at 5:19 Alexander MillsAlexander Mills 100k165 gold badges532 silver badges909 bronze badges 10- If you make a new profile and only install the extension you're testing, does the issue still occur? – Wesley Smith Commented Feb 4, 2018 at 5:21
- Right so you think another extension is blocking the iframe? If that's the case, then my iframe solution is not gonna work, simply because other users will likely face the same problem I am facing. Other users will have extensions that block iframes or whatever...right? – Alexander Mills Commented Feb 4, 2018 at 5:53
-
yeah even with a new profile and just my extension loaded, I get the same error:
Requests to the server have been blocked by an extension.
– Alexander Mills Commented Feb 4, 2018 at 5:58 - 1 Possibly given the content of the message. I would start a new profile and add one extension at a time till it happens again to narrow down the extension causing the issue. Then, see why that extension is causing the issue. – Wesley Smith Commented Feb 4, 2018 at 5:58
- 1 Thats possible depending on the styling of the iframe. Right click on the edge of the frame and click "inspect". That'll open the dom inspector in the dev tools console. Hover over the iframe node in the console and you should see clearly all the space the frame takes up. Then you can play with the css for the frame in the right had CSS panel till you get it to where it doesnt interfere with the page. – Wesley Smith Commented Feb 4, 2018 at 19:46
1 Answer
Reset to default 15I ran into this a few weeks ago. I found that adding a "web_accessible_resources" section to my manifest.json file resolved it.
From what you are calling out, it should look like:
"web_accessible_resources": [
"modal-iframe.html"
],
https://developer.chrome./extensions/manifest/web_accessible_resources
Just make sure that you are including "modal-iframe.html" in your extension build directory.
Hope that helps.