Injecting a script tag (or script code) to inside every iframe
See original GitHub issueHi,
My goal is to re-initialize certain Javascript read-only variables such as window.screen.pixelDepth for the entire page, including iframes in it. I can add a script tag to the top-level HTML by using this code:
await page.evaluate(scriptText => {
const el = document.createElement('script');
el.type = 'text/javascript';
el.textContent = scriptText;
document.head.prepend(el);
}, scriptToInject);
However, this does not get applied to the HTML pages loaded by <iframe> tags. I wonder how I can inject Javascript for all HTML pages inside iframes of a top-level page.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
inject a javascript function into an Iframe - Stack Overflow
First of all you can only accomplish this if your frame and the page displaying it is within the same domain (Due to...
Read more >Using Iframes vs Scripts for Embedding Components
Out of these methods, IFrame and Script Tags stand out. Both of them allow content to be embedded dynamically. In this article, I...
Read more >inject JS code inside a frame that is inside an iframe
Hello,. I want to inject JavaScript code with a chrome extension, within a frame that is inside an iframe and that inside another...
Read more >How to inject JavaScript into an iFrame - Jaspreet Chahal
The JavaScript · injectJS() { · var iFrameHead = window.frames["myiframe"].document.getElementsByTagName("head")[0]; · var myscript = document.
Read more >javascript iframe injection - CodePen
URL Extension Required. When linking another Pen as a resource, make sure you use a URL Extension of the type of code you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, this works nicely. Thanks very much for your clever solution!
Another attempt: