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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

If you need an image of a page from JavaScript running in that page, use html2canvas to render a DOM element into a canvas, then export it as PNG. That gives you a DOM-based reconstruction, not a literal capture of the browser’s pixels. For an automated screenshot of actual browser rendering, use Playwright or Puppeteer; for a screen-sharing or recording flow, use getDisplayMedia(), which requires the user to choose what to share.

Choose the right kind of screenshot

“Screenshot the current page” can mean different things. Decide whether you need a client-side image, an automated browser capture, a user-selected screen stream, or an extension capture before choosing an API.

Need Suitable approach Important distinction
Render a page or element from code running on the page html2canvas Rebuilds an image from DOM and style information; fidelity can differ from the browser’s rendered pixels.
Capture a rendered page in an automated workflow Playwright or Puppeteer Runs in a browser automation context; Playwright documents viewport and full-page screenshots.
Let a person choose a screen, window, or tab to share or record getDisplayMedia() Prompts the user and returns a media stream rather than a one-time image.
Capture from a browser extension The target browser’s extension screenshot API Check that browser’s current API, permissions, and restrictions.

Capture the current page with html2canvas

html2canvas takes a target element, traverses its DOM and style information, and resolves a Promise with a canvas. The project cautions that the result “does not make an actual screenshot,” but builds one from information available on the page. That makes it useful for in-page exports, but it should not be treated as a pixel-perfect substitute for a real browser screenshot.

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

Install and load the library

Use the project’s Getting Started instructions to add html2canvas to your application. The code below assumes the library has been loaded and runs in a browser page where document and window are available. It does not run by itself in Node.js.

#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Save the page as a PNG

html2canvas(document.body)
  .then((canvas) => {
    const link = document.createElement('a');
    link.download = 'screenshot.png';
    link.href = canvas.toDataURL('image/png');
    link.click();
  })
  .catch((error) => {
    console.error('Could not create the screenshot:', error);
  });

The key sequence is: pass the element to capture, wait for the Promise, convert the resulting canvas to a data URL, then click a temporary download link. The download may be blocked or behave differently in some contexts; run the action in response to a user interaction when your browser requires it.

Capture one element instead of the page

Pass a specific element when the user only needs a component, card, chart, or other region. Check that the selector exists before calling the library:

const target = document.querySelector('#capture');

if (!target) {
  throw new Error('Capture target #capture was not found');
}

const canvas = await html2canvas(target);
const link = document.createElement('a');
link.download = 'capture.png';
link.href = canvas.toDataURL('image/png');
link.click();

This example uses await, so place it inside an async function or an ES module that supports top-level await. Choose the target deliberately: capturing document.body does not guarantee a complete full-page image for every layout. Measure and validate the dimensions and content you actually need.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Export and error handling

For PNG, canvas.toDataURL('image/png') gives the browser a PNG data URL. If you need another output format, confirm that it is supported by the browser and that the canvas remains readable. A canvas containing restricted cross-origin content can be tainted, preventing export. Catch rejected Promises and handle export errors rather than assuming every page can be serialized.

When to use Playwright or Puppeteer instead

If the requirement is “capture what the browser rendered,” especially in a test, documentation pipeline, or server-side job, use browser automation rather than DOM reconstruction. Playwright’s Page API documents screenshot options including fullPage for the full scrollable page. Its screenshot documentation also describes options such as masking elements and omitting the background. Puppeteer is a JavaScript browser-automation library that also supports screenshots and PDF generation, as described by Chrome for Developers.

Playwright: full-page capture

In a Playwright script, once you have navigated to a page and obtained its Page object, use:

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
await page.screenshot({ path: 'page.png', fullPage: true });

Omit fullPage: true when you only want the current viewport. Use the options in the Page API for additional capture behavior, such as masking chosen elements. A browser automation screenshot is the better fit when the result must reflect the browser’s actual rendering, but it requires an automation context rather than a small snippet running in the visitor’s page.

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

When getDisplayMedia is the right tool

navigator.mediaDevices.getDisplayMedia() is for consent-based sharing or recording, not a silent screenshot shortcut. It prompts the user to select a display surface such as a screen or window and returns a media stream. Chrome’s documentation on privacy-preserving screen-sharing controls covers controls including excluding the current tab and configuring audio capture. Use this path when the product needs a continuing shared or recorded stream; use an image-capture method for a saved page image.

Cross-origin content, frames, and fidelity limits

Images and other cross-origin resources

Browser security policy still applies when html2canvas draws page content. Resources from another origin may taint the canvas, making it unreadable for export; the library cannot bypass those content policies. A proxy can sometimes make resources available in a permitted way, but use only a proxy you control or trust, and consider the privacy and security implications of sending page assets through it.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Iframes

Same-origin frames can be rendered recursively, but JavaScript cannot freely inspect cross-origin frames. If important content is inside an inaccessible cross-origin iframe, html2canvas may not be able to include it. Do not promise a complete capture where the browser’s same-origin security restrictions prevent access.

CSS and exact visual matching

Because html2canvas reconstructs the image rather than reading browser pixels, unsupported or incompletely implemented CSS, fonts, images, and other rendering details can change the result. Inspect the output in the browsers and layouts that matter to your application. If visual fidelity to a particular browser render is a hard requirement, capture through Playwright or Puppeteer instead.

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

Viewport versus full page

A viewport is the visible browser area; a full-page capture extends through the scrollable document. These are separate requirements. Playwright explicitly offers fullPage: true. With html2canvas, selecting document.body is not a universal guarantee that the output covers the entire intended page; determine the required bounds and check the resulting canvas.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

  • The library is undefined: html2canvas has not been loaded, or the code ran before the script or module was available. Follow the project’s setup instructions and invoke capture only after loading.
  • The selector is null: the element does not exist at capture time, the selector is wrong, or the component has not rendered yet. Verify the selector and wait until the target is present.
  • The image is missing a remote picture: the resource may be cross-origin or blocked from canvas use. Check the image’s origin and access configuration; browser policies cannot be bypassed by html2canvas.
  • PNG export fails: the canvas may be tainted by inaccessible cross-origin content. Remove or make those resources safely available, then try export again.
  • An iframe’s contents are absent: a cross-origin frame cannot be inspected as though it belonged to the current page. Capture it through an authorized approach in its own context, or accept that it cannot be included from the parent page.
  • The result differs from the visible page: that can be an html2canvas fidelity limitation. Check unsupported CSS, fonts, resource loading, and layout; use real-browser automation if an actual rendered capture is needed.
  • The page is cut off: the chosen target or rendered bounds may cover only part of the document. Confirm whether you need viewport or full-page output and validate the canvas dimensions; for full scrollable capture, Playwright provides fullPage: true.
  • It fails in Node.js: page-context code depends on browser APIs such as window and document. Launch a real browser with an automation framework for server-side capture.

Performance, reliability, and cost considerations

There is no single safe image-size limit to quote here: canvas limits vary by browser and can change. Large pages also require more rendering and memory than a small element. Prefer capturing only the needed region when that satisfies the task, and test long or image-heavy pages in the browsers your users run. For automated work, account for browser startup, navigation, and page loading in the workflow rather than treating screenshot capture as a synchronous utility call.

Reliability depends on the page being ready and its resources being accessible. For client-side captures, wait until the target and required content have rendered, catch Promise errors, and inspect the exported result. For automation, use the framework’s navigation and screenshot APIs in a controlled browser context. Neither approach removes browser security boundaries around inaccessible resources.

Or skip the browser setup

If you need an API call rather than a library running inside the current page, ScreenshotNeo returns a website screenshot or PDF from one GET request. Its response identifies page verdict and billing status in headers: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing. It can remove cookie and consent banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. It also provides an MCP server with screenshot tools for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

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.
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 API documentation for request options and response details. Sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Can JavaScript take a screenshot without asking the user?

Code running in a page can use DOM reconstruction such as html2canvas, subject to its rendering and browser-security limits. Capturing a user’s screen or tab through getDisplayMedia is different: the user chooses a surface.

Can html2canvas capture a cross-origin iframe?

Not by freely reading its contents from the parent page. Cross-origin frame access is restricted by browser security policy, so its contents may be missing from the result.

Does html2canvas capture the whole page automatically?

Not reliably for every layout. Select and validate the intended bounds; Playwright offers an explicit fullPage option for full scrollable-page capture.

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.

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.