@playwright/mcp 0.0.35 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -80,7 +80,7 @@ For more information, see the [Codex MCP documentation](https://github.com/opena
80
80
 
81
81
  #### Or install manually:
82
82
 
83
- Go to `Cursor Settings` -> `MCP` -> `Add new MCP Server`. Name to your liking, use `command` type with the command `npx @playwright/mcp`. You can also verify config or add command like arguments via clicking `Edit`.
83
+ Go to `Cursor Settings` -> `MCP` -> `Add new MCP Server`. Name to your liking, use `command` type with the command `npx @playwright/mcp@latest`. You can also verify config or add command like arguments via clicking `Edit`.
84
84
 
85
85
  </details>
86
86
 
@@ -705,5 +705,52 @@ http.createServer(async (req, res) => {
705
705
 
706
706
  </details>
707
707
 
708
+ <details>
709
+ <summary><b>Verify (opt-in via --caps=verify)</b></summary>
710
+
711
+ <!-- NOTE: This has been generated via update-readme.js -->
712
+
713
+ - **browser_verify_element_visible**
714
+ - Title: Verify element visible
715
+ - Description: Verify element is visible on the page
716
+ - Parameters:
717
+ - `role` (string): ROLE of the element. Can be found in the snapshot like this: `- {ROLE} "Accessible Name":`
718
+ - `accessibleName` (string): ACCESSIBLE_NAME of the element. Can be found in the snapshot like this: `- role "{ACCESSIBLE_NAME}"`
719
+ - Read-only: **true**
720
+
721
+ <!-- NOTE: This has been generated via update-readme.js -->
722
+
723
+ - **browser_verify_list_visible**
724
+ - Title: Verify list visible
725
+ - Description: Verify list is visible on the page
726
+ - Parameters:
727
+ - `element` (string): Human-readable list description
728
+ - `ref` (string): Exact target element reference that points to the list
729
+ - `items` (array): Items to verify
730
+ - Read-only: **true**
731
+
732
+ <!-- NOTE: This has been generated via update-readme.js -->
733
+
734
+ - **browser_verify_text_visible**
735
+ - Title: Verify text visible
736
+ - Description: Verify text is visible on the page. Prefer browser_verify_element_visible if possible.
737
+ - Parameters:
738
+ - `text` (string): TEXT to verify. Can be found in the snapshot like this: `- role "Accessible Name": {TEXT}` or like this: `- text: {TEXT}`
739
+ - Read-only: **true**
740
+
741
+ <!-- NOTE: This has been generated via update-readme.js -->
742
+
743
+ - **browser_verify_value**
744
+ - Title: Verify value
745
+ - Description: Verify element value
746
+ - Parameters:
747
+ - `type` (string): Type of the element
748
+ - `element` (string): Human-readable element description
749
+ - `ref` (string): Exact target element reference that points to the element
750
+ - `value` (string): Value to verify. For checkbox, use "true" or "false".
751
+ - Read-only: **true**
752
+
753
+ </details>
754
+
708
755
 
709
756
  <!--- End of tools generated section -->
package/config.d.ts CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  import type * as playwright from 'playwright';
18
18
 
19
- export type ToolCapability = 'core' | 'core-tabs' | 'core-install' | 'vision' | 'pdf';
19
+ export type ToolCapability = 'core' | 'core-tabs' | 'core-install' | 'vision' | 'pdf' | 'verify';
20
20
 
21
21
  export type Config = {
22
22
  /**
@@ -26,6 +26,7 @@ import { WebSocket, WebSocketServer } from 'ws';
26
26
  import { httpAddressToString } from '../mcp/http.js';
27
27
  import { logUnhandledError } from '../utils/log.js';
28
28
  import { ManualPromise } from '../mcp/manualPromise.js';
29
+ import * as protocol from './protocol.js';
29
30
  // @ts-ignore
30
31
  const { registry } = await import('playwright-core/lib/server/registry/index');
31
32
  const debugLogger = debug('pw:mcp:relay');
@@ -33,6 +34,7 @@ export class CDPRelayServer {
33
34
  _wsHost;
34
35
  _browserChannel;
35
36
  _userDataDir;
37
+ _executablePath;
36
38
  _cdpPath;
37
39
  _extensionPath;
38
40
  _wss;
@@ -41,10 +43,11 @@ export class CDPRelayServer {
41
43
  _connectedTabInfo;
42
44
  _nextSessionId = 1;
43
45
  _extensionConnectionPromise;
44
- constructor(server, browserChannel, userDataDir) {
46
+ constructor(server, browserChannel, userDataDir, executablePath) {
45
47
  this._wsHost = httpAddressToString(server.address()).replace(/^http/, 'ws');
46
48
  this._browserChannel = browserChannel;
47
49
  this._userDataDir = userDataDir;
50
+ this._executablePath = executablePath;
48
51
  const uuid = crypto.randomUUID();
49
52
  this._cdpPath = `/cdp/${uuid}`;
50
53
  this._extensionPath = `/extension/${uuid}`;
@@ -83,15 +86,19 @@ export class CDPRelayServer {
83
86
  version: clientInfo.version,
84
87
  };
85
88
  url.searchParams.set('client', JSON.stringify(client));
89
+ url.searchParams.set('protocolVersion', process.env.PWMCP_TEST_PROTOCOL_VERSION ?? protocol.VERSION.toString());
86
90
  if (toolName)
87
91
  url.searchParams.set('newTab', String(toolName === 'browser_navigate'));
88
92
  const href = url.toString();
89
- const executableInfo = registry.findExecutable(this._browserChannel);
90
- if (!executableInfo)
91
- throw new Error(`Unsupported channel: "${this._browserChannel}"`);
92
- const executablePath = executableInfo.executablePath();
93
- if (!executablePath)
94
- throw new Error(`"${this._browserChannel}" executable not found. Make sure it is installed at a standard location.`);
93
+ let executablePath = this._executablePath;
94
+ if (!executablePath) {
95
+ const executableInfo = registry.findExecutable(this._browserChannel);
96
+ if (!executableInfo)
97
+ throw new Error(`Unsupported channel: "${this._browserChannel}"`);
98
+ executablePath = executableInfo.executablePath();
99
+ if (!executablePath)
100
+ throw new Error(`"${this._browserChannel}" executable not found. Make sure it is installed at a standard location.`);
101
+ }
95
102
  const args = [];
96
103
  if (this._userDataDir)
97
104
  args.push(`--user-data-dir=${this._userDataDir}`);
@@ -195,10 +202,6 @@ export class CDPRelayServer {
195
202
  params: params.params
196
203
  });
197
204
  break;
198
- case 'detachedFromTab':
199
- debugLogger('← Debugger detached from tab:', params);
200
- this._connectedTabInfo = undefined;
201
- break;
202
205
  }
203
206
  }
204
207
  async _handlePlaywrightMessage(message) {
@@ -234,7 +237,7 @@ export class CDPRelayServer {
234
237
  if (sessionId)
235
238
  break;
236
239
  // Simulate auto-attach behavior with real target info
237
- const { targetInfo } = await this._extensionConnection.send('attachToTab');
240
+ const { targetInfo } = await this._extensionConnection.send('attachToTab', {});
238
241
  this._connectedTabInfo = {
239
242
  targetInfo,
240
243
  sessionId: `pw-tab-${this._nextSessionId++}`,
@@ -284,11 +287,11 @@ class ExtensionConnection {
284
287
  this._ws.on('close', this._onClose.bind(this));
285
288
  this._ws.on('error', this._onError.bind(this));
286
289
  }
287
- async send(method, params, sessionId) {
290
+ async send(method, params) {
288
291
  if (this._ws.readyState !== WebSocket.OPEN)
289
292
  throw new Error(`Unexpected WebSocket state: ${this._ws.readyState}`);
290
293
  const id = ++this._lastId;
291
- this._ws.send(JSON.stringify({ id, method, params, sessionId }));
294
+ this._ws.send(JSON.stringify({ id, method, params }));
292
295
  const error = new Error(`Protocol error: ${method}`);
293
296
  return new Promise((resolve, reject) => {
294
297
  this._callbacks.set(id, { resolve, reject, error });
@@ -21,9 +21,11 @@ const debugLogger = debug('pw:mcp:relay');
21
21
  export class ExtensionContextFactory {
22
22
  _browserChannel;
23
23
  _userDataDir;
24
- constructor(browserChannel, userDataDir) {
24
+ _executablePath;
25
+ constructor(browserChannel, userDataDir, executablePath) {
25
26
  this._browserChannel = browserChannel;
26
27
  this._userDataDir = userDataDir;
28
+ this._executablePath = executablePath;
27
29
  }
28
30
  async createContext(clientInfo, abortSignal, toolName) {
29
31
  const browser = await this._obtainBrowser(clientInfo, abortSignal, toolName);
@@ -46,7 +48,7 @@ export class ExtensionContextFactory {
46
48
  httpServer.close();
47
49
  throw new Error(abortSignal.reason);
48
50
  }
49
- const cdpRelayServer = new CDPRelayServer(httpServer, this._browserChannel, this._userDataDir);
51
+ const cdpRelayServer = new CDPRelayServer(httpServer, this._browserChannel, this._userDataDir, this._executablePath);
50
52
  abortSignal.addEventListener('abort', () => cdpRelayServer.stop());
51
53
  debugLogger(`CDP relay server started, extension endpoint: ${cdpRelayServer.extensionEndpoint()}.`);
52
54
  return cdpRelayServer;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ // Whenever the commands/events change, the version must be updated. The latest
17
+ // extension version should be compatible with the old MCP clients.
18
+ export const VERSION = 1;
package/lib/program.js CHANGED
@@ -66,7 +66,7 @@ program
66
66
  }
67
67
  const config = await resolveCLIConfig(options);
68
68
  const browserContextFactory = contextFactory(config);
69
- const extensionContextFactory = new ExtensionContextFactory(config.browser.launchOptions.channel || 'chrome', config.browser.userDataDir);
69
+ const extensionContextFactory = new ExtensionContextFactory(config.browser.launchOptions.channel || 'chrome', config.browser.userDataDir, config.browser.launchOptions.executablePath);
70
70
  if (options.extension) {
71
71
  const serverBackendFactory = {
72
72
  name: 'Playwright w/ extension',
package/lib/tools/tabs.js CHANGED
@@ -45,7 +45,7 @@ const browserTabs = defineTool({
45
45
  return;
46
46
  }
47
47
  case 'select': {
48
- if (!params.index)
48
+ if (params.index === undefined)
49
49
  throw new Error('Tab index is required');
50
50
  await context.selectTab(params.index);
51
51
  response.setIncludeSnapshot();
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { z } from 'zod';
17
+ import { defineTabTool } from './tool.js';
18
+ import * as javascript from '../utils/codegen.js';
19
+ import { generateLocator } from './utils.js';
20
+ const verifyElement = defineTabTool({
21
+ capability: 'verify',
22
+ schema: {
23
+ name: 'browser_verify_element_visible',
24
+ title: 'Verify element visible',
25
+ description: 'Verify element is visible on the page',
26
+ inputSchema: z.object({
27
+ role: z.string().describe('ROLE of the element. Can be found in the snapshot like this: \`- {ROLE} "Accessible Name":\`'),
28
+ accessibleName: z.string().describe('ACCESSIBLE_NAME of the element. Can be found in the snapshot like this: \`- role "{ACCESSIBLE_NAME}"\`'),
29
+ }),
30
+ type: 'readOnly',
31
+ },
32
+ handle: async (tab, params, response) => {
33
+ const locator = tab.page.getByRole(params.role, { name: params.accessibleName });
34
+ if (await locator.count() === 0) {
35
+ response.addError(`Element with role "${params.role}" and accessible name "${params.accessibleName}" not found`);
36
+ return;
37
+ }
38
+ response.addCode(`await expect(page.getByRole(${javascript.escapeWithQuotes(params.role)}, { name: ${javascript.escapeWithQuotes(params.accessibleName)} })).toBeVisible();`);
39
+ response.addResult('Done');
40
+ },
41
+ });
42
+ const verifyText = defineTabTool({
43
+ capability: 'verify',
44
+ schema: {
45
+ name: 'browser_verify_text_visible',
46
+ title: 'Verify text visible',
47
+ description: `Verify text is visible on the page. Prefer ${verifyElement.schema.name} if possible.`,
48
+ inputSchema: z.object({
49
+ text: z.string().describe('TEXT to verify. Can be found in the snapshot like this: \`- role "Accessible Name": {TEXT}\` or like this: \`- text: {TEXT}\`'),
50
+ }),
51
+ type: 'readOnly',
52
+ },
53
+ handle: async (tab, params, response) => {
54
+ const locator = tab.page.getByText(params.text).filter({ visible: true });
55
+ if (await locator.count() === 0) {
56
+ response.addError('Text not found');
57
+ return;
58
+ }
59
+ response.addCode(`await expect(page.getByText(${javascript.escapeWithQuotes(params.text)})).toBeVisible();`);
60
+ response.addResult('Done');
61
+ },
62
+ });
63
+ const verifyList = defineTabTool({
64
+ capability: 'verify',
65
+ schema: {
66
+ name: 'browser_verify_list_visible',
67
+ title: 'Verify list visible',
68
+ description: 'Verify list is visible on the page',
69
+ inputSchema: z.object({
70
+ element: z.string().describe('Human-readable list description'),
71
+ ref: z.string().describe('Exact target element reference that points to the list'),
72
+ items: z.array(z.string()).describe('Items to verify'),
73
+ }),
74
+ type: 'readOnly',
75
+ },
76
+ handle: async (tab, params, response) => {
77
+ const locator = await tab.refLocator({ ref: params.ref, element: params.element });
78
+ const itemTexts = [];
79
+ for (const item of params.items) {
80
+ const itemLocator = locator.getByText(item);
81
+ if (await itemLocator.count() === 0) {
82
+ response.addError(`Item "${item}" not found`);
83
+ return;
84
+ }
85
+ itemTexts.push((await itemLocator.textContent()));
86
+ }
87
+ const ariaSnapshot = `\`
88
+ - list:
89
+ ${itemTexts.map(t => ` - listitem: ${javascript.escapeWithQuotes(t, '"')}`).join('\n')}
90
+ \``;
91
+ response.addCode(`await expect(page.locator('body')).toMatchAriaSnapshot(${ariaSnapshot});`);
92
+ response.addResult('Done');
93
+ },
94
+ });
95
+ const verifyValue = defineTabTool({
96
+ capability: 'verify',
97
+ schema: {
98
+ name: 'browser_verify_value',
99
+ title: 'Verify value',
100
+ description: 'Verify element value',
101
+ inputSchema: z.object({
102
+ type: z.enum(['textbox', 'checkbox', 'radio', 'combobox', 'slider']).describe('Type of the element'),
103
+ element: z.string().describe('Human-readable element description'),
104
+ ref: z.string().describe('Exact target element reference that points to the element'),
105
+ value: z.string().describe('Value to verify. For checkbox, use "true" or "false".'),
106
+ }),
107
+ type: 'readOnly',
108
+ },
109
+ handle: async (tab, params, response) => {
110
+ const locator = await tab.refLocator({ ref: params.ref, element: params.element });
111
+ const locatorSource = `page.${await generateLocator(locator)}`;
112
+ if (params.type === 'textbox' || params.type === 'slider' || params.type === 'combobox') {
113
+ const value = await locator.inputValue();
114
+ if (value !== params.value) {
115
+ response.addError(`Expected value "${params.value}", but got "${value}"`);
116
+ return;
117
+ }
118
+ response.addCode(`await expect(${locatorSource}).toHaveValue(${javascript.quote(params.value)});`);
119
+ }
120
+ else if (params.type === 'checkbox' || params.type === 'radio') {
121
+ const value = await locator.isChecked();
122
+ if (value !== (params.value === 'true')) {
123
+ response.addError(`Expected value "${params.value}", but got "${value}"`);
124
+ return;
125
+ }
126
+ const matcher = value ? 'toBeChecked' : 'not.toBeChecked';
127
+ response.addCode(`await expect(${locatorSource}).${matcher}();`);
128
+ }
129
+ response.addResult('Done');
130
+ },
131
+ });
132
+ export default [
133
+ verifyElement,
134
+ verifyText,
135
+ verifyList,
136
+ verifyValue,
137
+ ];
package/lib/tools.js CHANGED
@@ -21,6 +21,7 @@ import files from './tools/files.js';
21
21
  import form from './tools/form.js';
22
22
  import install from './tools/install.js';
23
23
  import keyboard from './tools/keyboard.js';
24
+ import mouse from './tools/mouse.js';
24
25
  import navigate from './tools/navigate.js';
25
26
  import network from './tools/network.js';
26
27
  import pdf from './tools/pdf.js';
@@ -28,7 +29,7 @@ import snapshot from './tools/snapshot.js';
28
29
  import tabs from './tools/tabs.js';
29
30
  import screenshot from './tools/screenshot.js';
30
31
  import wait from './tools/wait.js';
31
- import mouse from './tools/mouse.js';
32
+ import verify from './tools/verify.js';
32
33
  export const allTools = [
33
34
  ...common,
34
35
  ...console,
@@ -46,6 +47,7 @@ export const allTools = [
46
47
  ...snapshot,
47
48
  ...tabs,
48
49
  ...wait,
50
+ ...verify,
49
51
  ];
50
52
  export function filteredTools(config) {
51
53
  return allTools.filter(tool => tool.capability.startsWith('core') || config.capabilities?.includes(tool.capability));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playwright/mcp",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "description": "Playwright Tools for MCP",
5
5
  "type": "module",
6
6
  "repository": {
@@ -43,8 +43,8 @@
43
43
  "debug": "^4.4.1",
44
44
  "dotenv": "^17.2.0",
45
45
  "mime": "^4.0.7",
46
- "playwright": "1.55.0-alpha-2025-08-12",
47
- "playwright-core": "1.55.0-alpha-2025-08-12",
46
+ "playwright": "1.56.0-alpha-1756505518000",
47
+ "playwright-core": "1.56.0-alpha-1756505518000",
48
48
  "ws": "^8.18.1",
49
49
  "zod": "^3.24.1",
50
50
  "zod-to-json-schema": "^3.24.4"
@@ -53,7 +53,7 @@
53
53
  "@anthropic-ai/sdk": "^0.57.0",
54
54
  "@eslint/eslintrc": "^3.2.0",
55
55
  "@eslint/js": "^9.19.0",
56
- "@playwright/test": "1.55.0-alpha-2025-08-12",
56
+ "@playwright/test": "1.56.0-alpha-1756505518000",
57
57
  "@stylistic/eslint-plugin": "^3.0.1",
58
58
  "@types/debug": "^4.1.12",
59
59
  "@types/node": "^22.13.10",