What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
To add a script to an iframe in Puppeteer, find the intended Frame and call await frame.addScriptTag(...). page.addScriptTag() is a shortcut for the page’s main frame; it does not target an arbitrary child frame.
Inject a script into the intended frame
Here is a runnable example for a page that contains a frame whose URL includes /embedded/:
As an Amazon Associate I earn from qualifying purchases.
const frame = page.frames().find(frame => frame.url().includes('/embedded/'));
if (!frame) {
throw new Error('Target frame was not found');
}
await frame.addScriptTag({
content: 'window.exampleFlag = true;',
});
Use a condition that uniquely identifies the frame on the page you are automating. Matching a distinctive URL fragment is one option; if the page exposes a stable frame name, you can inspect it through the frame’s element. A broad test such as “first child frame” can select the wrong frame when a page has multiple embeds.
Free tools Windows power users keep installed
One-click scans. No signup required.
Choose how to provide the script
Frame.addScriptTag() accepts inline content, a hosted script URL, or a local file path. It returns a promise for a handle to the inserted script element.
#1 Best Overall
| Use case | Example | Notes |
|---|---|---|
| Inline JavaScript | await frame.addScriptTag({ content: 'window.exampleFlag = true;' }); |
Useful for short snippets that should be added as a script element. |
| Hosted script | await frame.addScriptTag({ url: 'https://example.test/script.js' }); |
The frame loads the script from the specified URL. |
| Local file | await frame.addScriptTag({ path: './script.js' }); |
Relative paths are resolved from Node.js process.cwd(), not automatically from the JavaScript file’s directory. |
The documented options are content, id, path, type, and url. Set type: 'module' when the script should load as an ES module. See the FrameAddScriptTagOptions reference for the option details.
Make sure you have the right frame
A Puppeteer page has a frame tree. Use page.mainFrame() for the top-level document and Frame.childFrames() to inspect a frame’s direct children. The page.frames() example above searches the frames currently known to the page. A Frame also exposes url() and frameElement(); Puppeteer’s Frame class reference demonstrates inspecting a frame element’s name.
Rank #2
Frames can attach, navigate, or detach as the page runs. If a page creates the iframe dynamically, wait until it is available before selecting it. If it navigates or is replaced, locate the current frame again rather than assuming a previously selected reference still represents the intended document. The Page class reference documents the page’s frame-related context.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Use the main-frame shortcut only for the top-level page
await page.addScriptTag(options) is documented as a shortcut for await page.mainFrame().addScriptTag(options). Use it when the script belongs in the top-level document. For an iframe, call addScriptTag() on that iframe’s Frame instead. See Page.addScriptTag().
Use frame-scoped evaluation when no script element is needed
If your goal is to run code in the frame rather than add a <script> element, use Frame.evaluate():
const title = await frame.evaluate(() => document.title);
The function runs in the selected frame’s context, much like Page.evaluate() runs in the page context. Work in one frame does not automatically execute in its child frames, so select the frame where the code belongs. See the Frame.evaluate() reference.
Rank #4
Troubleshoot common problems
- The target frame was not found: The iframe may not have attached yet, or the URL condition may not match its current URL. Wait for the page’s frame to become available, then inspect
page.frames()and refine the identifying condition. - The script appears in the wrong document: Check whether you called
page.addScriptTag(), which targets the main frame. Select the childFrameand callframe.addScriptTag(). - The local script file cannot be found: Resolve the path relative to the process working directory. Check
process.cwd()or provide the intended absolute path. - The frame navigated or disappeared: Pages can attach, navigate, and detach frames dynamically. Reacquire the intended frame after the change and inject into the current document.
- The script runs in the parent but not an embedded document: Frame execution is scoped. Select and target each frame that needs the script; parent-frame evaluation does not automatically reach child frames.
Or skip the browser setup
If you only need a screenshot of a webpage rather than custom Puppeteer frame logic, ScreenshotNeo provides a website screenshot API. One GET request can return an image or PDF; for example, this cURL call saves a WebP screenshot of Stripe:
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorscurl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request details. Cookie banners, popups, and chat widgets are removed before capture; bot checks, blank pages, failed loads, and cache hits are not billed. Its MCP server provides screenshot tools for AI agents, including Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for 1,000 free screenshots a month, with no card required.
Best Value
- Used Book in Good Condition
Frequently Asked Questions
Can I add a script to every frame with one call?
No. Select each frame that needs the script and call its addScriptTag() method.
Does Frame.addScriptTag() return the script element?
It returns a promise for a handle to the inserted script element.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




