PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteFind the Puppeteer Frame you want, then call await frame.addScriptTag(...). For example, use content for inline JavaScript. page.addScriptTag() is a shortcut for the page’s main frame, so use the selected frame’s method when you need to target an iframe.
Inject a script into a specific frame
This example selects a frame by part of its URL, checks that it exists, and inserts inline code:
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;',
});
Replace /embedded/ and the script with conditions and code appropriate to your page. Make the selection condition specific enough to distinguish the intended frame from other frames.
A page has a frame tree. You can inspect it through page.mainFrame() and a frame’s childFrames(); a frame also exposes url() and frameElement(). Puppeteer’s Frame API documentation includes an example that gets a frame element and reads its name attribute.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
Choose how to supply the script
Frame.addScriptTag() accepts these options:
| Option | Use it for |
|---|---|
content |
JavaScript source supplied as a string. |
url |
A script hosted at a URL: await frame.addScriptTag({ url: 'https://example.test/script.js' }); |
path |
A local script file: await frame.addScriptTag({ path: './script.js' });. Relative paths resolve from Node.js process.cwd(). |
id |
An ID for the inserted script element. |
type |
The script type; set type: 'module' to load an ES2015 module. |
The call returns a promise for a handle to the inserted script element. See the official FrameAddScriptTagOptions reference for the option definitions.
Use frame evaluation when you do not need a script element
If your goal is simply to run a function in the selected frame’s JavaScript context, use Frame.evaluate() instead:
Rank #2
const title = await frame.evaluate(() => document.title);
This evaluates the function in that frame; it does not automatically run in the frame’s child frames. Use the frame where the work belongs. The Frame.evaluate() reference documents this frame-scoped execution.
Target the main frame or an iframe
await page.addScriptTag(options) is documented as a shortcut for page.mainFrame().addScriptTag(options). Use it when the script belongs in the top-level document. For an iframe, locate its corresponding Frame and call frame.addScriptTag(options). The Page.addScriptTag() reference describes the shortcut, and the Page API provides the broader page context.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Handle frame timing and lifecycle changes
Frames can attach, navigate, or detach. If the page creates an iframe dynamically, wait until the intended frame is available before selecting it. If navigation replaces or changes the frame, reacquire the frame and perform the injection in the relevant document rather than assuming an earlier selection still identifies the right target. Puppeteer’s Frame documentation covers frame lifecycle and frame selection.
Troubleshoot common problems
- The frame was not found: The selector condition may not match its current URL, or the iframe may not have attached yet. Inspect the current frame tree and select after the expected frame is available.
- The script appears in the wrong document: The call may have used
page.addScriptTag(), which targets the main frame. CalladdScriptTag()on the intended iframe’sFrame. - A local script cannot be loaded: Check that the file exists relative to Node’s current working directory, not necessarily the JavaScript file’s directory.
- The injected code is no longer present after navigation: The frame’s document changed. Locate the frame in its current state and inject into that document after navigation.
- Code runs in the selected frame but not a nested iframe: Frame evaluation and script injection are frame-scoped. Select the nested frame separately if it needs the code.
Or skip the browser setup
If your actual goal is to capture a webpage rather than execute custom JavaScript inside its iframe, ScreenshotNeo can return a screenshot with one GET request. It does not inject a script into a Puppeteer frame; use the Puppeteer methods above when that is what you need.
Rank #4
See the ScreenshotNeo documentation for request options. Example cURL request:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
For screenshot captures, ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.
Sign up for ScreenshotNeo’s free plan.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Frequently Asked Questions
Does adding a script to a frame affect its child frames?
No. Injection targets the selected frame. Select each child frame that needs the script separately.
Quick Recap
Best Value
- Used Book in Good Condition
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.

