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

With html2canvas, the simplest way to leave an iframe out of a capture is to mark it with data-html2canvas-ignore. If you cannot edit the markup, pass an ignoreElements predicate; if the rule should affect only the temporary rendering copy, remove the iframe in onclone. These are html2canvas features, not universal options for every JavaScript screenshot library.

The three html2canvas mechanisms

All three approaches are documented in the html2canvas options reference. Choose according to which elements you control and how broadly the rule should apply.

Method Best for Scope What changes
data-html2canvas-ignore A known iframe in your markup Only marked elements The element is skipped during rendering
ignoreElements A reusable runtime rule Every element that matches your predicate The matching element is filtered from the render
onclone Clone-only DOM changes Anything you remove or alter in the cloned document The original page remains unchanged

The element passed to html2canvas() must contain the iframe. Capturing a different node cannot be affected by a rule aimed at a frame outside that node.

Option 1: mark one iframe with data-html2canvas-ignore

Use the attribute when you own the HTML and want to exclude a specific frame. The attribute is boolean, so it does not need a value.

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.
<section id="capture">
  <h1>Report</h1>
  <iframe
    src="https://embed.example/"
    title="External dashboard"
    data-html2canvas-ignore>
  </iframe>
  <p>This text remains in the canvas.</p>
</section>

<script>
  async function captureReport() {
    const canvas = await html2canvas(document.querySelector('#capture'));
    const image = canvas.toDataURL('image/png');
    document.querySelector('#preview').src = image;
  }
</script>
<img id="preview" alt="Screenshot preview">

When html2canvas walks the target, it recognizes the attribute and omits that iframe. Other elements in #capture are rendered normally. The official examples show this same pattern at html2canvas examples.

Keep the rule narrow

If only one frame should disappear, put the attribute on that frame rather than applying a global predicate. You can still leave a visual placeholder in the layout, such as a fixed-height div, when removing the frame would otherwise make surrounding content move.

Option 2: use ignoreElements when markup is not yours

ignoreElements receives each element considered for rendering. Return true for an element that must be skipped.

async function captureWithoutIframes() {
  const target = document.querySelector('#capture');

  const canvas = await html2canvas(target, {
    ignoreElements: (element) => element.tagName === 'IFRAME'
  });

  return canvas;
}

This predicate excludes every iframe inside the target. A narrower rule can preserve selected frames by checking an identifier, class, or attribute:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const canvas = await html2canvas(document.querySelector('#capture'), {
  ignoreElements: (element) =>
    element.tagName === 'IFRAME' &&
    !element.matches('[data-keep-in-screenshot]')
});

Use an element test rather than inspecting contentDocument; the latter is unavailable for many cross-origin frames.

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.

Option 3: remove frames in onclone

onclone runs after html2canvas has created the document clone used for rendering. Removing nodes there changes only that temporary copy, so application state and the visible page are not modified.

const canvas = await html2canvas(document.querySelector('#capture'), {
  onclone: (clonedDocument) => {
    clonedDocument.querySelectorAll('iframe').forEach((iframe) => {
      iframe.remove();
    });
  }
});

This is useful when the exclusion policy is capture-specific or when code elsewhere depends on the iframe remaining mounted. You can combine the callback with a selector to remove only particular frames:

onclone: (clonedDocument) => {
  clonedDocument
    .querySelectorAll('iframe.analytics, iframe[data-private]')
    .forEach((iframe) => iframe.remove());
}

Prefer ignoreElements for a simple filter and onclone when you need several clone-only changes, such as replacing a live widget with a static placeholder.

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.

Complete capture patterns

Capture after the page has settled

Call html2canvas after your application has inserted the target and after any layout changes that must appear in the image. For a frame created asynchronously, wait for your own application signal before calling the function; an iframe that is added later cannot be ignored by a capture that already finished.

async function capture() {
  const target = document.getElementById('capture');
  if (!target) throw new Error('Capture target was not found');

  await new Promise((resolve) => requestAnimationFrame(resolve));

  return html2canvas(target, {
    ignoreElements: (element) => element.tagName === 'IFRAME'
  });
}

capture().then((canvas) => {
  const link = document.createElement('a');
  link.download = 'report.png';
  link.href = canvas.toDataURL('image/png');
  link.click();
});

Preserve a reserved area

Ignoring an iframe does not guarantee that the space it occupied will be visually filled. CSS layout still determines the dimensions of the target. If the empty area is intentional, wrap the frame in a container with an explicit height and style a placeholder inside it:

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.
<div class="embed-slot">
  <div class="embed-placeholder" aria-hidden="true"></div>
  <iframe src="https://embed.example/" data-html2canvas-ignore></iframe>
</div>

Whether the placeholder or the container appears depends on which node you ignore. If you ignore only the iframe, the wrapper and its placeholder remain available to html2canvas.

Same-origin and cross-origin iframe limits

html2canvas reconstructs an image from DOM information; it does not capture the browser’s final pixels like an operating-system screenshot. Its documentation states that same-origin iframe content can be supported recursively, while cross-origin frames and sandboxed frames without allow-same-origin cannot be read through contentDocument. See the html2canvas documentation for those rendering limits.

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

For exclusion, this distinction is usually an advantage: html2canvas can skip the iframe element without opening or examining its document. Do not attempt to work around the browser’s same-origin policy merely to hide a frame. If you need pixels from a cross-origin frame instead of omitting it, you need cooperation from the framed origin and a design that satisfies the browser’s security rules; the ignore APIs do not grant access.

Choosing the right rule

  • You control the HTML and know the exact frame: add data-html2canvas-ignore.
  • You need a reusable “ignore all iframes” policy: use ignoreElements with element.tagName === 'IFRAME'.
  • You need capture-only DOM edits: use onclone and remove or replace nodes in the clone.
  • Some frames must remain: narrow the predicate or selector instead of filtering every iframe.

Troubleshooting

The iframe still appears

  • Confirm that the iframe is inside the element passed to html2canvas().
  • Check the spelling: the attribute is exactly data-html2canvas-ignore.
  • Make sure the predicate returns true for the actual element. tagName is normally uppercase, so compare with 'IFRAME'.
  • If you use onclone, query clonedDocument, not the live document.
  • Ensure the capture is not occurring before a framework has mounted the iframe.

The page looks different after exclusion

Removing the frame can change layout when its parent sizes itself from the frame’s content. Give the parent an explicit size or leave a placeholder element. This keeps the screenshot’s geometry predictable without rendering the embedded content.

A cross-origin error is reported

An exclusion rule should not need to read the iframe document. Remove code that accesses iframe.contentDocument or frame-internal elements. Filter the iframe element itself with the attribute, predicate, or clone callback.

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

The result is blank or incomplete

Verify that the target is visible, has dimensions, and is selected after its content has rendered. html2canvas is DOM-based, so browser pixels produced by plugins, protected canvases, or content it cannot read may not match what you see interactively. Test with a simple local element first, then add the iframe and exclusion rule.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

A dynamically inserted frame is not excluded

The attribute or predicate must be present when the capture runs. Attach the attribute when creating the iframe, or wait for the insertion before calling html2canvas. A clone callback can remove frames that exist at clone time, but it cannot remove a frame added after cloning.

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

Performance, reliability, and security considerations

Ignoring a large embedded document can reduce the amount of DOM that html2canvas needs to process, but the total capture cost still depends on the rest of the target: images, fonts, layout complexity, and canvas size. Capture the smallest practical container, avoid unnecessarily large dimensions, and wait for required resources before rendering.

For repeatable output, make the exclusion rule deterministic and keep a stable placeholder size. If the page contains several unrelated third-party frames, a global predicate is easier to maintain than a list of changing selectors. Conversely, a global rule can hide a frame that a future feature expects in the image, so document the policy and add a test fixture for the intended result.

Skipping an iframe is not the same as blocking its network activity. The browser may still load the frame while the page is displayed. If privacy or bandwidth requires preventing that request, use an application-level loading strategy (for example, defer assigning src) rather than relying on a screenshot ignore rule.

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.

Do not confuse html2canvas with browser screenshot APIs

The attribute, ignoreElements, and onclone options belong to html2canvas. Playwright, Puppeteer, Selenium, browser extensions, and hosted screenshot APIs have different controls. In those tools, hiding an iframe generally means changing page CSS or DOM before capture, or using the tool’s own masking and clipping features. Copying an html2canvas option into another package will not make it work.

Or skip the browser setup

If you need a server-side image or PDF rather than a canvas built in the page, ScreenshotNeo accepts one GET request and returns a PNG, JPEG, WebP, or PDF. It can capture a URL without you wiring up a browser, and its options include CSS-selector element capture, custom CSS, JavaScript, click actions, wait conditions, resource blocking, device and viewport settings, and PDF controls.

For an entire page, including a frame you do not want, pass CSS in custom_css (or use the service’s hide-selector option) to set that iframe to display:none before capture. The exact API parameter names used by other screenshot APIs also work, which can simplify migration.

cURL

curl -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 documentation for authentication, output and option names.

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

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const buffer = Buffer.from(await res.arrayBuffer());
require('fs').writeFileSync('shot.webp', buffer);

ScreenshotNeo removes cookie-consent banners, newsletter popups, and chat widgets before the shot when those cleanup steps are enabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and whether the request was billed. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

The Free plan includes 1,000 shots each month without a card. Paid plans are Starter $5 for 3,000 shots, Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000; yearly billing provides two months free, and every feature is included on every plan. Create a free ScreenshotNeo account to start with the 1,000-shot allowance.

Frequently Asked Questions

Does ignoring an iframe stop its requests?

No. The rule controls html2canvas rendering; the browser can still load the iframe while the page is open. Prevent loading separately if that is required.

Can I exclude an iframe only for one capture?

Yes. Use onclone to remove it from html2canvas’s temporary cloned document, leaving the live page untouched.

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

What if the iframe is added after capture starts?

The exclusion rule applies only to elements present when html2canvas examines the target. Wait for the frame to be inserted, or trigger a new capture after insertion.

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.