@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.
Files changed (69) hide show
  1. package/README.md +1 -1
  2. package/cli.js +1 -1
  3. package/index.d.ts +1 -1
  4. package/index.js +2 -2
  5. package/lib/{browserContextFactory.js → browser/browserContextFactory.js} +76 -36
  6. package/lib/{browserServerBackend.js → browser/browserServerBackend.js} +24 -22
  7. package/lib/{utils → browser}/codegen.js +8 -3
  8. package/lib/{config.js → browser/config.js} +43 -26
  9. package/lib/{context.js → browser/context.js} +27 -30
  10. package/lib/{response.js → browser/response.js} +14 -14
  11. package/lib/{sessionLog.js → browser/sessionLog.js} +23 -18
  12. package/lib/{tab.js → browser/tab.js} +29 -27
  13. package/lib/{tools → browser/tools}/common.js +11 -9
  14. package/lib/{tools → browser/tools}/console.js +7 -5
  15. package/lib/{tools → browser/tools}/dialogs.js +9 -7
  16. package/lib/browser/tools/evaluate.js +88 -0
  17. package/lib/{tools → browser/tools}/files.js +8 -6
  18. package/lib/browser/tools/form.js +92 -0
  19. package/lib/{tools → browser/tools}/install.js +18 -14
  20. package/lib/browser/tools/keyboard.js +113 -0
  21. package/lib/{tools → browser/tools}/mouse.js +18 -16
  22. package/lib/{tools → browser/tools}/navigate.js +10 -8
  23. package/lib/{tools → browser/tools}/network.js +7 -5
  24. package/lib/browser/tools/pdf.js +76 -0
  25. package/lib/browser/tools/screenshot.js +115 -0
  26. package/lib/browser/tools/snapshot.js +175 -0
  27. package/lib/{tools → browser/tools}/tabs.js +9 -7
  28. package/lib/{tools → browser/tools}/tool.js +6 -2
  29. package/lib/{tools → browser/tools}/utils.js +10 -5
  30. package/lib/{tools → browser/tools}/verify.js +59 -24
  31. package/lib/{tools → browser/tools}/wait.js +10 -8
  32. package/lib/browser/tools.js +61 -0
  33. package/lib/extension/cdpRelay.js +85 -48
  34. package/lib/extension/extensionContextFactory.js +48 -11
  35. package/lib/extension/protocol.js +4 -1
  36. package/lib/index.js +47 -12
  37. package/lib/{utils/log.js → log.js} +11 -4
  38. package/lib/{utils/package.js → package.js} +9 -5
  39. package/lib/program.js +68 -39
  40. package/lib/sdk/bundle.js +79 -0
  41. package/lib/{mcp → sdk}/http.js +57 -17
  42. package/lib/{mcp → sdk}/inProcessTransport.js +15 -20
  43. package/lib/{mcp → sdk}/manualPromise.js +11 -9
  44. package/lib/{mcp → sdk}/mdb.js +77 -38
  45. package/lib/{mcp → sdk}/proxyBackend.js +53 -16
  46. package/lib/sdk/server.js +164 -0
  47. package/lib/{mcp → sdk}/tool.js +8 -4
  48. package/lib/vscode/host.js +64 -35
  49. package/lib/vscode/main.js +48 -13
  50. package/package.json +6 -7
  51. package/lib/loop/loop.js +0 -69
  52. package/lib/loop/loopClaude.js +0 -152
  53. package/lib/loop/loopOpenAI.js +0 -141
  54. package/lib/loop/main.js +0 -60
  55. package/lib/loopTools/context.js +0 -67
  56. package/lib/loopTools/main.js +0 -54
  57. package/lib/loopTools/perform.js +0 -32
  58. package/lib/loopTools/snapshot.js +0 -29
  59. package/lib/loopTools/tool.js +0 -18
  60. package/lib/mcp/server.js +0 -123
  61. package/lib/tools/evaluate.js +0 -53
  62. package/lib/tools/form.js +0 -57
  63. package/lib/tools/keyboard.js +0 -78
  64. package/lib/tools/pdf.js +0 -40
  65. package/lib/tools/screenshot.js +0 -79
  66. package/lib/tools/snapshot.js +0 -139
  67. package/lib/tools.js +0 -54
  68. package/lib/utils/fileUtils.js +0 -36
  69. 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
- import { spawn } from 'child_process';
24
- import debug from 'debug';
25
- import { WebSocket, WebSocketServer } from 'ws';
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 { registry } = await import('playwright-core/lib/server/registry/index');
32
- const debugLogger = debug('pw:mcp:relay');
33
- export class CDPRelayServer {
34
- _wsHost;
35
- _browserChannel;
36
- _userDataDir;
37
- _executablePath;
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._wsHost = httpAddressToString(server.address()).replace(/^http/, 'ws');
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) : 5_000)),
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 ?? protocol.VERSION.toString());
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
- this._extensionConnection?.close(reason);
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
- if (this._playwrightConnection?.readyState === WebSocket.OPEN)
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?.sessionId;
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?.targetInfo;
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?.sessionId === sessionId)
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
- debugLogger('→ Playwright:', `${message.method ?? `response(id=${message.id})`}`);
275
- this._playwrightConnection?.send(JSON.stringify(message));
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?.message}`);
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?.message}`);
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?.(object.method, object.params);
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?.(this, event.reason);
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
- import debug from 'debug';
17
- import * as playwright from 'playwright';
18
- import { startHttpServer } from '../mcp/http.js';
19
- import { CDPRelayServer } from './cdpRelay.js';
20
- const debugLogger = debug('pw:mcp:relay');
21
- export class ExtensionContextFactory {
22
- _browserChannel;
23
- _userDataDir;
24
- _executablePath;
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
- export const VERSION = 1;
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
- import { BrowserServerBackend } from './browserServerBackend.js';
17
- import { resolveConfig } from './config.js';
18
- import { contextFactory } from './browserContextFactory.js';
19
- import * as mcpServer from './mcp/server.js';
20
- import { packageJSON } from './utils/package.js';
21
- export async function createConnection(userConfig = {}, contextGetter) {
22
- const config = await resolveConfig(userConfig);
23
- const factory = contextGetter ? new SimpleBrowserContextFactory(contextGetter) : contextFactory(config);
24
- return mcpServer.createServer('Playwright', packageJSON.version, new BrowserServerBackend(config, factory), false);
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
- import debug from 'debug';
17
- const errorsDebug = debug('pw:mcp:errors');
18
- export function logUnhandledError(error) {
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
- export const testDebug = debug('pw:mcp:test');
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
- import fs from 'fs';
17
- import path from 'path';
18
- import url from 'url';
19
- const __filename = url.fileURLToPath(import.meta.url);
20
- export const packageJSON = JSON.parse(fs.readFileSync(path.join(path.dirname(__filename), '..', '..', 'package.json'), 'utf8'));
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'));