@playwright/mcp 0.0.36-alpha-2025-09-04 → 0.0.37-alpha-2025-09-08
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 +81 -46
- package/cli.js +7 -1
- package/config.d.ts +24 -0
- package/index.js +1 -1
- package/package.json +14 -39
- package/lib/browser/browserContextFactory.js +0 -251
- package/lib/browser/browserServerBackend.js +0 -79
- package/lib/browser/codegen.js +0 -54
- package/lib/browser/config.js +0 -263
- package/lib/browser/context.js +0 -223
- package/lib/browser/response.js +0 -165
- package/lib/browser/sessionLog.js +0 -126
- package/lib/browser/tab.js +0 -251
- package/lib/browser/tools/common.js +0 -57
- package/lib/browser/tools/console.js +0 -35
- package/lib/browser/tools/dialogs.js +0 -49
- package/lib/browser/tools/evaluate.js +0 -88
- package/lib/browser/tools/files.js +0 -46
- package/lib/browser/tools/form.js +0 -92
- package/lib/browser/tools/install.js +0 -57
- package/lib/browser/tools/keyboard.js +0 -113
- package/lib/browser/tools/mouse.js +0 -101
- package/lib/browser/tools/navigate.js +0 -56
- package/lib/browser/tools/network.js +0 -43
- package/lib/browser/tools/pdf.js +0 -76
- package/lib/browser/tools/screenshot.js +0 -115
- package/lib/browser/tools/snapshot.js +0 -175
- package/lib/browser/tools/tabs.js +0 -61
- package/lib/browser/tools/tool.js +0 -37
- package/lib/browser/tools/utils.js +0 -79
- package/lib/browser/tools/verify.js +0 -172
- package/lib/browser/tools/wait.js +0 -57
- package/lib/browser/tools.js +0 -61
- package/lib/extension/cdpRelay.js +0 -395
- package/lib/extension/extensionContextFactory.js +0 -93
- package/lib/extension/protocol.js +0 -21
- package/lib/index.js +0 -75
- package/lib/log.js +0 -28
- package/lib/package.js +0 -24
- package/lib/program.js +0 -161
- package/lib/sdk/bundle.js +0 -79
- package/lib/sdk/http.js +0 -175
- package/lib/sdk/inProcessTransport.js +0 -67
- package/lib/sdk/manualPromise.js +0 -113
- package/lib/sdk/mdb.js +0 -237
- package/lib/sdk/proxyBackend.js +0 -141
- package/lib/sdk/server.js +0 -164
- package/lib/sdk/tool.js +0 -36
- package/lib/vscode/host.js +0 -199
- package/lib/vscode/main.js +0 -97
package/lib/vscode/host.js
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
-
var ownKeys = function(o) {
|
|
35
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
-
var ar = [];
|
|
37
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
return ownKeys(o);
|
|
41
|
-
};
|
|
42
|
-
return function (mod) {
|
|
43
|
-
if (mod && mod.__esModule) return mod;
|
|
44
|
-
var result = {};
|
|
45
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
-
__setModuleDefault(result, mod);
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
})();
|
|
50
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
51
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.runVSCodeTools = runVSCodeTools;
|
|
55
|
-
const path_1 = __importDefault(require("path"));
|
|
56
|
-
const mcpBundle = __importStar(require("../sdk/bundle"));
|
|
57
|
-
const mcpServer = __importStar(require("../sdk/server"));
|
|
58
|
-
const log_1 = require("../log");
|
|
59
|
-
const package_1 = require("../package");
|
|
60
|
-
const browserServerBackend_1 = require("../browser/browserServerBackend");
|
|
61
|
-
const browserContextFactory_1 = require("../browser/browserContextFactory");
|
|
62
|
-
const { z, zodToJsonSchema } = mcpBundle;
|
|
63
|
-
const contextSwitchOptions = z.object({
|
|
64
|
-
connectionString: z.string().optional().describe('The connection string to use to connect to the browser'),
|
|
65
|
-
lib: z.string().optional().describe('The library to use for the connection'),
|
|
66
|
-
debugController: z.boolean().optional().describe('Enable the debug controller')
|
|
67
|
-
});
|
|
68
|
-
class VSCodeProxyBackend {
|
|
69
|
-
constructor(_config, _defaultTransportFactory) {
|
|
70
|
-
this._config = _config;
|
|
71
|
-
this._defaultTransportFactory = _defaultTransportFactory;
|
|
72
|
-
this.name = 'Playwright MCP Client Switcher';
|
|
73
|
-
this.version = package_1.packageJSON.version;
|
|
74
|
-
this._roots = [];
|
|
75
|
-
this._contextSwitchTool = this._defineContextSwitchTool();
|
|
76
|
-
}
|
|
77
|
-
async initialize(server, clientVersion, roots) {
|
|
78
|
-
this._clientVersion = clientVersion;
|
|
79
|
-
this._roots = roots;
|
|
80
|
-
const transport = await this._defaultTransportFactory(this);
|
|
81
|
-
await this._setCurrentClient(transport);
|
|
82
|
-
}
|
|
83
|
-
async listTools() {
|
|
84
|
-
const response = await this._currentClient.listTools();
|
|
85
|
-
return [
|
|
86
|
-
...response.tools,
|
|
87
|
-
this._contextSwitchTool,
|
|
88
|
-
];
|
|
89
|
-
}
|
|
90
|
-
async callTool(name, args) {
|
|
91
|
-
if (name === this._contextSwitchTool.name)
|
|
92
|
-
return this._callContextSwitchTool(args);
|
|
93
|
-
return await this._currentClient.callTool({
|
|
94
|
-
name,
|
|
95
|
-
arguments: args,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
serverClosed(server) {
|
|
99
|
-
var _a;
|
|
100
|
-
void ((_a = this._currentClient) === null || _a === void 0 ? void 0 : _a.close().catch(log_1.logUnhandledError));
|
|
101
|
-
}
|
|
102
|
-
onContext(context) {
|
|
103
|
-
this._context = context;
|
|
104
|
-
context.on('close', () => {
|
|
105
|
-
this._context = undefined;
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
async _getDebugControllerURL() {
|
|
109
|
-
if (!this._context)
|
|
110
|
-
return;
|
|
111
|
-
const browser = this._context.browser();
|
|
112
|
-
if (!browser || !browser._launchServer)
|
|
113
|
-
return;
|
|
114
|
-
if (this._browser !== browser)
|
|
115
|
-
this._browserServer = undefined;
|
|
116
|
-
if (!this._browserServer)
|
|
117
|
-
this._browserServer = await browser._launchServer({ _debugController: true });
|
|
118
|
-
const url = new URL(this._browserServer.wsEndpoint());
|
|
119
|
-
url.searchParams.set('debug-controller', '1');
|
|
120
|
-
return url.toString();
|
|
121
|
-
}
|
|
122
|
-
async _callContextSwitchTool(params) {
|
|
123
|
-
if (params.debugController) {
|
|
124
|
-
const url = await this._getDebugControllerURL();
|
|
125
|
-
const lines = [`### Result`];
|
|
126
|
-
if (url) {
|
|
127
|
-
lines.push(`URL: ${url}`);
|
|
128
|
-
lines.push(`Version: ${package_1.packageJSON.dependencies.playwright}`);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
lines.push(`No open browsers.`);
|
|
132
|
-
}
|
|
133
|
-
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
134
|
-
}
|
|
135
|
-
if (!params.connectionString || !params.lib) {
|
|
136
|
-
const transport = await this._defaultTransportFactory(this);
|
|
137
|
-
await this._setCurrentClient(transport);
|
|
138
|
-
return {
|
|
139
|
-
content: [{ type: 'text', text: '### Result\nSuccessfully disconnected.\n' }],
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
await this._setCurrentClient(new mcpBundle.StdioClientTransport({
|
|
143
|
-
command: process.execPath,
|
|
144
|
-
cwd: process.cwd(),
|
|
145
|
-
args: [
|
|
146
|
-
path_1.default.join(__dirname, 'main.js'),
|
|
147
|
-
JSON.stringify(this._config),
|
|
148
|
-
params.connectionString,
|
|
149
|
-
params.lib,
|
|
150
|
-
],
|
|
151
|
-
}));
|
|
152
|
-
return {
|
|
153
|
-
content: [{ type: 'text', text: '### Result\nSuccessfully connected.\n' }],
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
_defineContextSwitchTool() {
|
|
157
|
-
return {
|
|
158
|
-
name: 'browser_connect',
|
|
159
|
-
description: 'Do not call, this tool is used in the integration with the Playwright VS Code Extension and meant for programmatic usage only.',
|
|
160
|
-
inputSchema: zodToJsonSchema(contextSwitchOptions, { strictUnions: true }),
|
|
161
|
-
annotations: {
|
|
162
|
-
title: 'Connect to a browser running in VS Code.',
|
|
163
|
-
readOnlyHint: true,
|
|
164
|
-
openWorldHint: false,
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
async _setCurrentClient(transport) {
|
|
169
|
-
var _a;
|
|
170
|
-
await ((_a = this._currentClient) === null || _a === void 0 ? void 0 : _a.close());
|
|
171
|
-
this._currentClient = undefined;
|
|
172
|
-
const client = new mcpBundle.Client(this._clientVersion);
|
|
173
|
-
client.registerCapabilities({
|
|
174
|
-
roots: {
|
|
175
|
-
listRoots: true,
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
client.setRequestHandler(mcpBundle.ListRootsRequestSchema, () => ({ roots: this._roots }));
|
|
179
|
-
client.setRequestHandler(mcpBundle.PingRequestSchema, () => ({}));
|
|
180
|
-
await client.connect(transport);
|
|
181
|
-
this._currentClient = client;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
async function runVSCodeTools(config) {
|
|
185
|
-
const serverBackendFactory = {
|
|
186
|
-
name: 'Playwright w/ vscode',
|
|
187
|
-
nameInConfig: 'playwright-vscode',
|
|
188
|
-
version: package_1.packageJSON.version,
|
|
189
|
-
create: () => new VSCodeProxyBackend(config, delegate => mcpServer.wrapInProcess(new browserServerBackend_1.BrowserServerBackend(config, {
|
|
190
|
-
async createContext(clientInfo, abortSignal, toolName) {
|
|
191
|
-
const context = await (0, browserContextFactory_1.contextFactory)(config).createContext(clientInfo, abortSignal, toolName);
|
|
192
|
-
delegate.onContext(context.browserContext);
|
|
193
|
-
return context;
|
|
194
|
-
},
|
|
195
|
-
})))
|
|
196
|
-
};
|
|
197
|
-
await mcpServer.start(serverBackendFactory, config.server);
|
|
198
|
-
return;
|
|
199
|
-
}
|
package/lib/vscode/main.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
-
var ownKeys = function(o) {
|
|
35
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
-
var ar = [];
|
|
37
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
return ownKeys(o);
|
|
41
|
-
};
|
|
42
|
-
return function (mod) {
|
|
43
|
-
if (mod && mod.__esModule) return mod;
|
|
44
|
-
var result = {};
|
|
45
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
-
__setModuleDefault(result, mod);
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
})();
|
|
50
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
const mcpBundle = __importStar(require("../sdk/bundle"));
|
|
52
|
-
const mcpServer = __importStar(require("../sdk/server"));
|
|
53
|
-
const browserServerBackend_1 = require("../browser/browserServerBackend");
|
|
54
|
-
class VSCodeBrowserContextFactory {
|
|
55
|
-
constructor(_config, _playwright, _connectionString) {
|
|
56
|
-
this._config = _config;
|
|
57
|
-
this._playwright = _playwright;
|
|
58
|
-
this._connectionString = _connectionString;
|
|
59
|
-
this.name = 'vscode';
|
|
60
|
-
this.description = 'Connect to a browser running in the Playwright VS Code extension';
|
|
61
|
-
}
|
|
62
|
-
async createContext(clientInfo, abortSignal) {
|
|
63
|
-
var _a;
|
|
64
|
-
let launchOptions = this._config.browser.launchOptions;
|
|
65
|
-
if (this._config.browser.userDataDir) {
|
|
66
|
-
launchOptions = {
|
|
67
|
-
...launchOptions,
|
|
68
|
-
...this._config.browser.contextOptions,
|
|
69
|
-
userDataDir: this._config.browser.userDataDir,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const connectionString = new URL(this._connectionString);
|
|
73
|
-
connectionString.searchParams.set('launch-options', JSON.stringify(launchOptions));
|
|
74
|
-
const browserType = this._playwright.chromium; // it could also be firefox or webkit, we just need some browser type to call `connect` on
|
|
75
|
-
const browser = await browserType.connect(connectionString.toString());
|
|
76
|
-
const context = (_a = browser.contexts()[0]) !== null && _a !== void 0 ? _a : await browser.newContext(this._config.browser.contextOptions);
|
|
77
|
-
return {
|
|
78
|
-
browserContext: context,
|
|
79
|
-
close: async () => {
|
|
80
|
-
await browser.close();
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async function main(config, connectionString, lib) {
|
|
86
|
-
const playwright = await Promise.resolve(`${lib}`).then(s => __importStar(require(s))).then(mod => { var _a; return (_a = mod.default) !== null && _a !== void 0 ? _a : mod; });
|
|
87
|
-
const factory = new VSCodeBrowserContextFactory(config, playwright, connectionString);
|
|
88
|
-
await mcpServer.connect({
|
|
89
|
-
name: 'Playwright MCP',
|
|
90
|
-
nameInConfig: 'playwright-vscode',
|
|
91
|
-
create: () => new browserServerBackend_1.BrowserServerBackend(config, factory),
|
|
92
|
-
version: 'unused'
|
|
93
|
-
}, new mcpBundle.StdioServerTransport(), false);
|
|
94
|
-
}
|
|
95
|
-
void (async () => {
|
|
96
|
-
await main(JSON.parse(process.argv[2]), process.argv[3], process.argv[4]);
|
|
97
|
-
})();
|