Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/skills/playwright-dev/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ See [CLAUDE.md](../../../CLAUDE.md) for monorepo structure, build/test/lint comm

- [Library Architecture](library.md) — client/server/dispatcher structure, protocol layer, DEPS rules
- [Adding and Modifying APIs](api.md) — define API docs, implement client/server, add tests
- [MCP Tools and CLI Commands](mcp-dev.md) — add MCP tools, CLI commands, config options
- [MCP Tools and CLI Commands](tools.md) — add MCP tools, CLI commands, config options
- [Vendoring Dependencies](vendor.md) — bundle third-party npm packages into playwright-core or playwright
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

### Step 1: Create the Tool File

Create `packages/playwright/src/tools/<your-tool>.ts`.
Create `packages/playwright-core/src/tools/backend/<your-tool>.ts`.

Import zod from the MCP bundle and use `defineTool` or `defineTabTool`:

```typescript
import { z } from 'playwright-core/lib/mcpBundle';
import { z } from '../../mcpBundle';
import { defineTool, defineTabTool } from './tool';
```

Expand Down Expand Up @@ -90,7 +90,7 @@ const myContextTool = defineTool({

### Step 2: Add ToolCapability (if needed)

If your tool doesn't fit an existing capability, add a new one to `packages/playwright/src/mcp/config.d.ts`:
If your tool doesn't fit an existing capability, add a new one to `packages/playwright-core/src/tools/mcp/config.d.ts`:

```typescript
export type ToolCapability =
Expand All @@ -115,10 +115,10 @@ export type ToolCapability =

### Step 3: Register the Tool

In `packages/playwright/src/tools/tools.ts`:
In `packages/playwright-core/src/tools/backend/tools.ts`:

```typescript
import myTool from './tools/myTool';
import myTool from './myTool';

export const browserTools: Tool<any>[] = [
// ... existing tools ...
Expand Down Expand Up @@ -198,10 +198,10 @@ Implement the corresponding MCP tool first (see section above). CLI commands cal

### Step 2: Add the Command Declaration

In `packages/playwright/src/cli/daemon/commands.ts`, use `declareCommand()`:
In `packages/playwright-core/src/tools/cli-daemon/commands.ts`, use `declareCommand()`:

```typescript
import { z } from 'playwright-core/lib/mcpBundle';
import { z } from '../../mcpBundle';
import { declareCommand } from './command';

const myCommand = declareCommand({
Expand Down Expand Up @@ -249,7 +249,7 @@ const commandsArray: AnyCommandSchema[] = [
];
```

**Categories** (defined in `packages/playwright/src/cli/daemon/command.ts`):
**Categories** (defined in `packages/playwright-core/src/tools/cli-daemon/command.ts`):

```typescript
type Category = 'core' | 'navigation' | 'keyboard' | 'mouse' | 'export' |
Expand All @@ -258,8 +258,8 @@ type Category = 'core' | 'navigation' | 'keyboard' | 'mouse' | 'export' |
```

To add a new category:
1. Add it to `Category` type in `packages/playwright/src/cli/daemon/command.ts`
2. Add it to the `categories` array in `packages/playwright/src/cli/daemon/helpGenerator.ts`:
1. Add it to `Category` type in `packages/playwright-core/src/tools/cli-daemon/command.ts`
2. Add it to the `categories` array in `packages/playwright-core/src/tools/cli-daemon/helpGenerator.ts`:
```typescript
const categories: { name: Category, title: string }[] = [
// ... existing ...
Expand Down Expand Up @@ -316,7 +316,7 @@ test('my-command', async ({ cli, server }) => {

When you need to add a new config option, update these files in order:

### 1. Type definition: `packages/playwright/src/mcp/config.d.ts`
### 1. Type definition: `packages/playwright-core/src/tools/mcp/config.d.ts`

Add the option to the `Config` type with JSDoc:

Expand All @@ -331,7 +331,7 @@ export type Config = {
};
```

### 2. CLI options type: `packages/playwright/src/mcp/config.ts`
### 2. CLI options type: `packages/playwright-core/src/tools/mcp/config.ts`

Add to `CLIOptions` type:

Expand Down Expand Up @@ -379,7 +379,7 @@ options.myOption = envToString(process.env.PLAYWRIGHT_MCP_MY_OPTION);
// For semicolon lists: semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_MY_OPTION)
```

### 5. MCP server CLI: `packages/playwright/src/mcp/program.ts`
### 5. MCP server CLI: `packages/playwright-core/src/tools/mcp/program.ts`

Add CLI flag:

Expand Down Expand Up @@ -418,58 +418,72 @@ Run `npm run playwright-cli -- --help` to see the latest available commands and
### Directory Structure

```
packages/playwright-core/src/tools/
├── backend/ # All MCP tool implementations
│ ├── tool.ts # Tool/TabTool types, defineTool(), defineTabTool()
│ ├── tools.ts # Tool registry (browserTools array, filteredTools)
│ ├── browserBackend.ts # Browser backend
│ ├── context.ts # Browser context management
│ ├── tab.ts # Tab management
│ ├── response.ts # Response class, parseResponse()
│ ├── common.ts # close, resize
│ ├── navigate.ts # navigate, goBack, goForward, reload
│ ├── snapshot.ts # page snapshot
│ ├── form.ts # click, type, fill, select, check
│ ├── keyboard.ts # press, keydown, keyup
│ ├── mouse.ts # mouse move, click, wheel
│ ├── tabs.ts # tab management
│ ├── cookies.ts # cookie CRUD
│ ├── webstorage.ts # localStorage, sessionStorage
│ ├── storage.ts # storage state save/load
│ ├── network.ts # network requests listing
│ ├── route.ts # request mocking/routing
│ ├── console.ts # console messages
│ ├── evaluate.ts # JS evaluation
│ ├── screenshot.ts # screenshots
│ ├── pdf.ts # PDF generation
│ ├── files.ts # file upload
│ ├── dialogs.ts # dialog handling
│ ├── verify.ts # assertions
│ ├── wait.ts # wait operations
│ ├── tracing.ts # trace recording
│ ├── video.ts # video recording
│ ├── runCode.ts # run Playwright code
│ ├── devtools.ts # DevTools integration
│ ├── config.ts # config tool
│ └── utils.ts # shared utilities
├── mcp/ # MCP server
│ ├── config.d.ts # Config type, ToolCapability type
│ ├── config.ts # Config resolution, CLIOptions, FullConfig
│ ├── program.ts # MCP server CLI setup
│ ├── index.ts # MCP server entry
│ ├── browserFactory.ts # Browser factory
│ ├── extensionContextFactory.ts
│ ├── cdpRelay.ts # CDP relay
│ ├── watchdog.ts # Watchdog
│ └── log.ts # Logging
├── cli-client/ # CLI client
│ ├── program.ts # CLI client entry (argument parsing)
│ ├── session.ts # Session management
│ └── registry.ts # Session registry
├── cli-daemon/ # CLI daemon
│ ├── command.ts # Category type, CommandSchema, declareCommand(), parseCommand()
│ ├── commands.ts # All CLI command declarations
│ ├── helpGenerator.ts # Help text generation (generateHelp, generateHelpJSON)
│ ├── daemon.ts # Daemon server
│ └── program.ts # Daemon program entry
├── dashboard/ # Dashboard UI
│ ├── dashboardApp.ts # Dashboard app
│ └── dashboardController.ts
├── utils/
│ ├── socketConnection.ts # Socket connection utilities
│ └── mcp/ # MCP SDK utilities
│ ├── server.ts # MCP server wrapper
│ ├── tool.ts # ToolSchema type, toMcpTool()
│ └── http.ts # HTTP utilities
└── exports.ts # Public exports

packages/playwright/src/
├── mcp/
│ ├── browser/
│ │ ├── tools/ # All MCP tool implementations
│ │ │ ├── tool.ts # Tool/TabTool types, defineTool(), defineTabTool()
│ │ │ ├── common.ts # close, resize
│ │ │ ├── navigate.ts # navigate, goBack, goForward, reload
│ │ │ ├── snapshot.ts # page snapshot
│ │ │ ├── form.ts # click, type, fill, select, check
│ │ │ ├── keyboard.ts # press, keydown, keyup
│ │ │ ├── mouse.ts # mouse move, click, wheel
│ │ │ ├── tabs.ts # tab management
│ │ │ ├── cookies.ts # cookie CRUD
│ │ │ ├── webstorage.ts # localStorage, sessionStorage
│ │ │ ├── storage.ts # storage state save/load
│ │ │ ├── network.ts # network requests listing
│ │ │ ├── route.ts # request mocking/routing
│ │ │ ├── console.ts # console messages
│ │ │ ├── evaluate.ts # JS evaluation
│ │ │ ├── screenshot.ts # screenshots
│ │ │ ├── pdf.ts # PDF generation
│ │ │ ├── files.ts # file upload
│ │ │ ├── dialogs.ts # dialog handling
│ │ │ ├── verify.ts # assertions
│ │ │ ├── wait.ts # wait operations
│ │ │ ├── tracing.ts # trace recording
│ │ │ ├── video.ts # video recording
│ │ │ ├── runCode.ts # run Playwright code
│ │ │ ├── devtools.ts # DevTools integration
│ │ │ ├── config.ts # config tool
│ │ │ ├── install.ts # browser install
│ │ │ └── utils.ts # shared utilities
│ │ ├── tools.ts # Tool registry (browserTools array, filteredTools)
│ │ ├── config.ts # Config resolution, CLIOptions, FullConfig
│ │ ├── context.ts # Browser context management
│ │ ├── response.ts # Response class, parseResponse()
│ │ └── tab.ts # Tab management
│ ├── sdk/
│ │ ├── server.ts # MCP server
│ │ └── tool.ts # ToolSchema type, toMcpTool()
│ ├── config.d.ts # Config type, ToolCapability type
│ └── program.ts # MCP server CLI setup
├── cli/
│ ├── client/
│ │ ├── program.ts # CLI client entry (argument parsing)
│ │ ├── session.ts # Session management
│ │ └── registry.ts # Session registry
│ └── daemon/
│ ├── command.ts # Category type, CommandSchema, declareCommand(), parseCommand()
│ ├── commands.ts # All CLI command declarations
│ ├── helpGenerator.ts # Help text generation (generateHelp, generateHelpJSON)
│ └── daemon.ts # Daemon server
└── skill/
├── SKILL.md # Skill documentation
└── references/ # Reference docs
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/tests_components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ on:
paths-ignore:
- 'browser_patches/**'
- 'docs/**'
- 'packages/playwright-core/src/cli/client/**'
- 'packages/playwright-core/src/cli/daemon/**'
- 'packages/playwright-core/src/mcp/**'
- 'packages/playwright/src/mcp/**'
- 'packages/playwright-core/src/tools/**'
- 'tests/mcp/**'
branches:
- main
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/tests_primary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ on:
paths-ignore:
- 'browser_patches/**'
- 'docs/**'
- 'packages/playwright-core/src/cli/client/**'
- 'packages/playwright-core/src/cli/daemon/**'
- 'packages/playwright-core/src/mcp/**'
- 'packages/playwright/src/mcp/**'
- 'packages/playwright-core/src/tools/**'
- 'tests/mcp/**'
branches:
- main
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ Detailed guides for common development tasks:

- **[Architecture: Client, Server, and Dispatchers](.claude/skills/playwright-dev/library.md)** — package layout, protocol layer, ChannelOwner/SdkObject/Dispatcher base classes, DEPS rules, end-to-end RPC flow, object lifecycle
- **[Adding and Modifying APIs](.claude/skills/playwright-dev/api.md)** — 6-step process: define docs → implement client → define protocol → implement dispatcher → implement server → write tests
- **[MCP Tools and CLI Commands](.claude/skills/playwright-dev/mcp-dev.md)** — `defineTool()`/`defineTabTool()`, tool capabilities, CLI `declareCommand()`, config options, testing with MCP fixtures
- **[MCP Tools and CLI Commands](.claude/skills/playwright-dev/tools.md)** — `defineTool()`/`defineTabTool()`, tool capabilities, CLI `declareCommand()`, config options, testing with MCP fixtures
- **[Vendoring Dependencies](.claude/skills/playwright-dev/vendor.md)** — bundle architecture, esbuild setup, typed wrappers, adding deps to existing bundles
11 changes: 8 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"build-android-driver": "./utils/build_android_driver.sh",
"innerloop": "playwright run-server --reuse-browser",
"test-playwright-cli": "playwright test --config=tests/mcp/playwright.config.ts --project=chrome cli-",
"playwright-cli": "node packages/playwright-core/lib/cli/client/cli.js",
"playwright-cli": "node packages/playwright-core/lib/tools/cli-client/cli.js",
"playwright-cli-readme": "node utils/generate_cli_help.js --readme"
},
"workspaces": [
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@playwright/devtools",
"name": "@playwright/dashboard",
"private": true,
"version": "0.0.0",
"type": "module"
Expand Down
File renamed without changes.
File renamed without changes.
Loading
Loading