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.

Use Playwright’s locator screenshot method to capture the canvas as it appears in the page: await page.locator('canvas').screenshot({ path: 'canvas.png' });. Specify a path to save an image, or omit it to receive the screenshot as a buffer. Make sure your application has finished drawing before capture; Playwright cannot infer an arbitrary canvas’s application-specific ready state.

Capture a canvas to an image file

In a Playwright test using JavaScript or TypeScript, locate the intended canvas and call screenshot(). Replace the generic selector if the page contains more than one canvas.

import { test } from '@playwright/test';

test('capture canvas', async ({ page }) => {
  await page.goto('https://example.com/app');

  const canvas = page.locator('canvas');
  await canvas.screenshot({ path: 'artifacts/canvas.png' });
});

The locator screenshot API has been available since Playwright v1.14. It waits for actionability checks and scrolls the element into view before taking the screenshot. See the Playwright screenshots guide and Locator API reference for the current API details.

Wait until the canvas has finished drawing

Playwright’s element screenshot behavior does not provide a universal signal that an application has completed drawing arbitrary canvas content. Synchronize on a condition specific to your app before calling screenshot(), such as a known ready-state element or an application event indicating rendering is complete.

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.

For example, if your app exposes a visible ready marker, wait for it before capture:

await page.goto('https://example.com/app');
await page.getByTestId('canvas-ready').waitFor();
await page.locator('#chart-canvas').screenshot({ path: 'artifacts/chart.png' });

canvas-ready is an example application-specific marker, not a Playwright-provided selector. Use a readiness condition your application actually guarantees; a fixed delay may be unreliable if rendering time varies.

Return image bytes instead of saving a file

Omit path when you want to pass the screenshot directly to image-processing or visual-diff code. In Node.js, the returned value is a Buffer.

const imageBuffer = await page.locator('#chart-canvas').screenshot();
// Pass imageBuffer to an image-processing or visual-diff step.

In Python, the corresponding locator call can save to a path or return image bytes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
canvas = page.locator("#chart-canvas")
canvas_bytes = canvas.screenshot()
# Or save directly:
# canvas.screenshot(path="artifacts/chart.png")

Playwright’s Python screenshots guide documents element screenshots through page.locator(...).screenshot().

Choose the image format and scale

PNG is the documented default. Playwright also supports JPEG and WebP; JPEG quality can be configured. Choose the format according to what will consume the artifact, such as a test diff or a smaller image file.

The scale option controls output dimensions:

  • CSS scale: produces one image pixel per CSS pixel, which is useful for compact captures sized to the page layout.
  • Device scale: follows the device pixel ratio and can produce a larger, higher-density image.

Neither scale is universally best. Choose based on whether your downstream use needs layout-sized output or device-resolution detail. The Locator API reference documents screenshot options including format, quality, scale, animation handling, masks, background handling, screenshot styles, and timeouts: locator.screenshot().

Understand what the screenshot includes

locator.screenshot() captures the rendered page region corresponding to the matched element’s bounds. It is a screenshot of the page presentation, not simply an export of the canvas’s underlying bitmap.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • If another element covers part of the canvas, that covered page content can appear in the capture.
  • For a scrollable element, the screenshot reflects the content currently scrolled into view.
  • CSS clipping, overlays, and other composited page content can affect what is visible in the captured region.

Browser-side canvas export methods such as toDataURL() are a different capture path: they export the canvas bitmap rather than screenshotting the rendered page region. Use the locator screenshot method when you need the page-rendered element view.

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

Troubleshoot common capture problems

Symptom Likely cause What to do
The image is blank or shows an incomplete drawing. The screenshot ran before the app finished rendering. Wait for an application-specific ready condition or completed-render event before taking the screenshot.
The wrong canvas was captured. The generic canvas selector matched an unintended element. Use a selector that identifies the specific canvas, such as an application ID or a locator scoped to its container.
The screenshot includes unexpected content over the canvas. Another page element overlaps the canvas, and the screenshot reflects the rendered region. Check the page layout and overlays at capture time. If you need the canvas bitmap without page composition, use a canvas export approach instead, recognizing that it is not the same as a page screenshot.
The captured content differs from the expected scrolled view. The element is scrollable or the page position changed before capture. Set up the intended scroll state before capture and confirm which portion is visible.
The image dimensions are unexpectedly large or small. The selected screenshot scale does not match the intended pixel dimensions. Choose CSS scale for one output pixel per CSS pixel or device scale to follow the device pixel ratio.
A screenshot option is rejected or behaves differently. The installed Playwright version may differ from the current living API documentation. Check the Locator API reference against the version installed in your project and use options supported by that version.

Or skip the browser setup

For a hosted one-request capture, ScreenshotNeo accepts a URL and returns a screenshot or PDF. Its API can capture an element by CSS selector; clean-shot handling accepts cookie and consent banners and removes supported consent platforms, newsletter popups, and chat widgets before capture. Bot checks, blank pages, and failed loads are not billed, and responses identify the page verdict and billing status. ScreenshotNeo also provides an MCP server with screenshot tools for AI agents.

Example cURL request (replace the URL with the page you want to capture):

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 authentication and request options. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for free.

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

Frequently Asked Questions

Can I capture a canvas by its CSS selector?

Yes. Use a locator for the selector, such as page.locator('#chart-canvas').screenshot().

Does locator.screenshot() return bytes if I omit the path?

Yes. In Node.js, it returns a Buffer; in Python, it returns screenshot bytes.

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.