@playwright/mcp 0.0.36-alpha-2025-09-02 → 0.0.36-alpha-2025-09-04
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 +1 -1
- package/cli.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/lib/{browserContextFactory.js → browser/browserContextFactory.js} +76 -36
- package/lib/{browserServerBackend.js → browser/browserServerBackend.js} +24 -22
- package/lib/{utils → browser}/codegen.js +8 -3
- package/lib/{config.js → browser/config.js} +43 -26
- package/lib/{context.js → browser/context.js} +27 -30
- package/lib/{response.js → browser/response.js} +14 -14
- package/lib/{sessionLog.js → browser/sessionLog.js} +23 -18
- package/lib/{tab.js → browser/tab.js} +29 -27
- package/lib/{tools → browser/tools}/common.js +11 -9
- package/lib/{tools → browser/tools}/console.js +7 -5
- package/lib/{tools → browser/tools}/dialogs.js +9 -7
- package/lib/browser/tools/evaluate.js +88 -0
- package/lib/{tools → browser/tools}/files.js +8 -6
- package/lib/browser/tools/form.js +92 -0
- package/lib/{tools → browser/tools}/install.js +18 -14
- package/lib/browser/tools/keyboard.js +113 -0
- package/lib/{tools → browser/tools}/mouse.js +18 -16
- package/lib/{tools → browser/tools}/navigate.js +10 -8
- package/lib/{tools → browser/tools}/network.js +7 -5
- package/lib/browser/tools/pdf.js +76 -0
- package/lib/browser/tools/screenshot.js +115 -0
- package/lib/browser/tools/snapshot.js +175 -0
- package/lib/{tools → browser/tools}/tabs.js +9 -7
- package/lib/{tools → browser/tools}/tool.js +6 -2
- package/lib/{tools → browser/tools}/utils.js +10 -5
- package/lib/{tools → browser/tools}/verify.js +59 -24
- package/lib/{tools → browser/tools}/wait.js +10 -8
- package/lib/browser/tools.js +61 -0
- package/lib/extension/cdpRelay.js +85 -48
- package/lib/extension/extensionContextFactory.js +48 -11
- package/lib/extension/protocol.js +4 -1
- package/lib/index.js +47 -12
- package/lib/{utils/log.js → log.js} +11 -4
- package/lib/{utils/package.js → package.js} +9 -5
- package/lib/program.js +68 -39
- package/lib/sdk/bundle.js +79 -0
- package/lib/{mcp → sdk}/http.js +57 -17
- package/lib/{mcp → sdk}/inProcessTransport.js +15 -20
- package/lib/{mcp → sdk}/manualPromise.js +11 -9
- package/lib/{mcp → sdk}/mdb.js +77 -38
- package/lib/{mcp → sdk}/proxyBackend.js +53 -16
- package/lib/sdk/server.js +164 -0
- package/lib/{mcp → sdk}/tool.js +8 -4
- package/lib/vscode/host.js +64 -35
- package/lib/vscode/main.js +48 -13
- package/package.json +6 -7
- package/lib/loop/loop.js +0 -69
- package/lib/loop/loopClaude.js +0 -152
- package/lib/loop/loopOpenAI.js +0 -141
- package/lib/loop/main.js +0 -60
- package/lib/loopTools/context.js +0 -67
- package/lib/loopTools/main.js +0 -54
- package/lib/loopTools/perform.js +0 -32
- package/lib/loopTools/snapshot.js +0 -29
- package/lib/loopTools/tool.js +0 -18
- package/lib/mcp/server.js +0 -123
- package/lib/tools/evaluate.js +0 -53
- package/lib/tools/form.js +0 -57
- package/lib/tools/keyboard.js +0 -78
- package/lib/tools/pdf.js +0 -40
- package/lib/tools/screenshot.js +0 -79
- package/lib/tools/snapshot.js +0 -139
- package/lib/tools.js +0 -54
- package/lib/utils/fileUtils.js +0 -36
- package/lib/utils/guid.js +0 -22
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,6 +14,44 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
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.CDPRelayServer = void 0;
|
|
16
55
|
/**
|
|
17
56
|
* WebSocket server that bridges Playwright MCP and Chrome Extension
|
|
18
57
|
*
|
|
@@ -20,31 +59,22 @@
|
|
|
20
59
|
* - /cdp/guid - Full CDP interface for Playwright MCP
|
|
21
60
|
* - /extension/guid - Extension connection for chrome.debugger forwarding
|
|
22
61
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
import { httpAddressToString } from '../mcp/http.js';
|
|
27
|
-
import { logUnhandledError } from '../utils/log.js';
|
|
28
|
-
import { ManualPromise } from '../mcp/manualPromise.js';
|
|
29
|
-
import * as protocol from './protocol.js';
|
|
62
|
+
const child_process_1 = require("child_process");
|
|
63
|
+
const debug_1 = __importDefault(require("debug"));
|
|
64
|
+
const ws_1 = require("ws");
|
|
30
65
|
// @ts-ignore
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
_cdpPath;
|
|
39
|
-
_extensionPath;
|
|
40
|
-
_wss;
|
|
41
|
-
_playwrightConnection = null;
|
|
42
|
-
_extensionConnection = null;
|
|
43
|
-
_connectedTabInfo;
|
|
44
|
-
_nextSessionId = 1;
|
|
45
|
-
_extensionConnectionPromise;
|
|
66
|
+
const index_1 = require("playwright-core/lib/server/registry/index");
|
|
67
|
+
const http_1 = require("../sdk/http");
|
|
68
|
+
const log_1 = require("../log");
|
|
69
|
+
const manualPromise_1 = require("../sdk/manualPromise");
|
|
70
|
+
const protocol = __importStar(require("./protocol"));
|
|
71
|
+
const debugLogger = (0, debug_1.default)('pw:mcp:relay');
|
|
72
|
+
class CDPRelayServer {
|
|
46
73
|
constructor(server, browserChannel, userDataDir, executablePath) {
|
|
47
|
-
this.
|
|
74
|
+
this._playwrightConnection = null;
|
|
75
|
+
this._extensionConnection = null;
|
|
76
|
+
this._nextSessionId = 1;
|
|
77
|
+
this._wsHost = (0, http_1.httpAddressToString)(server.address()).replace(/^http/, 'ws');
|
|
48
78
|
this._browserChannel = browserChannel;
|
|
49
79
|
this._userDataDir = userDataDir;
|
|
50
80
|
this._executablePath = executablePath;
|
|
@@ -52,7 +82,7 @@ export class CDPRelayServer {
|
|
|
52
82
|
this._cdpPath = `/cdp/${uuid}`;
|
|
53
83
|
this._extensionPath = `/extension/${uuid}`;
|
|
54
84
|
this._resetExtensionConnection();
|
|
55
|
-
this._wss = new WebSocketServer({ server });
|
|
85
|
+
this._wss = new ws_1.WebSocketServer({ server });
|
|
56
86
|
this._wss.on('connection', this._onConnection.bind(this));
|
|
57
87
|
}
|
|
58
88
|
cdpEndpoint() {
|
|
@@ -71,12 +101,13 @@ export class CDPRelayServer {
|
|
|
71
101
|
this._extensionConnectionPromise,
|
|
72
102
|
new Promise((_, reject) => setTimeout(() => {
|
|
73
103
|
reject(new Error(`Extension connection timeout. Make sure the "Playwright MCP Bridge" extension is installed. See https://github.com/microsoft/playwright-mcp/blob/main/extension/README.md for installation instructions.`));
|
|
74
|
-
}, process.env.PWMCP_TEST_CONNECTION_TIMEOUT ? parseInt(process.env.PWMCP_TEST_CONNECTION_TIMEOUT, 10) :
|
|
104
|
+
}, process.env.PWMCP_TEST_CONNECTION_TIMEOUT ? parseInt(process.env.PWMCP_TEST_CONNECTION_TIMEOUT, 10) : 5000)),
|
|
75
105
|
new Promise((_, reject) => abortSignal.addEventListener('abort', reject))
|
|
76
106
|
]);
|
|
77
107
|
debugLogger('Extension connection established');
|
|
78
108
|
}
|
|
79
109
|
_connectBrowser(clientInfo, toolName) {
|
|
110
|
+
var _a;
|
|
80
111
|
const mcpRelayEndpoint = `${this._wsHost}${this._extensionPath}`;
|
|
81
112
|
// Need to specify "key" in the manifest.json to make the id stable when loading from file.
|
|
82
113
|
const url = new URL('chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html');
|
|
@@ -86,13 +117,13 @@ export class CDPRelayServer {
|
|
|
86
117
|
version: clientInfo.version,
|
|
87
118
|
};
|
|
88
119
|
url.searchParams.set('client', JSON.stringify(client));
|
|
89
|
-
url.searchParams.set('protocolVersion', process.env.PWMCP_TEST_PROTOCOL_VERSION
|
|
120
|
+
url.searchParams.set('protocolVersion', (_a = process.env.PWMCP_TEST_PROTOCOL_VERSION) !== null && _a !== void 0 ? _a : protocol.VERSION.toString());
|
|
90
121
|
if (toolName)
|
|
91
122
|
url.searchParams.set('newTab', String(toolName === 'browser_navigate'));
|
|
92
123
|
const href = url.toString();
|
|
93
124
|
let executablePath = this._executablePath;
|
|
94
125
|
if (!executablePath) {
|
|
95
|
-
const executableInfo = registry.findExecutable(this._browserChannel);
|
|
126
|
+
const executableInfo = index_1.registry.findExecutable(this._browserChannel);
|
|
96
127
|
if (!executableInfo)
|
|
97
128
|
throw new Error(`Unsupported channel: "${this._browserChannel}"`);
|
|
98
129
|
executablePath = executableInfo.executablePath();
|
|
@@ -103,7 +134,7 @@ export class CDPRelayServer {
|
|
|
103
134
|
if (this._userDataDir)
|
|
104
135
|
args.push(`--user-data-dir=${this._userDataDir}`);
|
|
105
136
|
args.push(href);
|
|
106
|
-
spawn(executablePath, args, {
|
|
137
|
+
(0, child_process_1.spawn)(executablePath, args, {
|
|
107
138
|
windowsHide: true,
|
|
108
139
|
detached: true,
|
|
109
140
|
shell: false,
|
|
@@ -161,18 +192,20 @@ export class CDPRelayServer {
|
|
|
161
192
|
debugLogger('Playwright MCP connected');
|
|
162
193
|
}
|
|
163
194
|
_closeExtensionConnection(reason) {
|
|
164
|
-
|
|
195
|
+
var _a;
|
|
196
|
+
(_a = this._extensionConnection) === null || _a === void 0 ? void 0 : _a.close(reason);
|
|
165
197
|
this._extensionConnectionPromise.reject(new Error(reason));
|
|
166
198
|
this._resetExtensionConnection();
|
|
167
199
|
}
|
|
168
200
|
_resetExtensionConnection() {
|
|
169
201
|
this._connectedTabInfo = undefined;
|
|
170
202
|
this._extensionConnection = null;
|
|
171
|
-
this._extensionConnectionPromise = new ManualPromise();
|
|
172
|
-
void this._extensionConnectionPromise.catch(logUnhandledError);
|
|
203
|
+
this._extensionConnectionPromise = new manualPromise_1.ManualPromise();
|
|
204
|
+
void this._extensionConnectionPromise.catch(log_1.logUnhandledError);
|
|
173
205
|
}
|
|
174
206
|
_closePlaywrightConnection(reason) {
|
|
175
|
-
|
|
207
|
+
var _a;
|
|
208
|
+
if (((_a = this._playwrightConnection) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.WebSocket.OPEN)
|
|
176
209
|
this._playwrightConnection.close(1000, reason);
|
|
177
210
|
this._playwrightConnection = null;
|
|
178
211
|
}
|
|
@@ -193,9 +226,10 @@ export class CDPRelayServer {
|
|
|
193
226
|
this._extensionConnectionPromise.resolve();
|
|
194
227
|
}
|
|
195
228
|
_handleExtensionMessage(method, params) {
|
|
229
|
+
var _a;
|
|
196
230
|
switch (method) {
|
|
197
231
|
case 'forwardCDPEvent':
|
|
198
|
-
const sessionId = params.sessionId || this._connectedTabInfo
|
|
232
|
+
const sessionId = params.sessionId || ((_a = this._connectedTabInfo) === null || _a === void 0 ? void 0 : _a.sessionId);
|
|
199
233
|
this._sendToPlaywright({
|
|
200
234
|
sessionId,
|
|
201
235
|
method: params.method,
|
|
@@ -221,6 +255,7 @@ export class CDPRelayServer {
|
|
|
221
255
|
}
|
|
222
256
|
}
|
|
223
257
|
async _handleCDPCommand(method, params, sessionId) {
|
|
258
|
+
var _a;
|
|
224
259
|
switch (method) {
|
|
225
260
|
case 'Browser.getVersion': {
|
|
226
261
|
return {
|
|
@@ -257,38 +292,38 @@ export class CDPRelayServer {
|
|
|
257
292
|
return {};
|
|
258
293
|
}
|
|
259
294
|
case 'Target.getTargetInfo': {
|
|
260
|
-
return this._connectedTabInfo
|
|
295
|
+
return (_a = this._connectedTabInfo) === null || _a === void 0 ? void 0 : _a.targetInfo;
|
|
261
296
|
}
|
|
262
297
|
}
|
|
263
298
|
return await this._forwardToExtension(method, params, sessionId);
|
|
264
299
|
}
|
|
265
300
|
async _forwardToExtension(method, params, sessionId) {
|
|
301
|
+
var _a;
|
|
266
302
|
if (!this._extensionConnection)
|
|
267
303
|
throw new Error('Extension not connected');
|
|
268
304
|
// Top level sessionId is only passed between the relay and the client.
|
|
269
|
-
if (this._connectedTabInfo
|
|
305
|
+
if (((_a = this._connectedTabInfo) === null || _a === void 0 ? void 0 : _a.sessionId) === sessionId)
|
|
270
306
|
sessionId = undefined;
|
|
271
307
|
return await this._extensionConnection.send('forwardCDPCommand', { sessionId, method, params });
|
|
272
308
|
}
|
|
273
309
|
_sendToPlaywright(message) {
|
|
274
|
-
|
|
275
|
-
|
|
310
|
+
var _a, _b;
|
|
311
|
+
debugLogger('→ Playwright:', `${(_a = message.method) !== null && _a !== void 0 ? _a : `response(id=${message.id})`}`);
|
|
312
|
+
(_b = this._playwrightConnection) === null || _b === void 0 ? void 0 : _b.send(JSON.stringify(message));
|
|
276
313
|
}
|
|
277
314
|
}
|
|
315
|
+
exports.CDPRelayServer = CDPRelayServer;
|
|
278
316
|
class ExtensionConnection {
|
|
279
|
-
_ws;
|
|
280
|
-
_callbacks = new Map();
|
|
281
|
-
_lastId = 0;
|
|
282
|
-
onmessage;
|
|
283
|
-
onclose;
|
|
284
317
|
constructor(ws) {
|
|
318
|
+
this._callbacks = new Map();
|
|
319
|
+
this._lastId = 0;
|
|
285
320
|
this._ws = ws;
|
|
286
321
|
this._ws.on('message', this._onMessage.bind(this));
|
|
287
322
|
this._ws.on('close', this._onClose.bind(this));
|
|
288
323
|
this._ws.on('error', this._onError.bind(this));
|
|
289
324
|
}
|
|
290
325
|
async send(method, params) {
|
|
291
|
-
if (this._ws.readyState !== WebSocket.OPEN)
|
|
326
|
+
if (this._ws.readyState !== ws_1.WebSocket.OPEN)
|
|
292
327
|
throw new Error(`Unexpected WebSocket state: ${this._ws.readyState}`);
|
|
293
328
|
const id = ++this._lastId;
|
|
294
329
|
this._ws.send(JSON.stringify({ id, method, params }));
|
|
@@ -299,7 +334,7 @@ class ExtensionConnection {
|
|
|
299
334
|
}
|
|
300
335
|
close(message) {
|
|
301
336
|
debugLogger('closing extension connection:', message);
|
|
302
|
-
if (this._ws.readyState === WebSocket.OPEN)
|
|
337
|
+
if (this._ws.readyState === ws_1.WebSocket.OPEN)
|
|
303
338
|
this._ws.close(1000, message);
|
|
304
339
|
}
|
|
305
340
|
_onMessage(event) {
|
|
@@ -309,7 +344,7 @@ class ExtensionConnection {
|
|
|
309
344
|
parsedJson = JSON.parse(eventData);
|
|
310
345
|
}
|
|
311
346
|
catch (e) {
|
|
312
|
-
debugLogger(`<closing ws> Closing websocket due to malformed JSON. eventData=${eventData} e=${e
|
|
347
|
+
debugLogger(`<closing ws> Closing websocket due to malformed JSON. eventData=${eventData} e=${e === null || e === void 0 ? void 0 : e.message}`);
|
|
313
348
|
this._ws.close();
|
|
314
349
|
return;
|
|
315
350
|
}
|
|
@@ -317,11 +352,12 @@ class ExtensionConnection {
|
|
|
317
352
|
this._handleParsedMessage(parsedJson);
|
|
318
353
|
}
|
|
319
354
|
catch (e) {
|
|
320
|
-
debugLogger(`<closing ws> Closing websocket due to failed onmessage callback. eventData=${eventData} e=${e
|
|
355
|
+
debugLogger(`<closing ws> Closing websocket due to failed onmessage callback. eventData=${eventData} e=${e === null || e === void 0 ? void 0 : e.message}`);
|
|
321
356
|
this._ws.close();
|
|
322
357
|
}
|
|
323
358
|
}
|
|
324
359
|
_handleParsedMessage(object) {
|
|
360
|
+
var _a;
|
|
325
361
|
if (object.id && this._callbacks.has(object.id)) {
|
|
326
362
|
const callback = this._callbacks.get(object.id);
|
|
327
363
|
this._callbacks.delete(object.id);
|
|
@@ -338,13 +374,14 @@ class ExtensionConnection {
|
|
|
338
374
|
debugLogger('← Extension: unexpected response', object);
|
|
339
375
|
}
|
|
340
376
|
else {
|
|
341
|
-
this.onmessage
|
|
377
|
+
(_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, object.method, object.params);
|
|
342
378
|
}
|
|
343
379
|
}
|
|
344
380
|
_onClose(event) {
|
|
381
|
+
var _a;
|
|
345
382
|
debugLogger(`<ws closed> code=${event.code} reason=${event.reason}`);
|
|
346
383
|
this._dispose();
|
|
347
|
-
this.onclose
|
|
384
|
+
(_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this, this, event.reason);
|
|
348
385
|
}
|
|
349
386
|
_onError(event) {
|
|
350
387
|
debugLogger(`<ws error> message=${event.message} type=${event.type} target=${event.target}`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,15 +14,50 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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.ExtensionContextFactory = void 0;
|
|
55
|
+
const debug_1 = __importDefault(require("debug"));
|
|
56
|
+
const playwright = __importStar(require("playwright"));
|
|
57
|
+
const http_1 = require("../sdk/http");
|
|
58
|
+
const cdpRelay_1 = require("./cdpRelay");
|
|
59
|
+
const debugLogger = (0, debug_1.default)('pw:mcp:relay');
|
|
60
|
+
class ExtensionContextFactory {
|
|
25
61
|
constructor(browserChannel, userDataDir, executablePath) {
|
|
26
62
|
this._browserChannel = browserChannel;
|
|
27
63
|
this._userDataDir = userDataDir;
|
|
@@ -43,14 +79,15 @@ export class ExtensionContextFactory {
|
|
|
43
79
|
return await playwright.chromium.connectOverCDP(relay.cdpEndpoint());
|
|
44
80
|
}
|
|
45
81
|
async _startRelay(abortSignal) {
|
|
46
|
-
const httpServer = await startHttpServer({});
|
|
82
|
+
const httpServer = await (0, http_1.startHttpServer)({});
|
|
47
83
|
if (abortSignal.aborted) {
|
|
48
84
|
httpServer.close();
|
|
49
85
|
throw new Error(abortSignal.reason);
|
|
50
86
|
}
|
|
51
|
-
const cdpRelayServer = new CDPRelayServer(httpServer, this._browserChannel, this._userDataDir, this._executablePath);
|
|
87
|
+
const cdpRelayServer = new cdpRelay_1.CDPRelayServer(httpServer, this._browserChannel, this._userDataDir, this._executablePath);
|
|
52
88
|
abortSignal.addEventListener('abort', () => cdpRelayServer.stop());
|
|
53
89
|
debugLogger(`CDP relay server started, extension endpoint: ${cdpRelayServer.extensionEndpoint()}.`);
|
|
54
90
|
return cdpRelayServer;
|
|
55
91
|
}
|
|
56
92
|
}
|
|
93
|
+
exports.ExtensionContextFactory = ExtensionContextFactory;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,6 +14,8 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.VERSION = void 0;
|
|
16
19
|
// Whenever the commands/events change, the version must be updated. The latest
|
|
17
20
|
// extension version should be compatible with the old MCP clients.
|
|
18
|
-
|
|
21
|
+
exports.VERSION = 1;
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,21 +14,55 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
exports.createConnection = createConnection;
|
|
52
|
+
const browserServerBackend_1 = require("./browser/browserServerBackend");
|
|
53
|
+
const config_1 = require("./browser/config");
|
|
54
|
+
const browserContextFactory_1 = require("./browser/browserContextFactory");
|
|
55
|
+
const mcpServer = __importStar(require("./sdk/server"));
|
|
56
|
+
const package_1 = require("./package");
|
|
57
|
+
async function createConnection(userConfig = {}, contextGetter) {
|
|
58
|
+
const config = await (0, config_1.resolveConfig)(userConfig);
|
|
59
|
+
const factory = contextGetter ? new SimpleBrowserContextFactory(contextGetter) : (0, browserContextFactory_1.contextFactory)(config);
|
|
60
|
+
return mcpServer.createServer('Playwright', package_1.packageJSON.version, new browserServerBackend_1.BrowserServerBackend(config, factory), false);
|
|
25
61
|
}
|
|
26
62
|
class SimpleBrowserContextFactory {
|
|
27
|
-
name = 'custom';
|
|
28
|
-
description = 'Connect to a browser using a custom context getter';
|
|
29
|
-
_contextGetter;
|
|
30
63
|
constructor(contextGetter) {
|
|
64
|
+
this.name = 'custom';
|
|
65
|
+
this.description = 'Connect to a browser using a custom context getter';
|
|
31
66
|
this._contextGetter = contextGetter;
|
|
32
67
|
}
|
|
33
68
|
async createContext() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,9 +14,15 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.testDebug = void 0;
|
|
22
|
+
exports.logUnhandledError = logUnhandledError;
|
|
23
|
+
const debug_1 = __importDefault(require("debug"));
|
|
24
|
+
const errorsDebug = (0, debug_1.default)('pw:mcp:errors');
|
|
25
|
+
function logUnhandledError(error) {
|
|
19
26
|
errorsDebug(error);
|
|
20
27
|
}
|
|
21
|
-
|
|
28
|
+
exports.testDebug = (0, debug_1.default)('pw:mcp:test');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -13,8 +14,11 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.packageJSON = void 0;
|
|
22
|
+
const fs_1 = __importDefault(require("fs"));
|
|
23
|
+
const path_1 = __importDefault(require("path"));
|
|
24
|
+
exports.packageJSON = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, '..', 'package.json'), 'utf8'));
|