Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a same-origin iframe, you can use html2canvas to render its DOM into a canvas and export the result as an image. This is a reconstruction, not a literal screenshot, so it may differ from the pixels the browser displays. If the iframe is cross-origin—or you need a faithful browser-rendered capture—use a real browser screenshot workflow such as Playwright instead.

Choose the capture method

Situation Use Main limitation
Same-origin iframe; approximate rendering is acceptable html2canvas in the page It rebuilds the image from readable DOM and CSS; unsupported styles may look different.
Cross-origin iframe Browser automation with access to the rendered page, or a capture/export feature supplied by the framed application The parent page cannot read the foreign frame’s document with html2canvas.
Need the browser’s rendered pixels or repeatable automation Playwright page or element screenshot Output depends on browser, viewport, page readiness, and selected region.
External images appear inside a DOM-to-canvas capture Allow CORS image loading when the image host supports it, or use a controlled proxy Images without suitable permission can taint the canvas and prevent export.

The key distinction is origin access. A parent page can inspect a same-origin frame, but browser security prevents it from reading a cross-origin frame’s document. CORS headers for an image do not remove that iframe boundary.

Capture a same-origin iframe with html2canvas

Load the library in your page, wait for the iframe to finish loading, then pass the iframe element to html2canvas. The function returns a Promise that resolves to a canvas. The following example waits for the frame load and downloads the result as a PNG:

<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<iframe id="report" src="/report.html"></iframe>
<button id="capture">Download iframe image</button>

<script>
  const iframe = document.querySelector('#report');

  function waitForLoad(frame) {
    if (frame.contentDocument?.readyState === 'complete') {
      return Promise.resolve();
    }
    return new Promise((resolve, reject) => {
      frame.addEventListener('load', resolve, { once: true });
      frame.addEventListener('error', reject, { once: true });
    });
  }

  document.querySelector('#capture').addEventListener('click', async () => {
    try {
      await waitForLoad(iframe);
      const canvas = await html2canvas(iframe);
      const link = document.createElement('a');
      link.download = 'iframe.png';
      link.href = canvas.toDataURL('image/png');
      link.click();
    } catch (error) {
      console.error('Could not capture iframe:', error);
    }
  });
</script>

Use a frame URL on the same origin as the parent, and avoid sandbox settings that remove same-origin access. If the frame is already loaded before the listener is installed, the readiness check avoids waiting forever. For applications that update iframe content after its initial load, wait for the application-specific ready condition as well; the load event alone does not guarantee that delayed content or animations have finished.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

The project describes html2canvas as building an image from information available in the DOM rather than taking an actual screenshot. As a result, CSS support and the rendered output can differ from the browser’s final appearance. See the html2canvas documentation and getting started guide.

Crop or increase the output scale

For a crop, supply x, y, width, and height in the options passed to html2canvas. For a higher-density output, the project’s examples set scale to window.devicePixelRatio. These are options to test against your layout, not a guarantee of sharper results for every browser or page. The examples show crop, scale, and PNG data-URL export patterns.

Export another supported image format

PNG is a straightforward choice for canvas.toDataURL('image/png'). Canvas export methods also support other formats where the browser supports them; for example, request JPEG with canvas.toDataURL('image/jpeg', 0.9). The second argument is a quality hint for lossy formats. Check the browser’s result and dimensions before relying on it in a production workflow.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Why cross-origin frames cannot be read this way

If the iframe’s document is hosted on a different origin, JavaScript in the parent cannot inspect its contentDocument as if it were local. html2canvas cannot bypass that browser security boundary. A cross-origin frame may therefore be inaccessible even when it is visibly rendered in the page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

There are two separate restrictions to keep straight:

  • Frame access: the parent cannot read a foreign iframe’s DOM. CORS headers on resources inside the frame do not grant that access.
  • Canvas readback: a canvas that draws foreign-origin images without permission may become tainted, preventing toDataURL or other pixel readback.

For images, html2canvas documents a useCORS option for cases where the remote image server returns suitable CORS headers. A proxy can also be used to serve resources in a controlled way, but it must be operated carefully: indiscriminate proxying can create security and operational risks. See the html2canvas FAQ and MDN’s canvas image CORS guidance.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

If you control the framed application, another option is to make it cooperate: expose a capture or export action, or use a messaging protocol such as postMessage to ask the frame to produce data it is authorized to provide. Validate message origins and define the exported content deliberately; cooperation is not a way to silently read an unrelated site’s document.

Capture rendered pixels with Playwright

For an automated capture that reflects what a browser rendered, Playwright can take a page screenshot or a screenshot of a selected element. This avoids trying to reconstruct the frame through the parent page’s DOM. A typical Node.js setup is:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npm install playwright
npx playwright install chromium

Then navigate to the page containing the iframe and capture the iframe element. This example uses a locator for the frame element itself and saves a PNG:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });

  try {
    await page.goto('https://example.com/page-with-frame', {
      waitUntil: 'networkidle',
      timeout: 30000
    });
    const frameElement = page.locator('iframe#report');
    await frameElement.waitFor({ state: 'visible' });
    await frameElement.screenshot({ path: 'iframe.png', type: 'png' });
  } finally {
    await browser.close();
  }
})();

Replace the example URL and selector with the page and iframe you are authorized to capture. The example waits for network activity to settle, but pages with persistent requests may not reach that state; in that case, wait for a meaningful selector or application-specific readiness signal instead. Playwright’s screenshot API also supports page screenshots, full-page capture, and image format and scale options. Consult the Playwright page screenshot API for the current option details.

A screenshot of the iframe element captures its visible rectangle. If you need content that extends beyond that viewport, consider a full-page capture of the page or adjust the frame/page layout before capture; the correct choice depends on whether you want the visible frame or the entire embedded document. Playwright’s browser screenshot behavior is also the route to choose when visual fidelity matters more than client-side DOM reconstruction. The html2canvas FAQ likewise points to browser screenshot approaches such as Puppeteer or Playwright for server-side screenshots.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot API rather than maintaining a browser capture workflow, ScreenshotNeo accepts a URL and returns an image or PDF. It captures rendered pages through its screenshot service; use it for a publicly accessible page URL, not as a means to bypass authorization or browser access controls on private iframe content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/page-with-frame -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners, newsletter popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents use screenshot tools, and the Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card required.

Troubleshoot common capture failures

The html2canvas result is blank or incomplete

  • Check whether the iframe is same-origin. If reading iframe.contentDocument throws a security error or returns inaccessible content, the parent cannot use this method on that frame.
  • Wait for actual content readiness. The iframe load event can precede data fetched by the framed app or later rendering. Wait for a visible, app-specific element before capturing.
  • Check unsupported CSS. Since html2canvas reconstructs from DOM and styles, unsupported or complex rendering may not match the browser. Use Playwright when the displayed pixels are the requirement.
  • Check canvas size. Very large canvases can render partially or blank, and browser/platform limits vary. Reduce the capture area or scale and test on the target browsers; the FAQ does not establish a universal safe maximum.

Export throws a security error

A SecurityError from toDataURL commonly indicates a tainted canvas, often due to an external image that was drawn without suitable CORS permission. Configure image loading with useCORS only if the image server allows it, remove or replace that resource, or use a controlled proxy. This is distinct from cross-origin iframe document access.

The frame is visible but inaccessible

Visual visibility does not imply DOM permission. Confirm the frame’s origin and sandbox attributes. A sandboxed iframe without allow-same-origin is inaccessible for same-origin DOM reading, even when its URL would otherwise match. If the content is cross-origin, use browser automation or an explicit cooperative export route.

The screenshot captures the wrong area or timing

For Playwright, verify the selector identifies the iframe you intend, confirm it is visible, and wait for application readiness rather than assuming network idle is always attainable. For html2canvas, check the crop coordinates and dimensions and capture only after the page has settled. Fix the viewport and device scale when repeatability matters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Practical reliability and performance checks

  • Test the target browser and device. CSS support, canvas limits, and device pixel ratio vary. Validate the result where it will be used.
  • Keep output dimensions reasonable. Full-page, high-scale captures consume more memory; large canvases may be clipped or blank.
  • Make readiness explicit. Wait for the frame and the content your user needs, not just a timer that may be too short or unnecessarily long.
  • Choose fidelity deliberately. html2canvas is useful when you can read the DOM and can accept reconstruction. Browser screenshots are better aligned with rendered-pixel capture.
  • Handle access and resources separately. Same-origin policy governs frame DOM access; image CORS governs whether canvas pixels can be exported.

Frequently Asked Questions

Can I capture a cross-origin iframe with html2canvas?

No. The parent page cannot inspect a cross-origin iframe’s document through html2canvas. Use an authorized browser screenshot workflow or an export mechanism provided by the framed application.

Does adding CORS headers to an image let the parent read a cross-origin iframe?

No. CORS permission for loading an image and access to a foreign iframe’s document are separate browser security rules.

Will html2canvas look exactly like a screenshot?

Not necessarily. It reconstructs an image from DOM and CSS information rather than capturing the browser’s actual pixels.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.