For AI agents and LLMs: a machine-readable index is available at llms.txt. A plain-Markdown version of any documentation page is available by appending .md to its URL.
Skip to main content

Run Playwright CLI and Playwright MCP on TestMu AI Browser Cloud

Playwright MCP and Playwright CLI are Microsoft's tools for giving an AI agent a browser. Both can attach to a running Chromium browser through a Chrome DevTools Protocol (CDP) endpoint. Point them at a TestMu AI Browser Cloud endpoint, and every page your agent opens loads in a cloud Chrome session, recorded on your dashboard, instead of in Chrome on your machine.

We checked this setup on November 23, 2026 with @playwright/mcp 0.0.86 and @playwright/cli 0.1.25 (both on Playwright 1.66.0-alpha-2026-11-18) and Node.js 24. Both connected to a Chrome 158 session on Windows 11, opened a page and read it back.

Choose Playwright CLI or Playwright MCP for Your Agent​

Playwright CLI (playwright-cli)Playwright MCP (@playwright/mcp)
How the agent calls itShell commands, taught by an installed skillMCP tools, loaded into the agent's context
Best fit, per the Playwright READMECoding agents that also work on a large codebase and need to save tokensLong agent loops that keep browser state and inspect page structure
How it reaches Browser Cloudbrowser.cdpEndpoint in .playwright/cli.config.jsonPLAYWRIGHT_MCP_CDP_ENDPOINT environment variable

The Playwright MCP README recommends the CLI for coding agents because CLI calls skip the large tool schemas and accessibility trees that MCP loads into context.

Set Up Credentials and Node.js for Playwright​

  1. A TestMu AI account. Your Username and Access Key are under Settings > Account Settings.
  2. Node.js 20 or later. Both packages require it.
  3. A coding agent or MCP client, such as Claude Code, Cursor, VS Code or Claude Desktop.

Set your credentials as environment variables:

export LT_USERNAME="your_username"
export LT_ACCESS_KEY="your_access_key"

Generate a Browser Cloud CDP Endpoint With Node.js​

Browser Cloud accepts CDP connections at wss://cdp.lambdatest.com/puppeteer. The session settings go in a capabilities query parameter as URL-encoded JSON, in the same format as the Puppeteer capabilities. Each new connection to the endpoint starts a new session.

Save this script as cdp-endpoint.mjs. It prints an endpoint built from your environment variables:

cdp-endpoint.mjs
// Prints a TestMu AI Browser Cloud CDP endpoint for tools that take a CDP URL.
const { LT_USERNAME, LT_ACCESS_KEY } = process.env;
if (!LT_USERNAME || !LT_ACCESS_KEY) {
console.error('Set LT_USERNAME and LT_ACCESS_KEY first.');
process.exit(1);
}

const capabilities = {
browserName: 'Chrome',
browserVersion: 'latest',
'LT:Options': {
platform: 'Windows 11',
build: 'Playwright',
name: process.argv[2] || 'Playwright session',
user: LT_USERNAME,
accessKey: LT_ACCESS_KEY,
network: true,
console: true,
},
};

console.log(
`wss://cdp.lambdatest.com/puppeteer?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
);

Run node cdp-endpoint.mjs "My session name" to print an endpoint. The session name is optional.

warning

The endpoint contains your access key. Keep it in local, untracked configuration only, and never paste it into a prompt, an issue or a file you commit.

Connect Playwright MCP to Browser Cloud​

Playwright MCP reads the endpoint from the PLAYWRIGHT_MCP_CDP_ENDPOINT environment variable (or the --cdp-endpoint option) and connects on the first browser tool call.

Add Playwright MCP to Claude Code​

Run this from your project folder. The local scope stores the server in your own Claude Code settings, not in the repository:

claude mcp add testmu-browser -s local \
-e PLAYWRIGHT_MCP_CDP_ENDPOINT="$(node cdp-endpoint.mjs 'Playwright MCP')" \
-- npx @playwright/mcp@latest

Do not use -s project: it writes the endpoint, and your access key with it, to .mcp.json, which teams usually commit.

Add Playwright MCP to Any MCP Client With a JSON Config​

Most MCP clients accept this configuration. Replace the value with the endpoint that cdp-endpoint.mjs printed:

{
"mcpServers": {
"testmu-browser": {
"command": "npx",
"args": ["@playwright/mcp@latest"],
"env": {
"PLAYWRIGHT_MCP_CDP_ENDPOINT": "<endpoint printed by cdp-endpoint.mjs>"
}
}
}
}

The Playwright MCP README gives the exact setup steps for each client. Keep the file that holds the endpoint out of version control.

Run a First Browser Task Through Playwright MCP​

Ask your agent for a browser task, for example:

Use the testmu-browser tools to open https://www.testmuai.com/selenium-playground/ and tell me the page title.

The first tool call starts the Browser Cloud session, which took 7 to 10 seconds in our runs. Later calls reuse the same session.

End a Playwright MCP Session on Browser Cloud​

The browser_close tool closes the cloud browser, and the dashboard lists the session as Completed. Quitting the MCP client also ends the session, which the dashboard then lists as Cancelled. A session that receives no command for idleTimeout seconds (300 by default) ends on its own.

Connect Playwright CLI to Browser Cloud​

Install the CLI, and install its skills so your coding agent learns the commands:

npm install -g @playwright/cli@latest
playwright-cli install --skills

Point Playwright CLI at Browser Cloud With a Config File​

Playwright CLI reads .playwright/cli.config.json from the folder it runs in. Put the endpoint in browser.cdpEndpoint:

.playwright/cli.config.json
{
"browser": {
"cdpEndpoint": "<endpoint printed by cdp-endpoint.mjs>"
}
}

Add .playwright/ to your .gitignore, because the file holds your access key.

note

playwright-cli attach --cdp=<endpoint> also connects, but it prints the full endpoint, access key included, in its output, where your coding agent reads and logs it. The config file keeps the endpoint out of the output.

Run Playwright CLI Commands in a Browser Cloud Session​

open starts a Browser Cloud session and attaches to it. The other commands run in that session:

playwright-cli open https://www.testmuai.com/selenium-playground/
playwright-cli snapshot
playwright-cli eval "() => document.title"
playwright-cli close

playwright-cli list shows the session as chrome (attached). A coding agent with the skills installed runs the same commands. Ask it, for example, to "use playwright-cli to open the Selenium Playground and check the page title".

End a Playwright CLI Session on Browser Cloud​

playwright-cli close and playwright-cli detach both disconnect, and Browser Cloud ends the session. In our runs the dashboard listed both as Cancelled, with the video and logs still recorded.

Change Platform and Idle Timeout for Playwright Sessions​

Edit LT:Options in cdp-endpoint.mjs, then generate a new endpoint:

OptionWhat it setsExample
platformOperating system of the cloud machine'Windows 11'
build, nameThe build and session names shown on the dashboard'Playwright'
network, consoleRecord network and browser console logstrue
resolutionScreen size (default 1920x1080)'1366x768'
idleTimeoutSeconds without a command before the session ends (default 300, maximum 1800)600
tunnel, tunnelNameSend traffic through a running tunnel to reach localhost or stagingtrue, 'my-tunnel'

Capabilities for Puppeteer lists every option. To reach private sites, start a tunnel first: Testing Locally Hosted Pages shows how.

Troubleshoot Playwright MCP and Playwright CLI Connections​

Error or symptomCause and fix
401 Unauthorized with Unauthorized, either Username or AccessKey is invalidBrowser Cloud rejected the credentials in the endpoint. Check LT_USERNAME and LT_ACCESS_KEY, run cdp-endpoint.mjs again and replace the old endpoint.
A CDP connection timeout from Playwright MCPPlaywright MCP waits 30 seconds by default. Raise it with --cdp-timeout or PLAYWRIGHT_MCP_CDP_TIMEOUT, and allow outbound WebSocket traffic to cdp.lambdatest.com on port 443.
Playwright CLI opens a local browserThe CLI did not find .playwright/cli.config.json. Run it from the folder that holds the .playwright folder.
The session ends during a long pauseThe agent sent no command for idleTimeout seconds. Raise idleTimeout, up to 1800.
warning

When the connection fails, Playwright MCP repeats the full endpoint in its error message to the agent, access key included. If that happens in a shared or logged session, rotate your access key.

Browser Use, SDK and Capability Guides for Browser Cloud​

Help and Support

Related Articles