Illustration of what playwright does: One API to test and automate Chromium, Firefox and WebKit, for scripts and agents

microsoft /

playwright

One API to test and automate Chromium, Firefox and WebKit, for scripts and agents

Playwright controls real web browsers from code. You write steps like open a page, click a link, check a heading, and Playwright runs them in Chromium, Firefox or WebKit with the same API. It works on Linux, macOS and Windows, headless or with a visible window.

It comes in several forms. Playwright Test is a test runner with auto-waiting, retrying assertions and a fresh browser context for every test. The library is for plain scripts such as screenshots, PDFs and scraping. A CLI and an MCP server let coding agents and LLM clients drive a browser.

For agents, the README says the CLI is more token-efficient than MCP because it avoids loading large tool schemas and accessibility trees into the model context. The MCP server instead gives agents a structured accessibility snapshot of the page, so no vision model or screenshots are needed. Playwright is also available for Python, .NET and Java.

What it does

  • Cross-browser, one API

    Runs Chromium, Firefox and WebKit on Linux, macOS and Windows, headless or headed.

  • Auto-wait and web-first assertions

    Playwright waits for elements to be actionable, and assertions retry until they pass, so tests need no artificial timeouts.

  • Isolated tests and Trace Viewer

    Each test gets a fresh browser context, and you can save login state to reuse. Traces capture actions, DOM snapshots, network requests and console messages for debugging.

  • CLI and MCP server for agents

    The CLI targets coding agents like Claude Code and Copilot. The MCP server lets clients such as VS Code, Cursor and Claude Desktop use a browser through accessibility snapshots.

  • VS Code extension

    Run and debug tests from the editor, record tests with CodeGen, and pick locators by hovering over elements.

What you could build

  • Write end-to-end tests for a web app and run them in parallel across three browsers.
  • Capture screenshots or generate PDFs of web pages with a short script.
  • Emulate a mobile device such as an iPhone 15 to check how a page looks.
  • Let a coding agent test a web flow and take screenshots using the CLI.
  • Connect an MCP client so an AI assistant can fill forms and navigate sites.

Get started

For testing, run the init command to set up a project with example tests, then run them. For AI agents, add the MCP server to your client's config or install the CLI as the README describes.

npm init playwright@latest
npx playwright test
npx @playwright/mcp@latest

Commands are copied from the project's README. Read it on GitHub for the full setup.

More in Browser & computer use

    ↑↓ to move, Enter to open, Esc to close