Glossary Term

Playwright

Playwright is an open-source automation framework by Microsoft that controls Chromium, Firefox, and WebKit browsers — used for testing, screenshots, and web automation across all major browser engines.

What Playwright can do

Playwright provides a unified API for automating browsers across all three major rendering engines: Chromium (powering Chrome and Edge), Firefox (Gecko), and WebKit (powering Safari). This cross-browser support is its defining feature — a single script can run against all three engines without modification.

Key capabilities include:

  • Cross-browser automation — write once, run against Chrome, Firefox, and Safari. Browser binaries are downloaded and managed automatically.
  • Screenshot capture — save pages as PNG or JPEG, capture the full page or a specific element, and set viewport dimensions and device emulation.
  • PDF generation — export rendered pages to PDF with full control over page size, margins, and scale.
  • Network interception — monitor, mock, or modify network requests for testing and data capture.
  • Browser contexts — create isolated browser sessions (like incognito windows) that share no cookies, storage, or state. Useful for capturing pages as different user types without restarting the browser.
  • Multi-language support — official bindings for JavaScript/TypeScript, Python, Java, and .NET.

Playwright's auto-waiting mechanism is particularly valuable. Unlike libraries that require explicit wait calls, Playwright automatically waits for elements to be attached to the DOM, visible, and stable before interacting with them. This makes scripts more reliable and reduces the "flaky test" problem.

Playwright for screenshots

Playwright's page.screenshot() method offers precise control over capture output. You can capture the visible viewport, the full scrollable page, or a specific DOM element by passing a locator.

Device emulation lets you simulate specific devices — setting viewport dimensions, device scale factor, and user agent in a single call. Playwright includes a built-in device registry with presets for popular phones and tablets, making it straightforward to capture how a page looks on an iPhone, Pixel, or iPad.

For pages with lazy-loaded content, Playwright's auto-scrolling behavior and wait conditions help ensure all images and dynamic content are loaded before capture. You can inject CSS to hide cookie banners, remove chat widgets, or adjust styling before taking the screenshot.

Because Playwright supports WebKit, it can produce screenshots that match Safari's rendering — something Puppeteer cannot do natively. This is critical for visual testing and design review workflows where cross-browser consistency matters.

For a Shotomatic-adjacent workflow, Playwright becomes valuable when the same page needs to be captured repeatedly across browsers, routes, or authentication states. It turns screenshot production into an explicit recipe instead of a manual browser session, which is why it shows up so often in monitoring and QA pipelines.

Playwright vs Puppeteer

Both libraries are excellent for headless browser automation, but they differ in scope and philosophy.

Browser coverage — Playwright supports Chromium, Firefox, and WebKit. Puppeteer supports Chrome and Chromium primarily, with experimental Firefox support. If you need Safari-accurate rendering, Playwright is the clear choice.

Auto-waiting — Playwright waits for elements to be ready before interacting. Puppeteer requires more explicit wait calls (waitForSelector, waitForNetworkIdle), which means more code and more potential for timing issues.

Browser contexts — Playwright's browser contexts allow multiple isolated sessions within a single browser instance, reducing resource usage. Puppeteer uses incognito browser contexts but the API is less developed.

API maturity — Puppeteer has been available since 2017 and has a larger ecosystem of community resources. Playwright launched in 2020 and has been growing rapidly, with more frequent releases and a broader feature set.

For screenshot-focused workflows, the choice often comes down to browser requirements. Chrome-only capture works well with either tool. Cross-browser capture — especially Safari — requires Playwright.

Common mistakes

  • Not installing browser binaries. After installing the Playwright package, you must run the install command to download browser binaries. Without this step, scripts will fail with a "browser not found" error.
  • Ignoring auto-wait limits. While auto-waiting reduces flakiness, it has a default timeout. If a page is slow to load, actions may time out before content is ready. Adjust timeout values for content-heavy pages.
  • Capturing before lazy content loads. Even with auto-waiting, Playwright does not automatically scroll through the page. For full-page screenshots of lazy-loaded pages, add a scroll step before capture.
  • Using the wrong browser for the use case. Running all captures against Chromium is faster but misses rendering differences in Firefox and WebKit. Use cross-browser capture when the visual output must match what users see in different browsers.
  • Not closing browser contexts. Failing to close browser contexts after capture leads to memory leaks in long-running scripts. Always close contexts and browser instances when finished.

Common Questions

Is Playwright free?

Yes. Playwright is open source under the Apache 2.0 license, maintained by Microsoft. It can be installed via npm, pip, or NuGet at no cost.

Which browsers does Playwright support?

Playwright supports Chromium (Chrome, Edge), Firefox, and WebKit (Safari) out of the box. It downloads and manages browser binaries automatically, so there is no separate installation step.

Can Playwright capture screenshots in Safari?

Playwright controls WebKit — the rendering engine behind Safari — on all platforms including Linux and Windows. This allows you to capture screenshots that match Safari's rendering without needing a Mac or iOS device.

What programming languages does Playwright support?

Playwright has official libraries for JavaScript/TypeScript (Node.js), Python, Java, and .NET. The JavaScript version is the most widely used and typically receives new features first.

How does Playwright handle dynamic content?

Playwright includes built-in auto-waiting — it automatically waits for elements to be visible, stable, and actionable before interacting with them. This reduces flaky scripts and makes it easier to capture pages with animations or lazy-loaded content.

Sources

Related Resources