@playwright/mcp 0.0.32 → 0.0.34
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 +33 -3
- package/lib/browserContextFactory.js +78 -60
- package/lib/browserServerBackend.js +47 -21
- package/lib/config.js +8 -8
- package/lib/context.js +76 -28
- package/lib/extension/cdpRelay.js +29 -50
- package/lib/extension/extensionContextFactory.js +56 -0
- package/lib/index.js +3 -1
- package/lib/loopTools/context.js +1 -1
- package/lib/loopTools/main.js +7 -5
- package/lib/mcp/proxyBackend.js +106 -0
- package/lib/mcp/server.js +32 -24
- package/lib/mcp/tool.js +29 -0
- package/lib/mcp/transport.js +1 -1
- package/lib/program.js +30 -21
- package/lib/response.js +81 -14
- package/lib/sessionLog.js +85 -34
- package/lib/tab.js +55 -52
- package/lib/tools/common.js +0 -1
- package/lib/tools/evaluate.js +1 -1
- package/lib/tools/files.js +0 -1
- package/lib/tools/keyboard.js +1 -3
- package/lib/tools/navigate.js +0 -3
- package/lib/tools/pdf.js +2 -4
- package/lib/tools/screenshot.js +13 -10
- package/lib/tools/snapshot.js +3 -8
- package/lib/tools/tool.js +5 -4
- package/lib/tools/utils.js +0 -7
- package/lib/tools/wait.js +3 -4
- package/lib/{javascript.js → utils/codegen.js} +1 -1
- package/lib/{fileUtils.js → utils/fileUtils.js} +6 -2
- package/lib/utils/guid.js +22 -0
- package/lib/{package.js → utils/package.js} +1 -1
- package/package.json +9 -9
- package/lib/extension/main.js +0 -33
- /package/lib/{httpServer.js → utils/httpServer.js} +0 -0
- /package/lib/{log.js → utils/log.js} +0 -0
- /package/lib/{manualPromise.js → utils/manualPromise.js} +0 -0
package/lib/tools/wait.js
CHANGED
|
@@ -31,20 +31,19 @@ const wait = defineTool({
|
|
|
31
31
|
handle: async (context, params, response) => {
|
|
32
32
|
if (!params.text && !params.textGone && !params.time)
|
|
33
33
|
throw new Error('Either time, text or textGone must be provided');
|
|
34
|
-
const code = [];
|
|
35
34
|
if (params.time) {
|
|
36
|
-
|
|
35
|
+
response.addCode(`await new Promise(f => setTimeout(f, ${params.time} * 1000));`);
|
|
37
36
|
await new Promise(f => setTimeout(f, Math.min(30000, params.time * 1000)));
|
|
38
37
|
}
|
|
39
38
|
const tab = context.currentTabOrDie();
|
|
40
39
|
const locator = params.text ? tab.page.getByText(params.text).first() : undefined;
|
|
41
40
|
const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : undefined;
|
|
42
41
|
if (goneLocator) {
|
|
43
|
-
|
|
42
|
+
response.addCode(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
|
|
44
43
|
await goneLocator.waitFor({ state: 'hidden' });
|
|
45
44
|
}
|
|
46
45
|
if (locator) {
|
|
47
|
-
|
|
46
|
+
response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
|
|
48
47
|
await locator.waitFor({ state: 'visible' });
|
|
49
48
|
}
|
|
50
49
|
response.addResult(`Waited for ${params.text || params.textGone || params.time}`);
|
|
@@ -25,7 +25,7 @@ export function escapeWithQuotes(text, char = '\'') {
|
|
|
25
25
|
if (char === '"')
|
|
26
26
|
return char + escapedText.replace(/["]/g, '\\"') + char;
|
|
27
27
|
if (char === '`')
|
|
28
|
-
return char + escapedText.replace(/[`]/g, '
|
|
28
|
+
return char + escapedText.replace(/[`]/g, '\\`') + char;
|
|
29
29
|
throw new Error('Invalid escape char');
|
|
30
30
|
}
|
|
31
31
|
export function quote(text) {
|
|
@@ -27,6 +27,10 @@ export function cacheDir() {
|
|
|
27
27
|
throw new Error('Unsupported platform: ' + process.platform);
|
|
28
28
|
return path.join(cacheDirectory, 'ms-playwright');
|
|
29
29
|
}
|
|
30
|
-
export
|
|
31
|
-
|
|
30
|
+
export function sanitizeForFilePath(s) {
|
|
31
|
+
const sanitize = (s) => s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-');
|
|
32
|
+
const separator = s.lastIndexOf('.');
|
|
33
|
+
if (separator === -1)
|
|
34
|
+
return sanitize(s);
|
|
35
|
+
return sanitize(s.substring(0, separator)) + '.' + sanitize(s.substring(separator + 1));
|
|
32
36
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 crypto from 'crypto';
|
|
17
|
+
export function createGuid() {
|
|
18
|
+
return crypto.randomBytes(16).toString('hex');
|
|
19
|
+
}
|
|
20
|
+
export function createHash(data) {
|
|
21
|
+
return crypto.createHash('sha256').update(data).digest('hex').slice(0, 7);
|
|
22
|
+
}
|
|
@@ -17,4 +17,4 @@ import fs from 'fs';
|
|
|
17
17
|
import path from 'path';
|
|
18
18
|
import url from 'url';
|
|
19
19
|
const __filename = url.fileURLToPath(import.meta.url);
|
|
20
|
-
export const packageJSON = JSON.parse(fs.readFileSync(path.join(path.dirname(__filename), '..', 'package.json'), 'utf8'));
|
|
20
|
+
export const packageJSON = JSON.parse(fs.readFileSync(path.join(path.dirname(__filename), '..', '..', 'package.json'), 'utf8'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playwright/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "Playwright Tools for MCP",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -17,18 +17,17 @@
|
|
|
17
17
|
"license": "Apache-2.0",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsc",
|
|
20
|
-
"
|
|
21
|
-
"lint": "npm run update-readme && eslint . && tsc --noEmit",
|
|
20
|
+
"lint": "npm run update-readme && npm run check-deps && eslint . && tsc --noEmit",
|
|
22
21
|
"lint-fix": "eslint . --fix",
|
|
22
|
+
"check-deps": "node utils/check-deps.js",
|
|
23
23
|
"update-readme": "node utils/update-readme.js",
|
|
24
24
|
"watch": "tsc --watch",
|
|
25
|
-
"watch:extension": "tsc --watch --project extension",
|
|
26
25
|
"test": "playwright test",
|
|
27
26
|
"ctest": "playwright test --project=chrome",
|
|
28
27
|
"ftest": "playwright test --project=firefox",
|
|
29
28
|
"wtest": "playwright test --project=webkit",
|
|
30
29
|
"run-server": "node lib/browserServer.js",
|
|
31
|
-
"clean": "rm -rf lib
|
|
30
|
+
"clean": "rm -rf lib",
|
|
32
31
|
"npm-publish": "npm run clean && npm run build && npm run test && npm publish"
|
|
33
32
|
},
|
|
34
33
|
"exports": {
|
|
@@ -44,24 +43,25 @@
|
|
|
44
43
|
"debug": "^4.4.1",
|
|
45
44
|
"dotenv": "^17.2.0",
|
|
46
45
|
"mime": "^4.0.7",
|
|
47
|
-
"playwright": "1.55.0-alpha-
|
|
48
|
-
"playwright-core": "1.55.0-alpha-
|
|
46
|
+
"playwright": "1.55.0-alpha-2025-08-12",
|
|
47
|
+
"playwright-core": "1.55.0-alpha-2025-08-12",
|
|
49
48
|
"ws": "^8.18.1",
|
|
49
|
+
"zod": "^3.24.1",
|
|
50
50
|
"zod-to-json-schema": "^3.24.4"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
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-
|
|
56
|
+
"@playwright/test": "1.55.0-alpha-2025-08-12",
|
|
57
57
|
"@stylistic/eslint-plugin": "^3.0.1",
|
|
58
|
-
"@types/chrome": "^0.0.315",
|
|
59
58
|
"@types/debug": "^4.1.12",
|
|
60
59
|
"@types/node": "^22.13.10",
|
|
61
60
|
"@types/ws": "^8.18.1",
|
|
62
61
|
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
|
63
62
|
"@typescript-eslint/parser": "^8.26.1",
|
|
64
63
|
"@typescript-eslint/utils": "^8.26.1",
|
|
64
|
+
"esbuild": "^0.20.1",
|
|
65
65
|
"eslint": "^9.19.0",
|
|
66
66
|
"eslint-plugin-import": "^2.31.0",
|
|
67
67
|
"eslint-plugin-notice": "^1.0.0",
|
package/lib/extension/main.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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 { startCDPRelayServer } from './cdpRelay.js';
|
|
17
|
-
import { BrowserServerBackend } from '../browserServerBackend.js';
|
|
18
|
-
import * as mcpTransport from '../mcp/transport.js';
|
|
19
|
-
export async function runWithExtension(config, abortController) {
|
|
20
|
-
const contextFactory = await startCDPRelayServer(config.browser.launchOptions.channel || 'chrome', abortController);
|
|
21
|
-
let backend;
|
|
22
|
-
const serverBackendFactory = () => {
|
|
23
|
-
if (backend)
|
|
24
|
-
throw new Error('Another MCP client is still connected. Only one connection at a time is allowed.');
|
|
25
|
-
backend = new BrowserServerBackend(config, contextFactory);
|
|
26
|
-
backend.onclose = () => {
|
|
27
|
-
contextFactory.clientDisconnected();
|
|
28
|
-
backend = undefined;
|
|
29
|
-
};
|
|
30
|
-
return backend;
|
|
31
|
-
};
|
|
32
|
-
await mcpTransport.start(serverBackendFactory, config.server);
|
|
33
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|