Playwright or Browser Agents? Where Scripted Automation Still Wins
Playwright scripts vs MCP-driven browser agents: brittleness, determinism and cost, one invoice task done both ways, the security risks and when each wins.
This article is published in English.
Sources: Playwright vs WebMCP: Will Browser Automation Survive the Agent Era?
The web was designed for people clicking links and reading pages. Selenium, Puppeteer and Playwright then let code do the clicking. For more than ten years, browser automation meant writing a script, spelling out every step and running it again and again. AI agents are now changing that. They can reason, plan and act, and they browse a page the way a person does: look at it, make sense of it, decide what comes next. That sets up a pointed question. Does the Model Context Protocol (MCP) make scripted automation obsolete, or does Playwright still earn its place?
Why developers like Playwright
Playwright, from Microsoft, is a modern browser automation framework. Code written against it drives Chromium, Firefox or WebKit to click buttons, fill forms, scrape data and run end-to-end tests. A small sample:
const { chromium } = require('playwright');
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com/login');
await page.fill('#email', 'user@example.com');
await page.fill('#password', 'secret');
await page.click('button[type="submit"]');
await page.waitForURL('**/dashboard');
console.log('Logged in!');
await browser.close();
The result is clean, deterministic and predictable. The usual reasons for its popularity:
- Cross-browser support comes built in.
- Test isolation and parallel runs are very solid.
- Auto-waiting removes the old
sleep(2000)hacks. - Tracing, screenshots and video recording are included.
- It slots neatly into CI/CD pipelines.
For QA automation, regression testing and scripted web workflows, it is the benchmark.
Where scripts hurt
The weakness is brittleness. Rename a button's CSS class and the script fails. Move a form field and it fails. Roll out an A/B variant with a new layout and it fails again. Each script is a hardcoded map of assumptions about how a page looked at one moment, and UIs never stop changing. Keeping a large Playwright suite alive at a fast-moving company can become a second full-time job.
An analogy helps. A script is a laminated card of directions through a city. It works until a road closes, a building moves or a one-way street appears. A better navigator would look around, read street signs and work it out live.
What MCP adds
MCP, introduced by Anthropic in late 2024, is an open standard for connecting AI models such as Claude to outside tools, data sources and environments in a structured way. It works like a universal plugin system for agents. Instead of living inside a chat window, a model can reach databases, APIs, file systems and web browsers.
A Playwright MCP server now exists, exposing browser actions as functions that an agent can call. Where a developer would write a line like this:
await page.click('#submit-button');
an agent receives a goal instead:
"Submit the contact form on acme.com with the user's name and email"
From there it navigates, locates elements and interacts with the page using vision, HTML parsing and reasoning, with no hardcoded selector anywhere.
Head-to-head comparison
Playwright, the traditional approach
- Control: the developer writes every step.
- Selectors: CSS, XPath or text.
- Resilience to UI change: breaks when the UI changes.
- Setup: moderate, since code is required.
- Determinism: fully deterministic.
- Debugging: easy, with trace logs and screenshots.
- Speed: fast.
- Cost: compute only.
- Best for: regression tests and CI/CD pipelines.
- Reliability: high when maintained.
WebMCP or Playwright MCP, the agent approach
- Control: an AI agent reasons and decides.
- Selectors: natural language plus visual understanding.
- Resilience to UI change: adapts by re-reasoning from the current DOM.
- Setup: low, because describing the goal is enough.
- Determinism: non-deterministic, as LLM reasoning is involved.
- Debugging: harder, since the question becomes why the agent chose that action.
- Speed: slower from LLM inference overhead.
- Cost: compute plus LLM API tokens.
- Best for: dynamic tasks, complex workflows and agents.
- Reliability: improving, but short of production grade.
One task, two methods
The task: sign in to a SaaS dashboard, find the latest invoice and download it as a PDF.
With Playwright, the script navigates to the login page, fills the email and password through data-testid selectors, clicks the login button and continues step by step.
await page.goto('https://app.saas.com/login');
await page.fill('[data-testid="email"]', credentials.email);
await page.fill('[data-testid="password"]', credentials.password);
await page.click('[data-testid="login-btn"]');
await page.waitForSelector('.dashboard');
await page.click('nav >> text=Billing');
await page.click('.invoice-list tr:first-child .download-btn');
await page.waitForEvent('download');
Consider what happens if the data-testid attribute is renamed in a refactor, if billing navigation moves to a sidebar, or if the invoice table is paginated differently.
With an agent, the instruction is a goal in plain words:
Goal: "Go to app.saas.com, log in with my credentials,
navigate to billing, find the most recent invoice,
and download it as a PDF."
The agent loads the page and reads the DOM and visual layout, spots the login form by meaning, fills in credentials and submits, looks for navigation labeled Billing, Invoices or similar, finds the newest invoice by date and clicks download. If the UI changes, it re-reads the page and adapts. No script needs updating.
From scripting to instructing
Traditional automation asks which exact steps the computer should take. Agent-era automation asks what outcome is wanted and whether the AI can find the steps. One way to put it: scripting programs the path, while instructing programs the destination.
For simple, stable, high-volume work such as 10,000 regression tests in CI, Playwright's determinism wins every time. For complex, changing, one-off workflows of the kind a human assistant would take on, browser agents driven through MCP are pulling ahead.
Tools appearing in this space
The ecosystem is growing quickly:
- Playwright MCP, an official MCP server exposing Playwright browser actions to AI agents.
- Stagehand from Browserbase, AI-native automation combining Playwright with LLM vision.
- Browser Use, an open-source framework for web browsing agents.
- Claude Computer Use, Anthropic's system that can see and control a full desktop or browser.
- OpenAI Operator, a GPT-4o agent that browses to finish tasks.
- Skyvern, vision and LLM based automation that needs no selectors.
These aren't toys. Companies apply them to procurement workflows, data extraction, form submissions and competitor monitoring, work that might otherwise take months of scripting.
Will Playwright disappear?
No, though its role is shifting. It stays essential but is no longer the only tool in the box. It resembles SQL: foundational, precise and irreplaceable for structured work, yet no longer the only route to answers. The future uses both approaches for the jobs each suits.
Choosing between them
The decision runs as a flowchart. Start by asking whether the task is well defined with a stable UI. If so, and it runs repeatedly at scale, as in CI or regression, scripts are the answer. If the UI shifts or the task is a one-off, an agent fits better.
Is the task well-defined with a stable UI?
│
├── YES → Does it run repeatedly at scale (CI/CD, regression)?
│ │
│ ├── YES → Use Playwright
│ └── NO → Either works; Playwright is cheaper
│
└── NO → Is the UI dynamic, unknown, or frequently changing?
│
├── YES → Use MCP Agent / AI Browser
└── NO → Does it require multi-step reasoning?
│
├── YES → Use MCP Agent
└── NO → Use Playwright
The next two years
Agents won't erase scripted automation overnight, but several trends are visible.
- Hybrid pipelines become normal. Playwright covers the stable, repetitive 80%, and an MCP agent takes the unpredictable 20% that breaks scripts every sprint.
- Playwright gains AI features. Expect selector healing in which a failing selector asks an LLM to locate the equivalent element on the updated page. Healenium and Reflect already do something like this, and native support in Playwright seems likely.
- Agent reliability improves. Current agents sometimes misread a page, click the wrong element or get thrown by popups. Better multimodal models such as GPT-4o, Claude 3.5 Sonnet and Gemini 2.0 should cut those failures sharply.
- QA changes shape. Instead of writing Playwright scripts, testers will state intentions in natural language and let agents interpret and run them, moving from scripting to specifying outcomes.
- Security becomes a live issue. An agent with autonomous browser control might click something unintended, submit a form with wrong data or be manipulated by a malicious page. Prompt injection through web content, where a page tricks an agent into unintended actions, is already a documented threat. Here lies Playwright's biggest advantage, because it does exactly what the script says and nothing more.
The bigger picture
For a decade, browser automation was a translation problem: turn human intent into code that imitates human actions. Playwright solved it beautifully. Agents now remove the translation step, since intent in plain language is enough and the agent handles the rest. That doesn't make Playwright obsolete. It makes it specialized, much as a surgeon keeps using a scalpel in the age of robotic surgery. The scalpel offers precision, control and reliability, and the robot offers handling of complexity, adaptability and scale. The practical question is no longer Playwright against MCP. It is when a scalpel is needed and when a robot is.