Compare commits

...

41 Commits

Author SHA1 Message Date
Yury Semikhatsky
112cbb8574 chore: fix npm audits (#1460) 2026-03-13 18:23:09 -07:00
Mark Zhang
81f5084757 fix(extension): arm inactivity timers for all pending tabs (#1443) 2026-03-13 11:59:21 -07:00
Yury Semikhatsky
2bb0de1fa8 fix(readme): add missing tool categories (#1459)
Closes #1457
2026-03-13 10:16:27 -07:00
dependabot[bot]
6e69d62c7a chore(deps-dev): bump hono from 4.12.5 to 4.12.7 (#1453) 2026-03-13 10:12:48 -07:00
Willian Tolotti
55622bf5f1 feat(package): add mcpName field for MCP Registry ownership verification (#1432) 2026-03-09 15:37:44 -07:00
Yury Semikhatsky
a9d95f8d83 docs: not a security boundary section (#1435) 2026-03-04 18:38:40 -08:00
Yury Semikhatsky
d8f8b7b52d Revert "docs: fix PLAYWRIGHT_MCP_ALLOWED_HOSTS env var name (#1414)" (#1440)
This reverts commit f1f42f8616.

It broke lint. See
https://github.com/microsoft/playwright-mcp/pull/1414/checks in the
original PR.
2026-03-04 17:13:40 -08:00
dependabot[bot]
0d8753294d chore(deps-dev): bump hono from 4.11.8 to 4.12.5 (#1437) 2026-03-04 17:05:26 -08:00
dependabot[bot]
1e0b51325e chore(deps-dev): bump @hono/node-server from 1.19.9 to 1.19.10 (#1438) 2026-03-04 17:05:05 -08:00
Promode
43e31e8361 doc: Add Antigravity to MCP client list in README (#1419) 2026-02-25 11:10:43 -08:00
Luca Moretti
f1f42f8616 docs: fix PLAYWRIGHT_MCP_ALLOWED_HOSTS env var name (#1414) 2026-02-21 15:07:56 -08:00
Luca Moretti
c60d7bd7a6 docs: add --host 0.0.0.0 to Docker service example (#1415) 2026-02-21 15:06:51 -08:00
Yury Semikhatsky
066e54b6ea chore: mark 0.0.68 (#1406) 2026-02-14 15:17:41 -08:00
Yury Semikhatsky
d6c2e7ce5e chore: roll to Feb 14 (#1405) 2026-02-14 14:33:34 -08:00
Yury Semikhatsky
8c4b1aaa25 chore: fix tests on linux (#1404) 2026-02-14 13:11:47 -08:00
Yury Semikhatsky
bd1428d5b4 chore: mark v0.0.67 (#1401) 2026-02-13 18:30:26 -08:00
Yury Semikhatsky
793215ac07 chore: roll 1.59.0-alpha-1771028105000 (#1400) 2026-02-13 18:28:41 -08:00
dependabot[bot]
b0b4b76d1b chore(deps-dev): bump qs from 6.14.1 to 6.14.2 (#1398) 2026-02-13 16:54:20 -08:00
Yury Semikhatsky
af9ec1823b chore: connect to published extension (#1399) 2026-02-13 16:50:28 -08:00
Yury Semikhatsky
79dd021d1d chore: normalize "repository.url" 2026-02-13 15:53:19 -08:00
Yury Semikhatsky
39d9213352 chore: remove stale @playwright/cli dependency from stub (#1397) 2026-02-13 15:49:32 -08:00
Yury Semikhatsky
167abba9e6 chore(extension): remove unused permission (#1383) 2026-02-09 12:33:16 -08:00
Yury Semikhatsky
e4575a6eb2 chore: bump deps (#1379)
Fixes audit errors
2026-02-06 14:07:30 -08:00
Yury Semikhatsky
1c8807acef devops: remove playwright-cli from this repo (#1378) 2026-02-06 13:40:38 -08:00
Yury Semikhatsky
a3d2ba699a devops: roll script (#1377) 2026-02-06 10:20:37 -08:00
Pavel Feldman
0e6e6d216e chore: mark v0.0.66 2026-02-06 10:07:42 -08:00
Yury Semikhatsky
6cbc866c2d chore: mark v0.0.65 (#1376) 2026-02-06 10:02:11 -08:00
Yury Semikhatsky
fe2e818968 chore: roll 1.59.0-alpha-1770400094000 (#1375) 2026-02-06 10:00:36 -08:00
Pavel Feldman
e39e83bb13 chore: mark v0.0.64 (#1371) 2026-02-05 17:11:02 -08:00
Pavel Feldman
de6776f318 update cli readme
Added installation instructions for skills and updated CLI commands.
2026-02-03 15:59:09 -08:00
Pavel Feldman
822d81e02b restoring readme 2026-02-03 15:52:13 -08:00
Pavel Feldman
fed2475a86 Enhance README with installation and feature details 2026-02-03 15:43:17 -08:00
Pavel Feldman
34679cc689 Update readme for new skills 2026-02-03 15:39:45 -08:00
Pavel Feldman
c83315e4c9 chore: mark v0.0.63 (#1365) 2026-02-03 15:21:11 -08:00
Pavel Feldman
d246fff5d7 chore: mark v0.0.62 (#1360) 2026-01-30 17:16:54 -08:00
Pavel Feldman
925735af51 chore: update the playwright-cli stub (#1353) 2026-01-28 20:24:13 -08:00
Yury Semikhatsky
8b8e518029 chore: add test for cli --extension (#1356) 2026-01-28 20:24:03 -08:00
Pavel Feldman
cd9819d0e8 chore: mark v0.0.61 (#1349) 2026-01-26 14:54:15 -08:00
Pavel Feldman
542b74d2b4 chore: remove dummy cli tests (#1348) 2026-01-26 14:33:53 -08:00
Pavel Feldman
15c299778a chore: read esbuild deps (#1347) 2026-01-26 14:20:58 -08:00
Pavel Feldman
5e0ac89c28 chore: split mcp into mcp and cli (#1346) 2026-01-26 14:17:36 -08:00
21 changed files with 1661 additions and 947 deletions

View File

@@ -6,6 +6,10 @@ on:
pull_request:
branches: [ main ]
env:
PWMCP_DEBUG: '1'
PWDEBUGIMPL: '1'
jobs:
lint:
runs-on: ubuntu-latest
@@ -21,7 +25,7 @@ jobs:
- name: Ensure no changes
run: git diff --exit-code
test_mcp:
test:
strategy:
fail-fast: false
matrix:
@@ -38,9 +42,20 @@ jobs:
run: npm ci
- name: Playwright install
run: npx playwright install --with-deps
- name: Run tests
run: npm run test
working-directory: ./packages/playwright-mcp
- name: Build
run: npm run build
- name: Run playwright-mcp tests
id: test-mcp
run: npm run test --workspace=packages/playwright-mcp
continue-on-error: true
- name: Run extension tests
id: test-extension
if: matrix.os == 'macos-15'
run: npm run test --workspace=packages/extension
continue-on-error: true
- name: Check test results
if: steps.test-mcp.outcome == 'failure' || steps.test-extension.outcome == 'failure'
run: exit 1
test_mcp_docker:
runs-on: ubuntu-latest
@@ -73,35 +88,3 @@ jobs:
working-directory: ./packages/playwright-mcp
env:
MCP_IN_DOCKER: 1
test_extension:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: '20' # crypto.randomUUID(); stalls in v18.20.8
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Playwright install
run: npx playwright install --with-deps
- name: Build extension
run: npm run build
working-directory: ./packages/extension
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: extension
path: ./extension/dist
retention-days: 7
- name: Run tests
run: |
if [[ "$(uname)" == "Linux" ]]; then
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test
else
npm run test
fi
shell: bash
working-directory: ./packages/extension

View File

@@ -186,8 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Portions Copyright (c) Microsoft Corporation.
Portions Copyright 2017 Google Inc.
Copyright (c) Microsoft Corporation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

318
README.md
View File

@@ -72,6 +72,26 @@ amp mcp add playwright -- npx @playwright/mcp@latest
</details>
<details>
<summary>Antigravity</summary>
Add via the Antigravity settings or by updating your configuration file:
```json
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest"
]
}
}
}
```
</details>
<details>
<summary>Claude Code</summary>
@@ -340,9 +360,10 @@ Playwright MCP server supports following arguments. They can be provided in the
| --blocked-origins <origins> | semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed. Important: *does not* serve as a security boundary and *does not* affect redirects.<br>*env* `PLAYWRIGHT_MCP_BLOCKED_ORIGINS` |
| --block-service-workers | block service workers<br>*env* `PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERS` |
| --browser <browser> | browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.<br>*env* `PLAYWRIGHT_MCP_BROWSER` |
| --caps <caps> | comma-separated list of additional capabilities to enable, possible values: vision, pdf.<br>*env* `PLAYWRIGHT_MCP_CAPS` |
| --caps <caps> | comma-separated list of additional capabilities to enable, possible values: vision, pdf, devtools.<br>*env* `PLAYWRIGHT_MCP_CAPS` |
| --cdp-endpoint <endpoint> | CDP endpoint to connect to.<br>*env* `PLAYWRIGHT_MCP_CDP_ENDPOINT` |
| --cdp-header <headers...> | CDP headers to send with the connect request, multiple can be specified.<br>*env* `PLAYWRIGHT_MCP_CDP_HEADER` |
| --cdp-timeout <timeout> | timeout in milliseconds for connecting to CDP endpoint, defaults to 30000ms<br>*env* `PLAYWRIGHT_MCP_CDP_TIMEOUT` |
| --codegen <lang> | specify the language to use for code generation, possible values: "typescript", "none". Default is "typescript".<br>*env* `PLAYWRIGHT_MCP_CODEGEN` |
| --config <path> | path to the configuration file.<br>*env* `PLAYWRIGHT_MCP_CONFIG` |
| --console-level <level> | level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.<br>*env* `PLAYWRIGHT_MCP_CONSOLE_LEVEL` |
@@ -363,6 +384,7 @@ Playwright MCP server supports following arguments. They can be provided in the
| --port <port> | port to listen on for SSE transport.<br>*env* `PLAYWRIGHT_MCP_PORT` |
| --proxy-bypass <bypass> | comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"<br>*env* `PLAYWRIGHT_MCP_PROXY_BYPASS` |
| --proxy-server <proxy> | specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"<br>*env* `PLAYWRIGHT_MCP_PROXY_SERVER` |
| --sandbox | enable the sandbox for all process types that are normally not sandboxed.<br>*env* `PLAYWRIGHT_MCP_SANDBOX` |
| --save-session | Whether to save the Playwright MCP session into the output directory.<br>*env* `PLAYWRIGHT_MCP_SAVE_SESSION` |
| --save-trace | Whether to save the Playwright Trace of the session into the output directory.<br>*env* `PLAYWRIGHT_MCP_SAVE_TRACE` |
| --save-video <size> | Whether to save the video of the session into the output directory. For example "--save-video=800x600"<br>*env* `PLAYWRIGHT_MCP_SAVE_VIDEO` |
@@ -537,6 +559,13 @@ npx @playwright/mcp@latest --config path/to/config.json
initScript?: string[];
},
/**
* Connect to a running browser instance (Edge/Chrome only). If specified, `browser`
* config is ignored.
* Requires the "Playwright MCP Bridge" browser extension to be installed.
*/
extension?: boolean;
server?: {
/**
* The port to listen on for SSE or MCP transport.
@@ -560,6 +589,7 @@ npx @playwright/mcp@latest --config path/to/config.json
* - 'core': Core browser automation features.
* - 'pdf': PDF generation and manipulation.
* - 'vision': Coordinate-based interactions.
* - 'devtools': Developer tools features.
*/
capabilities?: ToolCapability[];
@@ -613,11 +643,19 @@ npx @playwright/mcp@latest --config path/to/config.json
network?: {
/**
* List of origins to allow the browser to request. Default is to allow all. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked.
*
* Supported formats:
* - Full origin: `https://example.com:8080` - matches only that origin
* - Wildcard port: `http://localhost:*` - matches any port on localhost with http protocol
*/
allowedOrigins?: string[];
/**
* List of origins to block the browser to request. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked.
*
* Supported formats:
* - Full origin: `https://example.com:8080` - matches only that origin
* - Wildcard port: `http://localhost:*` - matches any port on localhost with http protocol
*/
blockedOrigins?: string[];
};
@@ -689,6 +727,10 @@ And then in MCP client config, set the `url` to the HTTP endpoint:
}
```
## Security
Playwright MCP is **not** a security boundary. See [MCP Security Best Practices](https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices) for guidance on securing your deployment.
<details>
<summary><b>Docker</b></summary>
@@ -713,7 +755,7 @@ docker run -d -i --rm --init --pull=always \
--name playwright \
-p 8931:8931 \
mcr.microsoft.com/playwright/mcp \
cli.js --headless --browser chromium --no-sandbox --port 8931
cli.js --headless --browser chromium --no-sandbox --port 8931 --host 0.0.0.0
```
The server will listen on host port **8931** and can be reached by any MCP client.
@@ -988,6 +1030,257 @@ http.createServer(async (req, res) => {
</details>
<details>
<summary><b>Configuration (opt-in via --caps=config)</b></summary>
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_get_config**
- Title: Get config
- Description: Get the final resolved config after merging CLI options, environment variables and config file.
- Parameters: None
- Read-only: **true**
</details>
<details>
<summary><b>Network (opt-in via --caps=network)</b></summary>
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_route**
- Title: Mock network requests
- Description: Set up a route to mock network requests matching a URL pattern
- Parameters:
- `pattern` (string): URL pattern to match (e.g., "**/api/users", "**/*.{png,jpg}")
- `status` (number, optional): HTTP status code to return (default: 200)
- `body` (string, optional): Response body (text or JSON string)
- `contentType` (string, optional): Content-Type header (e.g., "application/json", "text/html")
- `headers` (array, optional): Headers to add in "Name: Value" format
- `removeHeaders` (string, optional): Comma-separated list of header names to remove from request
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_route_list**
- Title: List network routes
- Description: List all active network routes
- Parameters: None
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_unroute**
- Title: Remove network routes
- Description: Remove network routes matching a pattern (or all routes if no pattern specified)
- Parameters:
- `pattern` (string, optional): URL pattern to unroute (omit to remove all routes)
- Read-only: **false**
</details>
<details>
<summary><b>Storage (opt-in via --caps=storage)</b></summary>
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_cookie_clear**
- Title: Clear cookies
- Description: Clear all cookies
- Parameters: None
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_cookie_delete**
- Title: Delete cookie
- Description: Delete a specific cookie
- Parameters:
- `name` (string): Cookie name to delete
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_cookie_get**
- Title: Get cookie
- Description: Get a specific cookie by name
- Parameters:
- `name` (string): Cookie name to get
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_cookie_list**
- Title: List cookies
- Description: List all cookies (optionally filtered by domain/path)
- Parameters:
- `domain` (string, optional): Filter cookies by domain
- `path` (string, optional): Filter cookies by path
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_cookie_set**
- Title: Set cookie
- Description: Set a cookie with optional flags (domain, path, expires, httpOnly, secure, sameSite)
- Parameters:
- `name` (string): Cookie name
- `value` (string): Cookie value
- `domain` (string, optional): Cookie domain
- `path` (string, optional): Cookie path
- `expires` (number, optional): Cookie expiration as Unix timestamp
- `httpOnly` (boolean, optional): Whether the cookie is HTTP only
- `secure` (boolean, optional): Whether the cookie is secure
- `sameSite` (string, optional): Cookie SameSite attribute
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_localstorage_clear**
- Title: Clear localStorage
- Description: Clear all localStorage
- Parameters: None
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_localstorage_delete**
- Title: Delete localStorage item
- Description: Delete a localStorage item
- Parameters:
- `key` (string): Key to delete
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_localstorage_get**
- Title: Get localStorage item
- Description: Get a localStorage item by key
- Parameters:
- `key` (string): Key to get
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_localstorage_list**
- Title: List localStorage
- Description: List all localStorage key-value pairs
- Parameters: None
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_localstorage_set**
- Title: Set localStorage item
- Description: Set a localStorage item
- Parameters:
- `key` (string): Key to set
- `value` (string): Value to set
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_sessionstorage_clear**
- Title: Clear sessionStorage
- Description: Clear all sessionStorage
- Parameters: None
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_sessionstorage_delete**
- Title: Delete sessionStorage item
- Description: Delete a sessionStorage item
- Parameters:
- `key` (string): Key to delete
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_sessionstorage_get**
- Title: Get sessionStorage item
- Description: Get a sessionStorage item by key
- Parameters:
- `key` (string): Key to get
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_sessionstorage_list**
- Title: List sessionStorage
- Description: List all sessionStorage key-value pairs
- Parameters: None
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_sessionstorage_set**
- Title: Set sessionStorage item
- Description: Set a sessionStorage item
- Parameters:
- `key` (string): Key to set
- `value` (string): Value to set
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_set_storage_state**
- Title: Restore storage state
- Description: Restore storage state (cookies, local storage) from a file. This clears existing cookies and local storage before restoring.
- Parameters:
- `filename` (string): Path to the storage state file to restore from
- Read-only: **false**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_storage_state**
- Title: Save storage state
- Description: Save storage state (cookies, local storage) to a file for later reuse
- Parameters:
- `filename` (string, optional): File name to save the storage state to. Defaults to `storage-state-{timestamp}.json` if not specified.
- Read-only: **true**
</details>
<details>
<summary><b>DevTools (opt-in via --caps=devtools)</b></summary>
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_start_tracing**
- Title: Start tracing
- Description: Start trace recording
- Parameters: None
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_start_video**
- Title: Start video
- Description: Start video recording
- Parameters:
- `size` (object, optional): Video size
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_stop_tracing**
- Title: Stop tracing
- Description: Stop trace recording
- Parameters: None
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_stop_video**
- Title: Stop video
- Description: Stop video recording
- Parameters:
- `filename` (string, optional): Filename to save the video
- Read-only: **true**
</details>
<details>
<summary><b>Coordinate-based (opt-in via --caps=vision)</b></summary>
@@ -1124,26 +1417,5 @@ http.createServer(async (req, res) => {
</details>
<details>
<summary><b>Tracing (opt-in via --caps=tracing)</b></summary>
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_start_tracing**
- Title: Start tracing
- Description: Start trace recording
- Parameters: None
- Read-only: **true**
<!-- NOTE: This has been generated via update-readme.js -->
- **browser_stop_tracing**
- Title: Stop tracing
- Description: Stop trace recording
- Parameters: None
- Read-only: **true**
</details>
<!--- End of tools generated section -->

1621
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "playwright-mcp-internal",
"version": "0.0.60",
"version": "0.0.68",
"private": true,
"repository": {
"type": "git",
@@ -17,14 +17,16 @@
"docker-run": "docker run -it -p 8080:8080 --name playwright-mcp-dev playwright-mcp-dev:latest",
"lint": "npm run lint --workspaces",
"test": "npm run test --workspaces",
"build": "npm run build --workspaces"
"build": "npm run build --workspaces",
"bump": "npm version --workspaces --no-git-tag-version",
"roll": "node roll.js"
},
"workspaces": [
"packages/*"
],
"devDependencies": {
"@modelcontextprotocol/sdk": "^1.25.2",
"@playwright/test": "1.59.0-alpha-1769452054000",
"@playwright/test": "1.59.0-alpha-1771104257000",
"@types/node": "^24.3.0"
}
}

View File

@@ -10,16 +10,9 @@ The Playwright MCP Chrome Extension allows you to connect to pages in your exist
## Installation Steps
### Download the Extension
### Install the Extension
Download the latest Chrome extension from GitHub:
- **Download link**: https://github.com/microsoft/playwright-mcp/releases
### Load Chrome Extension
1. Open Chrome and navigate to `chrome://extensions/`
2. Enable "Developer mode" (toggle in the top right corner)
3. Click "Load unpacked" and select the extension directory
Install [Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm) from the Chrome Web Store.
### Configure Playwright MCP server

View File

@@ -1,14 +1,12 @@
{
"manifest_version": 3,
"name": "Playwright MCP Bridge",
"version": "0.0.60",
"version": "0.0.68",
"description": "Share browser tabs with Playwright MCP server",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9nMS2b0WCohjVHPGb8D9qAdkbIngDqoAjTeSccHJijgcONejge+OJxOQOMLu7b0ovt1c9BiEJa5JcpM+EHFVGL1vluBxK71zmBy1m2f9vZF3HG0LSCp7YRkum9rAIEthDwbkxx6XTvpmAY5rjFa/NON6b9Hlbo+8peUSkoOK7HTwYnnI36asZ9eUTiveIf+DMPLojW2UX33vDWG2UKvMVDewzclb4+uLxAYshY7Mx8we/b44xu+Anb/EBLKjOPk9Yh541xJ5Ozc8EiP/5yxOp9c/lRiYUHaRW+4r0HKZyFt0eZ52ti2iM4Nfk7jRXR7an3JPsUIf5deC/1cVM/+1ZQIDAQAB",
"permissions": [
"debugger",
"activeTab",
"tabs",
"storage"
"tabs"
],
"host_permissions": [
"<all_urls>"

View File

@@ -1,6 +1,6 @@
{
"name": "@playwright/mcp-extension",
"version": "0.0.60",
"version": "0.0.68",
"description": "Playwright MCP Browser Extension",
"private": true,
"repository": {
@@ -27,10 +27,11 @@
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@vitejs/plugin-react": "^4.0.0",
"minimist": "^1.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^5.8.2",
"vite": "^5.4.21",
"vite": "^7.3.1",
"vite-plugin-static-copy": "^3.1.1"
}
}

View File

@@ -190,7 +190,6 @@ class TabShareExtension {
chrome.tabs.sendMessage(tabId, { type: 'connectionTimeout' });
}
}, 5000);
return;
}
}
}

View File

@@ -14,9 +14,10 @@
* limitations under the License.
*/
import fs from 'fs';
import fs from 'fs/promises';
import path from 'path';
import { chromium } from 'playwright';
import { spawn } from 'child_process';
import { test as base, expect } from '../../playwright-mcp/tests/fixtures';
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
@@ -28,16 +29,35 @@ type BrowserWithExtension = {
launch: (mode?: 'disable-extension') => Promise<BrowserContext>;
};
type CliResult = {
output: string;
error: string;
};
type TestFixtures = {
browserWithExtension: BrowserWithExtension,
pathToExtension: string,
useShortConnectionTimeout: (timeoutMs: number) => void
overrideProtocolVersion: (version: number) => void
cli: (...args: string[]) => Promise<CliResult>;
};
const extensionPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwRsUUO4mmbCi4JpmrIoIw31iVW9+xUJRZ6nSzya17PQkaUPDxe1IpgM+vpd/xB6mJWlJSyE1Lj95c0sbomGfVY1M0zUeKbaRVcAb+/a6m59gNR+ubFlmTX0nK9/8fE2FpRB9D+4N5jyeIPQuASW/0oswI2/ijK7hH5NTRX8gWc/ROMSgUj7rKhTAgBrICt/NsStgDPsxRTPPJnhJ/ViJtM1P5KsSYswE987DPoFnpmkFpq8g1ae0eYbQfXy55ieaacC4QWyJPj3daU2kMfBQw7MXnnk0H/WDxouMOIHnd8MlQxpEMqAihj7KpuONH+MUhuj9HEQo4df6bSaIuQ0b4QIDAQAB';
const extensionId = 'mmlmfjhmonkocbjadbfplnigmagldckm';
const test = base.extend<TestFixtures>({
pathToExtension: async ({}, use) => {
await use(path.resolve(__dirname, '../dist'));
pathToExtension: async ({}, use, testInfo) => {
const extensionDir = testInfo.outputPath('extension');
const srcDir = path.resolve(__dirname, '../dist');
await fs.cp(srcDir, extensionDir, { recursive: true });
const manifestPath = path.join(extensionDir, 'manifest.json');
const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
// We don't hardcode the key in manifest, but for the tests we set the key field
// to ensure that locally installed extension has the same id as the one published
// in the store.
manifest.key = extensionPublicKey;
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
await use(extensionDir);
},
browserWithExtension: async ({ mcpBrowser, pathToExtension }, use, testInfo) => {
@@ -71,6 +91,9 @@ const test = base.extend<TestFixtures>({
}
});
await browserContext?.close();
// Free up disk space.
await fs.rm(userDataDir, { recursive: true, force: true }).catch(() => {});
},
useShortConnectionTimeout: async ({}, use) => {
@@ -85,9 +108,73 @@ const test = base.extend<TestFixtures>({
process.env.PWMCP_TEST_PROTOCOL_VERSION = version.toString();
});
process.env.PWMCP_TEST_PROTOCOL_VERSION = undefined;
}
},
cli: async ({ mcpBrowser }, use, testInfo) => {
await use(async (...args: string[]) => {
return await runCli(args, { mcpBrowser, testInfo });
});
// Cleanup sessions
await runCli(['close-all'], { mcpBrowser, testInfo }).catch(() => {});
const daemonDir = path.join(testInfo.outputDir, 'daemon');
await fs.rm(daemonDir, { recursive: true, force: true }).catch(() => {});
},
});
async function runCli(
args: string[],
options: { mcpBrowser?: string, testInfo: any },
): Promise<CliResult> {
const stepTitle = `cli ${args.join(' ')}`;
return await test.step(stepTitle, async () => {
const testInfo = options.testInfo;
// Path to the terminal CLI
const cliPath = path.join(__dirname, '../../../node_modules/playwright/lib/cli/client/program.js');
return new Promise<CliResult>((resolve, reject) => {
let stdout = '';
let stderr = '';
const childProcess = spawn(process.execPath, [cliPath, ...args], {
cwd: testInfo.outputPath(),
env: {
...process.env,
PLAYWRIGHT_DAEMON_INSTALL_DIR: testInfo.outputPath(),
PLAYWRIGHT_DAEMON_SESSION_DIR: testInfo.outputPath('daemon'),
PLAYWRIGHT_DAEMON_SOCKETS_DIR: path.join(testInfo.project.outputDir, 'daemon-sockets'),
PLAYWRIGHT_MCP_BROWSER: options.mcpBrowser,
PLAYWRIGHT_MCP_HEADLESS: 'false',
},
detached: true,
});
childProcess.stdout?.on('data', (data) => {
stdout += data.toString();
});
childProcess.stderr?.on('data', (data) => {
if (process.env.PWMCP_DEBUG)
process.stderr.write(data);
stderr += data.toString();
});
childProcess.on('close', async (code) => {
await testInfo.attach(stepTitle, { body: stdout, contentType: 'text/plain' });
resolve({
output: stdout.trim(),
error: stderr.trim(),
});
});
childProcess.on('error', reject);
});
});
}
async function startWithExtensionFlag(browserWithExtension: BrowserWithExtension, startClient: StartClient): Promise<Client> {
const { client } = await startClient({
args: [`--extension`],
@@ -101,17 +188,13 @@ async function startWithExtensionFlag(browserWithExtension: BrowserWithExtension
}
const testWithOldExtensionVersion = test.extend({
pathToExtension: async ({}, use, testInfo) => {
const extensionDir = testInfo.outputPath('extension');
const oldPath = path.resolve(__dirname, '../dist');
await fs.promises.cp(oldPath, extensionDir, { recursive: true });
const manifestPath = path.join(extensionDir, 'manifest.json');
const manifest = JSON.parse(await fs.promises.readFile(manifestPath, 'utf8'));
pathToExtension: async ({ pathToExtension }, use, testInfo) => {
const manifestPath = path.join(pathToExtension, 'manifest.json');
const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
manifest.key = extensionPublicKey;
manifest.version = '0.0.1';
await fs.promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n');
await use(extensionDir);
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
await use(pathToExtension);
},
});
@@ -121,7 +204,7 @@ test(`navigate with extension`, async ({ browserWithExtension, startClient, serv
const client = await startWithExtensionFlag(browserWithExtension, startClient);
const confirmationPagePromise = browserContext.waitForEvent('page', page => {
return page.url().startsWith('chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html');
return page.url().startsWith(`chrome-extension://${extensionId}/connect.html`);
});
const navigateResponse = client.callTool({
@@ -152,7 +235,7 @@ test(`snapshot of an existing page`, async ({ browserWithExtension, startClient,
expect(browserContext.pages()).toHaveLength(3);
const confirmationPagePromise = browserContext.waitForEvent('page', page => {
return page.url().startsWith('chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html');
return page.url().startsWith(`chrome-extension://${extensionId}/connect.html`);
});
const navigateResponse = client.callTool({
@@ -180,7 +263,7 @@ test(`extension not installed timeout`, async ({ browserWithExtension, startClie
const client = await startWithExtensionFlag(browserWithExtension, startClient);
const confirmationPagePromise = browserContext.waitForEvent('page', page => {
return page.url().startsWith('chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html');
return page.url().startsWith(`chrome-extension://${extensionId}/connect.html`);
});
expect(await client.callTool({
@@ -203,7 +286,7 @@ testWithOldExtensionVersion(`works with old extension version`, async ({ browser
const client = await startWithExtensionFlag(browserWithExtension, startClient);
const confirmationPagePromise = browserContext.waitForEvent('page', page => {
return page.url().startsWith('chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html');
return page.url().startsWith(`chrome-extension://${extensionId}/connect.html`);
});
const navigateResponse = client.callTool({
@@ -230,7 +313,7 @@ test(`extension needs update`, async ({ browserWithExtension, startClient, serve
const client = await startWithExtensionFlag(browserWithExtension, startClient);
const confirmationPagePromise = browserContext.waitForEvent('page', page => {
return page.url().startsWith('chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html');
return page.url().startsWith(`chrome-extension://${extensionId}/connect.html`);
});
const navigateResponse = client.callTool({
@@ -251,7 +334,7 @@ test(`custom executablePath`, async ({ startClient, server, useShortConnectionTi
useShortConnectionTimeout(1000);
const executablePath = test.info().outputPath('echo.sh');
await fs.promises.writeFile(executablePath, '#!/bin/bash\necho "Custom exec args: $@" > "$(dirname "$0")/output.txt"', { mode: 0o755 });
await fs.writeFile(executablePath, '#!/bin/bash\necho "Custom exec args: $@" > "$(dirname "$0")/output.txt"', { mode: 0o755 });
const { client } = await startClient({
args: [`--extension`],
@@ -272,14 +355,14 @@ test(`custom executablePath`, async ({ startClient, server, useShortConnectionTi
error: expect.stringContaining('Extension connection timeout.'),
isError: true,
});
expect(await fs.promises.readFile(test.info().outputPath('output.txt'), 'utf8')).toContain('Custom exec args: chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html?');
expect(await fs.readFile(test.info().outputPath('output.txt'), 'utf8')).toMatch(new RegExp(`Custom exec args.*chrome-extension://${extensionId}/connect\\.html\\?`));
});
test(`bypass connection dialog with token`, async ({ browserWithExtension, startClient, server }) => {
const browserContext = await browserWithExtension.launch();
const page = await browserContext.newPage();
await page.goto('chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/status.html');
await page.goto(`chrome-extension://${extensionId}/status.html`);
const token = await page.locator('.auth-token-code').textContent();
const [name, value] = token?.split('=') || [];
@@ -302,3 +385,38 @@ test(`bypass connection dialog with token`, async ({ browserWithExtension, start
snapshot: expect.stringContaining(`- generic [active] [ref=e1]: Hello, world!`),
});
});
test.describe('CLI with extension', () => {
test('open <url> --extension', async ({ browserWithExtension, cli, server }, testInfo) => {
const browserContext = await browserWithExtension.launch();
// Write config file with userDataDir
const configPath = testInfo.outputPath('cli-config.json');
await fs.writeFile(configPath, JSON.stringify({
browser: {
userDataDir: browserWithExtension.userDataDir,
}
}, null, 2));
const confirmationPagePromise = browserContext.waitForEvent('page', page => {
return page.url().startsWith(`chrome-extension://${extensionId}/connect.html`);
});
// Start the CLI command in the background
const cliPromise = cli('open', server.HELLO_WORLD, '--extension', `--config=cli-config.json`);
// Wait for the confirmation page to appear
const confirmationPage = await confirmationPagePromise;
// Click the Connect button
await confirmationPage.locator('.tab-item', { hasText: 'Playwright MCP extension' }).getByRole('button', { name: 'Connect' }).click();
// Wait for the CLI command to complete
const { output } = await cliPromise;
// Verify the output
expect(output).toContain(`### Page`);
expect(output).toContain(`- Page URL: ${server.HELLO_WORLD}`);
expect(output).toContain(`- Page Title: Title`);
});
});

View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright (c) Microsoft Corporation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,7 @@
# 🎭 Playwright CLI
This package has moved to @playwright/cli.
```sh
$ npm i -g @playwright/cli
```

View File

@@ -0,0 +1,19 @@
{
"name": "playwright-cli",
"version": "0.262.0",
"description": "Deprecated package, use @playwright/cli instead.",
"repository": {
"type": "git",
"url": "git+https://github.com/microsoft/playwright-cli.git"
},
"homepage": "https://playwright.dev",
"scripts": {
"lint": "echo OK",
"build": "echo OK",
"test": "echo OK"
},
"author": {
"name": "Microsoft Corporation"
},
"license": "Apache-2.0"
}

View File

@@ -2,6 +2,5 @@
!README.md
!LICENSE
!cli.js
!playwright-cli.js
!index.*
!config.d.ts

View File

@@ -16,9 +16,9 @@
*/
const { program } = require('playwright-core/lib/utilsBundle');
const { decorateCommand } = require('playwright/lib/mcp/program');
const { decorateMCPCommand } = require('playwright/lib/mcp/program');
const packageJSON = require('./package.json');
const p = program.version('Version ' + packageJSON.version).name('Playwright MCP');
decorateCommand(p, packageJSON.version)
decorateMCPCommand(p, packageJSON.version)
void program.parseAsync(process.argv);

View File

@@ -17,16 +17,18 @@
import type * as playwright from 'playwright';
export type ToolCapability =
'config' |
'core' |
'core-input' |
'core-navigation' |
'core-tabs' |
'core-install' |
'core-input' |
'vision' |
'core-install' |
'network' |
'pdf' |
'storage' |
'testing' |
'tracing';
'vision' |
'devtools';
export type Config = {
/**
@@ -96,6 +98,13 @@ export type Config = {
initScript?: string[];
},
/**
* Connect to a running browser instance (Edge/Chrome only). If specified, `browser`
* config is ignored.
* Requires the "Playwright MCP Bridge" browser extension to be installed.
*/
extension?: boolean;
server?: {
/**
* The port to listen on for SSE or MCP transport.
@@ -119,6 +128,7 @@ export type Config = {
* - 'core': Core browser automation features.
* - 'pdf': PDF generation and manipulation.
* - 'vision': Coordinate-based interactions.
* - 'devtools': Developer tools features.
*/
capabilities?: ToolCapability[];
@@ -172,11 +182,19 @@ export type Config = {
network?: {
/**
* List of origins to allow the browser to request. Default is to allow all. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked.
*
* Supported formats:
* - Full origin: `https://example.com:8080` - matches only that origin
* - Wildcard port: `http://localhost:*` - matches any port on localhost with http protocol
*/
allowedOrigins?: string[];
/**
* List of origins to block the browser to request. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked.
*
* Supported formats:
* - Full origin: `https://example.com:8080` - matches only that origin
* - Wildcard port: `http://localhost:*` - matches any port on localhost with http protocol
*/
blockedOrigins?: string[];
};

View File

@@ -1,6 +1,6 @@
{
"name": "@playwright/mcp",
"version": "0.0.60",
"version": "0.0.68",
"description": "Playwright Tools for MCP",
"repository": {
"type": "git",
@@ -14,6 +14,7 @@
"name": "Microsoft Corporation"
},
"license": "Apache-2.0",
"mcpName": "io.github.microsoft/playwright-mcp",
"scripts": {
"lint": "node update-readme.js",
"test": "playwright test",
@@ -22,9 +23,7 @@
"wtest": "playwright test --project=webkit",
"dtest": "MCP_IN_DOCKER=1 playwright test --project=chromium-docker",
"build": "echo OK",
"npm-publish": "npm run lint && npm run test && npm publish",
"copy-config": "cp ../../../playwright/packages/playwright/src/mcp/config.d.ts . && perl -pi -e \"s|import type \\* as playwright from 'playwright-core';|import type * as playwright from 'playwright';|\" ./config.d.ts",
"roll": "npm run copy-config && npm run lint"
"npm-publish": "npm run lint && npm run test && npm publish"
},
"exports": {
"./package.json": "./package.json",
@@ -34,12 +33,10 @@
}
},
"dependencies": {
"minimist": "^1.2.5",
"playwright": "1.59.0-alpha-1769452054000",
"playwright-core": "1.59.0-alpha-1769452054000"
"playwright": "1.59.0-alpha-1771104257000",
"playwright-core": "1.59.0-alpha-1771104257000"
},
"bin": {
"mcp": "cli.js",
"playwright-cli": "./playwright-cli.js"
"playwright-mcp": "cli.js"
}
}

View File

@@ -1,23 +0,0 @@
#!/usr/bin/env node
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const { program } = require('playwright/lib/mcp/terminal/program');
const packageJSON = require('./package.json');
program({ version: packageJSON.version }).catch(e => {
console.error(e.message);
process.exit(1);
});

View File

@@ -1,32 +0,0 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from '@playwright/test';
import childProcess from 'child_process';
function runCLI(args: string[]) {
return childProcess.spawnSync(process.execPath, [require.resolve('../playwright-cli'), ...args], { encoding: 'utf-8' });
}
test('prints help', async () => {
const { stdout } = runCLI(['--help']);
expect(stdout).toContain('Usage: playwright-cli <command>');
});
test('prints version', async () => {
const { stdout } = runCLI(['--version']);
expect(stdout).toContain(require('../package.json').version);
});

View File

@@ -22,21 +22,30 @@ const { execSync } = require('child_process');
const { browserTools } = require('playwright/lib/mcp/browser/tools');
const capabilities = {
const capabilities = /** @type {Record<string, string>} */ ({
'core-navigation': 'Core automation',
'core': 'Core automation',
'core-tabs': 'Tab management',
'core-input': 'Core automation',
'core-install': 'Browser installation',
'vision': 'Coordinate-based (opt-in via --caps=vision)',
'pdf': 'PDF generation (opt-in via --caps=pdf)',
'testing': 'Test assertions (opt-in via --caps=testing)',
'tracing': 'Tracing (opt-in via --caps=tracing)',
};
'config': 'Configuration',
'network': 'Network',
'storage': 'Storage',
'devtools': 'DevTools',
'vision': 'Coordinate-based',
'pdf': 'PDF generation',
'testing': 'Test assertions',
});
const knownCapabilities = new Set(Object.keys(capabilities));
const unknownCapabilities = [...new Set(browserTools.map(tool => tool.capability))].filter(cap => !knownCapabilities.has(cap));
if (unknownCapabilities.length)
throw new Error(`Unknown tool capabilities: ${unknownCapabilities.join(', ')}. Please update the capabilities map in ${path.basename(__filename)}.`);
/** @type {Record<string, any[]>} */
const toolsByCapability = {};
for (const [capability, title] of Object.entries(capabilities)) {
for (const capability of Object.keys(capabilities)) {
const title = capabilityTitle(capability);
let tools = browserTools.filter(tool => tool.capability === capability && !tool.skillOnly);
tools = (toolsByCapability[title] || []).concat(tools);
toolsByCapability[title] = tools;
@@ -44,6 +53,15 @@ for (const [capability, title] of Object.entries(capabilities)) {
for (const [, tools] of Object.entries(toolsByCapability))
tools.sort((a, b) => a.schema.name.localeCompare(b.schema.name));
/**
* @param {string} capability
* @returns {string}
*/
function capabilityTitle(capability) {
const title = capabilities[capability];
return capability.startsWith('core') ? title : `${title} (opt-in via --caps=${capability})`;
}
/**
* @param {any} tool
* @returns {string[]}

58
roll.js Normal file
View File

@@ -0,0 +1,58 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
function copyConfig() {
const src = path.join(__dirname, '..', 'playwright', 'packages', 'playwright', 'src', 'mcp', 'config.d.ts');
const dst = path.join(__dirname, 'packages', 'playwright-mcp', 'config.d.ts');
let content = fs.readFileSync(src, 'utf-8');
content = content.replace(
"import type * as playwright from 'playwright-core';",
"import type * as playwright from 'playwright';"
);
fs.writeFileSync(dst, content);
console.log(`Copied config.d.ts from ${src} to ${dst}`);
}
function updatePlaywrightVersion(version) {
const packagesDir = path.join(__dirname, 'packages');
const files = [path.join(__dirname, 'package.json')];
for (const entry of fs.readdirSync(packagesDir, { withFileTypes: true })) {
const pkgJson = path.join(packagesDir, entry.name, 'package.json');
if (fs.existsSync(pkgJson))
files.push(pkgJson);
}
for (const file of files) {
const json = JSON.parse(fs.readFileSync(file, 'utf-8'));
let updated = false;
for (const section of ['dependencies', 'devDependencies']) {
for (const pkg of ['@playwright/test', 'playwright', 'playwright-core']) {
if (json[section]?.[pkg]) {
json[section][pkg] = version;
updated = true;
}
}
}
if (updated) {
fs.writeFileSync(file, JSON.stringify(json, null, 2) + '\n');
console.log(`Updated ${file}`);
}
}
execSync('npm install', { cwd: __dirname, stdio: 'inherit' });
}
function doRoll(version) {
updatePlaywrightVersion(version);
copyConfig();
// update readme
execSync('npm run lint', { cwd: __dirname, stdio: 'inherit' });
}
let version = process.argv[2];
if (!version) {
version = execSync('npm info playwright@next version', { encoding: 'utf-8' }).trim();
console.log(`Using next playwright version: ${version}`);
}
doRoll(version);