@playwright/mcp 0.0.36-alpha-2025-09-01 → 0.0.36-alpha-2025-09-02

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 (2) hide show
  1. package/lib/vscode/host.js +45 -3
  2. package/package.json +1 -1
@@ -28,6 +28,7 @@ import { contextFactory } from '../browserContextFactory.js';
28
28
  const contextSwitchOptions = z.object({
29
29
  connectionString: z.string().optional().describe('The connection string to use to connect to the browser'),
30
30
  lib: z.string().optional().describe('The library to use for the connection'),
31
+ debugController: z.boolean().optional().describe('Enable the debug controller')
31
32
  });
32
33
  class VSCodeProxyBackend {
33
34
  _config;
@@ -38,6 +39,9 @@ class VSCodeProxyBackend {
38
39
  _contextSwitchTool;
39
40
  _roots = [];
40
41
  _clientVersion;
42
+ _context;
43
+ _browser;
44
+ _browserServer;
41
45
  constructor(_config, _defaultTransportFactory) {
42
46
  this._config = _config;
43
47
  this._defaultTransportFactory = _defaultTransportFactory;
@@ -46,7 +50,7 @@ class VSCodeProxyBackend {
46
50
  async initialize(server, clientVersion, roots) {
47
51
  this._clientVersion = clientVersion;
48
52
  this._roots = roots;
49
- const transport = await this._defaultTransportFactory();
53
+ const transport = await this._defaultTransportFactory(this);
50
54
  await this._setCurrentClient(transport);
51
55
  }
52
56
  async listTools() {
@@ -67,9 +71,41 @@ class VSCodeProxyBackend {
67
71
  serverClosed(server) {
68
72
  void this._currentClient?.close().catch(logUnhandledError);
69
73
  }
74
+ onContext(context) {
75
+ this._context = context;
76
+ context.on('close', () => {
77
+ this._context = undefined;
78
+ });
79
+ }
80
+ async _getDebugControllerURL() {
81
+ if (!this._context)
82
+ return;
83
+ const browser = this._context.browser();
84
+ if (!browser || !browser._launchServer)
85
+ return;
86
+ if (this._browser !== browser)
87
+ this._browserServer = undefined;
88
+ if (!this._browserServer)
89
+ this._browserServer = await browser._launchServer({ _debugController: true });
90
+ const url = new URL(this._browserServer.wsEndpoint());
91
+ url.searchParams.set('debug-controller', '1');
92
+ return url.toString();
93
+ }
70
94
  async _callContextSwitchTool(params) {
95
+ if (params.debugController) {
96
+ const url = await this._getDebugControllerURL();
97
+ const lines = [`### Result`];
98
+ if (url) {
99
+ lines.push(`URL: ${url}`);
100
+ lines.push(`Version: ${packageJSON.dependencies.playwright}`);
101
+ }
102
+ else {
103
+ lines.push(`No open browsers.`);
104
+ }
105
+ return { content: [{ type: 'text', text: lines.join('\n') }] };
106
+ }
71
107
  if (!params.connectionString || !params.lib) {
72
- const transport = await this._defaultTransportFactory();
108
+ const transport = await this._defaultTransportFactory(this);
73
109
  await this._setCurrentClient(transport);
74
110
  return {
75
111
  content: [{ type: 'text', text: '### Result\nSuccessfully disconnected.\n' }],
@@ -121,7 +157,13 @@ export async function runVSCodeTools(config) {
121
157
  name: 'Playwright w/ vscode',
122
158
  nameInConfig: 'playwright-vscode',
123
159
  version: packageJSON.version,
124
- create: () => new VSCodeProxyBackend(config, () => mcpServer.wrapInProcess(new BrowserServerBackend(config, contextFactory(config))))
160
+ create: () => new VSCodeProxyBackend(config, delegate => mcpServer.wrapInProcess(new BrowserServerBackend(config, {
161
+ async createContext(clientInfo, abortSignal, toolName) {
162
+ const context = await contextFactory(config).createContext(clientInfo, abortSignal, toolName);
163
+ delegate.onContext(context.browserContext);
164
+ return context;
165
+ },
166
+ })))
125
167
  };
126
168
  await mcpServer.start(serverBackendFactory, config.server);
127
169
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playwright/mcp",
3
- "version": "0.0.36-alpha-2025-09-01",
3
+ "version": "0.0.36-alpha-2025-09-02",
4
4
  "description": "Playwright Tools for MCP",
5
5
  "type": "module",
6
6
  "repository": {