# Letting an agent work a no-API web app without handing it Save

> Playwright MCP reads the page's accessibility snapshot rather than screenshots, while the login session and every write stay under human control.

Original: https://fdetimes.net/en/guides/playwright-mcp-internal-web-no-api/

Picture a day at a client site. The operations team wants an agent to update order statuses automatically, but their internal system is a web interface written years ago, with no API at all. A forward deployed engineer should have a plan for this kind of situation before sitting down with the client.

Playwright MCP is a practical answer. Microsoft released it as an MCP server that lets an LLM control a browser through Playwright. The key point is that it works on a structured accessibility snapshot, so it needs neither screenshots nor a vision model.

This guide walks through five steps applied to a hypothetical case: the agent logs in to an internal order-management page, fills in a status-update form, and clicks "Save" only when a person approves. You need Node.js, Playwright installed, an MCP-capable client and a website to practise on. If you have no real internal app, a demo app running locally is enough.

## Step 1: the login session is your most sensitive asset

The agent should not type a password every time it runs. Playwright recommends saving the authenticated state to a file for reuse, placing that file in a `playwright/.auth` directory and adding the directory to `.gitignore`.

```bash
mkdir -p playwright/.auth
echo "playwright/.auth" >> .gitignore
git status   # the .auth directory must not appear here
```

The reason is spelled out in Playwright's documentation: the auth state file contains sensitive information, and they strongly recommend against committing it to a repository, even a private one. At a client, this file is usually the session cookie of a real employee. Leak the file and you leak that person's access.

Check after this step: run `git status` and make sure no file inside `.auth` shows up. To create the state file, follow the Authentication page in the Playwright docs.

## Step 2: launch the server with the session preloaded

Playwright MCP has a `--storage-state` option that preloads a login session into an isolated session. The agent's browser therefore opens already logged in. The snippet below only illustrates the flags; take the exact launch command and client configuration syntax from the README of the microsoft/playwright-mcp repository.

```bash
# Illustrative and simplified: replace <launch command> per the README
<Playwright MCP launch command> \
  --storage-state playwright/.auth/user.json \
  --allowed-origins https://orders.internal.example
```

The `--allowed-origins` flag limits which origins the browser may request, which makes it harder for the agent to wander onto other sites. But the README states plainly that this flag is not a security boundary. Treating it as your only line of defence is a design flaw.

## Step 3: the agent reads the snapshot instead of guessing coordinates

When the agent opens a page, it receives a snapshot describing the element tree. Each element has a ref, such as `e5`, which the agent uses in subsequent tool calls. Playwright's documentation sums it up: no screenshots, no guessing coordinates.

In the example below, the labels come from a Vietnamese-language app: "Mã đơn hàng" is the order ID, "Trạng thái" is the status and "Lưu" is the Save button.

```text
# Illustrative snapshot, shortened
- textbox "Order ID" [ref=e5]
- combobox "Status" [ref=e7]
- button "Save" [ref=e9]
```

For an old internal web app, this makes a big difference. A vision model has to guess which pixel the Save button sits on; with a snapshot, the agent only has to say "fill e5, select e7, click e9". If the layout shifts by a few pixels, working by ref still lands in the right place.

Check after this step: ask the agent to list the form's refs before it does anything. If the snapshot is missing labels, for instance an input field with no label, you have found the reason the agent will pick the wrong element. Note it down to report to the client's team.

## Step 4: the real protection is a human

Step 2 showed that `--allowed-origins` is not enough of a barrier. So where is the barrier? The MCP specification answers: there should always be a human in the loop with the ability to deny tool calls. The specification also recommends that clients ask for confirmation before sensitive operations and keep logs for audit.

In the order example, reading the snapshot and filling input fields can be left to the agent. Clicking e9 ("Save") changes real data, so it must pause and wait for a person to approve. A rule that is easy to apply: any action that cannot be undone requires confirmation, and every tool call is logged along with the ref and the value entered.

**Key point:** Restricting domains only keeps the agent from wandering; human approval and audit logs are the actual protection.

## Step 5: explore with MCP, run daily with a script

The official documentation places MCP in the category of specialised agentic loops and exploratory automation. The cost is tokens: both the tool schemas and the snapshots sit in the context. For coding agents such as Claude Code or Copilot working in large codebases, Playwright recommends the CLI.

A third-party benchmark, not part of the official documentation, found that the same task consumed about 114,000 tokens through MCP and about 27,000 through the Playwright CLI.

The figures depend on configuration, so treat them as indicative only. Even so, run the numbers assuming each order update costs exactly as much as the benchmark task: if the agent updates 50 orders a day, you spend 5,700,000 tokens instead of 1,350,000.

So once the workflow is clear, lock it into a script. Playwright codegen records your actions and favours locators based on role, text and test id.

How to do it: start codegen, then perform by hand exactly the steps the agent went through. Codegen records them and produces a script that is easy to review. It does not convert refs such as e5; instead, the role, text and test id locators it generates take the place of those refs in the script.

| Stage | Sensible tool | Why |
|---|---|---|
| Workflow not yet understood, unfamiliar interface | Playwright MCP | The agent reads the snapshot and experiments on its own |
| Workflow clear, run repeatedly | Script from codegen or the CLI | Fewer tokens, stable, easy to review |

## The most common mistakes

The first is committing the auth state file, usually because `.gitignore` was not updated before the file was created. The second is believing `--allowed-origins` is safe enough and skipping the confirmation step. The third is leaving MCP running indefinitely on a workflow that has already stabilised, then being surprised by the token bill.

A subtler problem lies in the interface itself. A snapshot is only as good as the page's accessibility labels. Faced with a form full of unnamed fields, do not try to write a longer prompt. Suggest that the client add labels or test ids, because that small change helps both the agent and the codegen script.

## How this skill shows up on a CV

When reading an FDE job description, phrases such as "legacy systems", "internal tools", "browser automation" or "human-in-the-loop" are your cue to bring this skill up. On your CV, do not just write "used Playwright MCP".

Tell the whole story: automated a system with no API, kept the login session out of the repo, put an approval step in front of data writes, then moved to scripts to cut costs.

On your first day at a client, the first thing to do is sit next to an operator and note which actions they can undo and which they cannot. That list determines where you place confirmation steps, and it usually matters more than any prompt you write for the agent.

**Try this week:**

- Save the login state of an internal web app (or a demo app) to playwright/.auth, add that directory to .gitignore, then check with git status.
- Have the agent read the snapshot of a form and list the ref of every input field, then make it stop and ask for confirmation before clicking the save button.
- Record the same workflow with Playwright codegen and compare the locators in the script with the refs the agent used.

## Sources

- [GitHub - microsoft/playwright-mcp: Playwright MCP server](https://github.com/microsoft/playwright-mcp)

- [Introduction | Playwright](https://playwright.dev/mcp/introduction)

- [The hidden cost of Agentic QA: How Playwright CLI reduced AI token usage by 40x](https://www.tothenew.com/insights/article/hidden-cost-agentic-qa-how-playwright-cli-reduced-ai-token-usage-40x)

- [Authentication | Playwright](https://playwright.dev/docs/auth)

- [Tools - Model Context Protocol](https://modelcontextprotocol.io/specification/2025-06-18/server/tools)

- [Test generator | Playwright](https://playwright.dev/docs/codegen)
