playwright 1.56.0-alpha-1757023974000 → 1.56.0-alpha-1757090131000

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.
@@ -38,7 +38,6 @@ var import_path = __toESM(require("path"));
38
38
  var playwright = __toESM(require("playwright-core"));
39
39
  var import_registry = require("playwright-core/lib/server/registry/index");
40
40
  var import_server = require("playwright-core/lib/server");
41
- var import_processUtils = require("./processUtils");
42
41
  var import_log = require("../log");
43
42
  var import_config = require("./config");
44
43
  function contextFactory(config) {
@@ -156,27 +155,27 @@ class PersistentContextFactory {
156
155
  (0, import_log.testDebug)("lock user data dir", userDataDir);
157
156
  const browserType = playwright[this.config.browser.browserName];
158
157
  for (let i = 0; i < 5; i++) {
159
- if (!await alreadyRunning(this.config, browserType, userDataDir))
160
- break;
161
- await new Promise((resolve) => setTimeout(resolve, 1e3));
162
- }
163
- try {
164
- const browserContext = await browserType.launchPersistentContext(userDataDir, {
165
- tracesDir,
166
- ...this.config.browser.launchOptions,
167
- ...this.config.browser.contextOptions,
168
- handleSIGINT: false,
169
- handleSIGTERM: false
170
- });
171
- const close = () => this._closeBrowserContext(browserContext, userDataDir);
172
- return { browserContext, close };
173
- } catch (error) {
174
- if (error.message.includes("Executable doesn't exist"))
175
- throw new Error(`Browser specified in your config is not installed. Either install it (likely) or change the config.`);
176
- if (error.message.includes("ProcessSingleton") || error.message.includes("Invalid URL"))
177
- throw new Error(`Browser is already in use for ${userDataDir}, use --isolated to run multiple instances of the same browser`);
178
- throw error;
158
+ try {
159
+ const browserContext = await browserType.launchPersistentContext(userDataDir, {
160
+ tracesDir,
161
+ ...this.config.browser.launchOptions,
162
+ ...this.config.browser.contextOptions,
163
+ handleSIGINT: false,
164
+ handleSIGTERM: false
165
+ });
166
+ const close = () => this._closeBrowserContext(browserContext, userDataDir);
167
+ return { browserContext, close };
168
+ } catch (error) {
169
+ if (error.message.includes("Executable doesn't exist"))
170
+ throw new Error(`Browser specified in your config is not installed. Either install it (likely) or change the config.`);
171
+ if (error.message.includes("ProcessSingleton") || error.message.includes("Invalid URL")) {
172
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
173
+ continue;
174
+ }
175
+ throw error;
176
+ }
179
177
  }
178
+ throw new Error(`Browser is already in use for ${userDataDir}, use --isolated to run multiple instances of the same browser`);
180
179
  }
181
180
  async _closeBrowserContext(browserContext, userDataDir) {
182
181
  (0, import_log.testDebug)("close browser context (persistent)");
@@ -195,12 +194,6 @@ class PersistentContextFactory {
195
194
  return result;
196
195
  }
197
196
  }
198
- async function alreadyRunning(config, browserType, userDataDir) {
199
- const execPath = config.browser.launchOptions.executablePath ?? (0, import_processUtils.getBrowserExecPath)(config.browser.launchOptions.channel ?? browserType.name());
200
- if (!execPath)
201
- return false;
202
- return !!(0, import_processUtils.findBrowserProcess)(execPath, userDataDir);
203
- }
204
197
  async function injectCdpPort(browserConfig) {
205
198
  if (browserConfig.browserName === "chromium")
206
199
  browserConfig.launchOptions.cdpPort = await findFreePort();
@@ -37,7 +37,7 @@ function escapeWithQuotes(text, char = "'") {
37
37
  function quote(text) {
38
38
  return escapeWithQuotes(text, "'");
39
39
  }
40
- function formatObject(value, indent = " ") {
40
+ function formatObject(value, indent = " ", mode = "multiline") {
41
41
  if (typeof value === "string")
42
42
  return quote(value);
43
43
  if (Array.isArray(value))
@@ -49,10 +49,12 @@ function formatObject(value, indent = " ") {
49
49
  const tokens = [];
50
50
  for (const key of keys)
51
51
  tokens.push(`${key}: ${formatObject(value[key])}`);
52
- return `{
53
- ${indent}${tokens.join(`,
52
+ if (mode === "multiline")
53
+ return `{
54
+ ${tokens.join(`,
54
55
  ${indent}`)}
55
56
  }`;
57
+ return `{ ${tokens.join(", ")} }`;
56
58
  }
57
59
  return String(value);
58
60
  }
@@ -32,6 +32,7 @@ __export(config_exports, {
32
32
  configFromCLIOptions: () => configFromCLIOptions,
33
33
  dotenvFileLoader: () => dotenvFileLoader,
34
34
  headerParser: () => headerParser,
35
+ numberParser: () => numberParser,
35
36
  outputFile: () => outputFile,
36
37
  resolveCLIConfig: () => resolveCLIConfig,
37
38
  resolveConfig: () => resolveConfig,
@@ -60,7 +61,11 @@ const defaultConfig = {
60
61
  blockedOrigins: void 0
61
62
  },
62
63
  server: {},
63
- saveTrace: false
64
+ saveTrace: false,
65
+ timeouts: {
66
+ action: 5e3,
67
+ navigation: 6e4
68
+ }
64
69
  };
65
70
  async function resolveConfig(config) {
66
71
  return mergeConfig(defaultConfig, config);
@@ -156,7 +161,11 @@ function configFromCLIOptions(cliOptions) {
156
161
  saveTrace: cliOptions.saveTrace,
157
162
  secrets: cliOptions.secrets,
158
163
  outputDir: cliOptions.outputDir,
159
- imageResponses: cliOptions.imageResponses
164
+ imageResponses: cliOptions.imageResponses,
165
+ timeouts: {
166
+ action: cliOptions.timeoutAction,
167
+ navigation: cliOptions.timeoutNavigation
168
+ }
160
169
  };
161
170
  return result;
162
171
  }
@@ -180,12 +189,14 @@ function configFromEnv() {
180
189
  options.imageResponses = "omit";
181
190
  options.sandbox = envToBoolean(process.env.PLAYWRIGHT_MCP_SANDBOX);
182
191
  options.outputDir = envToString(process.env.PLAYWRIGHT_MCP_OUTPUT_DIR);
183
- options.port = envToNumber(process.env.PLAYWRIGHT_MCP_PORT);
192
+ options.port = numberParser(process.env.PLAYWRIGHT_MCP_PORT);
184
193
  options.proxyBypass = envToString(process.env.PLAYWRIGHT_MCP_PROXY_BYPASS);
185
194
  options.proxyServer = envToString(process.env.PLAYWRIGHT_MCP_PROXY_SERVER);
186
195
  options.saveTrace = envToBoolean(process.env.PLAYWRIGHT_MCP_SAVE_TRACE);
187
196
  options.secrets = dotenvFileLoader(process.env.PLAYWRIGHT_MCP_SECRETS_FILE);
188
197
  options.storageState = envToString(process.env.PLAYWRIGHT_MCP_STORAGE_STATE);
198
+ options.timeoutAction = numberParser(process.env.PLAYWRIGHT_MCP_TIMEOUT_ACTION);
199
+ options.timeoutNavigation = numberParser(process.env.PLAYWRIGHT_MCP_TIMEOUT_NAVIGATION);
189
200
  options.userAgent = envToString(process.env.PLAYWRIGHT_MCP_USER_AGENT);
190
201
  options.userDataDir = envToString(process.env.PLAYWRIGHT_MCP_USER_DATA_DIR);
191
202
  options.viewportSize = envToString(process.env.PLAYWRIGHT_MCP_VIEWPORT_SIZE);
@@ -240,6 +251,10 @@ function mergeConfig(base, overrides) {
240
251
  server: {
241
252
  ...pickDefined(base.server),
242
253
  ...pickDefined(overrides.server)
254
+ },
255
+ timeouts: {
256
+ ...pickDefined(base.timeouts),
257
+ ...pickDefined(overrides.timeouts)
243
258
  }
244
259
  };
245
260
  }
@@ -258,6 +273,11 @@ function dotenvFileLoader(value) {
258
273
  return void 0;
259
274
  return import_utilsBundle.dotenv.parse(import_fs.default.readFileSync(value, "utf8"));
260
275
  }
276
+ function numberParser(value) {
277
+ if (!value)
278
+ return void 0;
279
+ return +value;
280
+ }
261
281
  function headerParser(arg, previous) {
262
282
  if (!arg)
263
283
  return previous || {};
@@ -266,11 +286,6 @@ function headerParser(arg, previous) {
266
286
  result[name] = value;
267
287
  return result;
268
288
  }
269
- function envToNumber(value) {
270
- if (!value)
271
- return void 0;
272
- return +value;
273
- }
274
289
  function envToBoolean(value) {
275
290
  if (value === "true" || value === "1")
276
291
  return true;
@@ -294,6 +309,7 @@ function sanitizeForFilePath(s) {
294
309
  configFromCLIOptions,
295
310
  dotenvFileLoader,
296
311
  headerParser,
312
+ numberParser,
297
313
  outputFile,
298
314
  resolveCLIConfig,
299
315
  resolveConfig,
@@ -58,8 +58,8 @@ class Tab extends import_events.EventEmitter {
58
58
  page.on("download", (download) => {
59
59
  void this._downloadStarted(download);
60
60
  });
61
- page.setDefaultNavigationTimeout(6e4);
62
- page.setDefaultTimeout(5e3);
61
+ page.setDefaultNavigationTimeout(this.context.config.timeouts.navigation);
62
+ page.setDefaultTimeout(this.context.config.timeouts.action);
63
63
  page[tabSymbol] = this;
64
64
  }
65
65
  static forPage(page) {
@@ -56,7 +56,8 @@ const elementSchema = import_bundle.z.object({
56
56
  });
57
57
  const clickSchema = elementSchema.extend({
58
58
  doubleClick: import_bundle.z.boolean().optional().describe("Whether to perform a double click instead of a single click"),
59
- button: import_bundle.z.enum(["left", "right", "middle"]).optional().describe("Button to click, defaults to left")
59
+ button: import_bundle.z.enum(["left", "right", "middle"]).optional().describe("Button to click, defaults to left"),
60
+ modifiers: import_bundle.z.array(import_bundle.z.enum(["Alt", "Control", "ControlOrMeta", "Meta", "Shift"])).optional().describe("Modifier keys to press")
60
61
  });
61
62
  const click = (0, import_tool.defineTabTool)({
62
63
  capability: "core",
@@ -70,17 +71,21 @@ const click = (0, import_tool.defineTabTool)({
70
71
  handle: async (tab, params, response) => {
71
72
  response.setIncludeSnapshot();
72
73
  const locator = await tab.refLocator(params);
73
- const button = params.button;
74
- const buttonAttr = button ? `{ button: '${button}' }` : "";
74
+ const options = {
75
+ button: params.button,
76
+ modifiers: params.modifiers
77
+ };
78
+ const formatted = javascript.formatObject(options, " ", "oneline");
79
+ const optionsAttr = formatted !== "{}" ? formatted : "";
75
80
  if (params.doubleClick)
76
- response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.dblclick(${buttonAttr});`);
81
+ response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.dblclick(${optionsAttr});`);
77
82
  else
78
- response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.click(${buttonAttr});`);
83
+ response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.click(${optionsAttr});`);
79
84
  await tab.waitForCompletion(async () => {
80
85
  if (params.doubleClick)
81
- await locator.dblclick({ button });
86
+ await locator.dblclick(options);
82
87
  else
83
- await locator.click({ button });
88
+ await locator.click(options);
84
89
  });
85
90
  }
86
91
  });
@@ -5,6 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
8
12
  var __copyProps = (to, from, except, desc) => {
9
13
  if (from && typeof from === "object" || typeof from === "function") {
10
14
  for (let key of __getOwnPropNames(from))
@@ -21,6 +25,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var program_exports = {};
30
+ __export(program_exports, {
31
+ decorateCommand: () => decorateCommand
32
+ });
33
+ module.exports = __toCommonJS(program_exports);
24
34
  var import_utilsBundle = require("playwright-core/lib/utilsBundle");
25
35
  var mcpServer = __toESM(require("./sdk/server"));
26
36
  var import_config = require("./browser/config");
@@ -29,56 +39,57 @@ var import_browserContextFactory = require("./browser/browserContextFactory");
29
39
  var import_proxyBackend = require("./sdk/proxyBackend");
30
40
  var import_browserServerBackend = require("./browser/browserServerBackend");
31
41
  var import_extensionContextFactory = require("./extension/extensionContextFactory");
32
- const packageJSON = require("../../package.json");
33
- import_utilsBundle.program.version("Version " + packageJSON.version).name("Playwright MCP").option("--allowed-origins <origins>", "semicolon-separated list of origins to allow the browser to request. Default is to allow all.", import_config.semicolonSeparatedList).option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--config <path>", "path to the configuration file.").option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".').option("--no-sandbox", "disable the sandbox for all process types that are normally sandboxed.").option("--output-dir <path>", "path to the directory for output files.").option("--port <port>", "port to listen on for SSE transport.").option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--save-session", "Whether to save the Playwright MCP session into the output directory.").option("--save-trace", "Whether to save the Playwright Trace of the session into the output directory.").option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <path>", "path to the user data directory. If not specified, a temporary directory will be created.").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280, 720"').addOption(new import_utilsBundle.ProgramOption("--connect-tool", "Allow to switch between different browser connection methods.").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).action(async (options) => {
34
- setupExitWatchdog();
35
- if (options.vision) {
36
- console.error("The --vision option is deprecated, use --caps=vision instead");
37
- options.caps = "vision";
38
- }
39
- const config = await (0, import_config.resolveCLIConfig)(options);
40
- const browserContextFactory = (0, import_browserContextFactory.contextFactory)(config);
41
- const extensionContextFactory = new import_extensionContextFactory.ExtensionContextFactory(config.browser.launchOptions.channel || "chrome", config.browser.userDataDir, config.browser.launchOptions.executablePath);
42
- if (options.extension) {
43
- const serverBackendFactory = {
44
- name: "Playwright w/ extension",
45
- nameInConfig: "playwright-extension",
46
- version: packageJSON.version,
47
- create: () => new import_browserServerBackend.BrowserServerBackend(config, extensionContextFactory)
48
- };
49
- await mcpServer.start(serverBackendFactory, config.server);
50
- return;
51
- }
52
- if (options.connectTool) {
53
- const providers = [
54
- {
55
- name: "default",
56
- description: "Starts standalone browser",
57
- connect: () => mcpServer.wrapInProcess(new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory))
58
- },
59
- {
60
- name: "extension",
61
- description: "Connect to a browser using the Playwright MCP extension",
62
- connect: () => mcpServer.wrapInProcess(new import_browserServerBackend.BrowserServerBackend(config, extensionContextFactory))
63
- }
64
- ];
65
- const factory2 = {
66
- name: "Playwright w/ switch",
67
- nameInConfig: "playwright-switch",
68
- version: packageJSON.version,
69
- create: () => new import_proxyBackend.ProxyBackend(providers)
42
+ function decorateCommand(command, version) {
43
+ command.option("--allowed-origins <origins>", "semicolon-separated list of origins to allow the browser to request. Default is to allow all.", import_config.semicolonSeparatedList).option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--config <path>", "path to the configuration file.").option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".').option("--no-sandbox", "disable the sandbox for all process types that are normally sandboxed.").option("--output-dir <path>", "path to the directory for output files.").option("--port <port>", "port to listen on for SSE transport.").option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--save-session", "Whether to save the Playwright MCP session into the output directory.").option("--save-trace", "Whether to save the Playwright Trace of the session into the output directory.").option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--timeout-action <timeout>", "specify action timeout in milliseconds, defaults to 5000ms", import_config.numberParser).option("--timeout-navigation <timeout>", "specify navigation timeout in milliseconds, defaults to 60000ms", import_config.numberParser).option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <path>", "path to the user data directory. If not specified, a temporary directory will be created.").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280, 720"').addOption(new import_utilsBundle.ProgramOption("--connect-tool", "Allow to switch between different browser connection methods.").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).action(async (options) => {
44
+ setupExitWatchdog();
45
+ if (options.vision) {
46
+ console.error("The --vision option is deprecated, use --caps=vision instead");
47
+ options.caps = "vision";
48
+ }
49
+ const config = await (0, import_config.resolveCLIConfig)(options);
50
+ const browserContextFactory = (0, import_browserContextFactory.contextFactory)(config);
51
+ const extensionContextFactory = new import_extensionContextFactory.ExtensionContextFactory(config.browser.launchOptions.channel || "chrome", config.browser.userDataDir, config.browser.launchOptions.executablePath);
52
+ if (options.extension) {
53
+ const serverBackendFactory = {
54
+ name: "Playwright w/ extension",
55
+ nameInConfig: "playwright-extension",
56
+ version,
57
+ create: () => new import_browserServerBackend.BrowserServerBackend(config, extensionContextFactory)
58
+ };
59
+ await mcpServer.start(serverBackendFactory, config.server);
60
+ return;
61
+ }
62
+ if (options.connectTool) {
63
+ const providers = [
64
+ {
65
+ name: "default",
66
+ description: "Starts standalone browser",
67
+ connect: () => mcpServer.wrapInProcess(new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory))
68
+ },
69
+ {
70
+ name: "extension",
71
+ description: "Connect to a browser using the Playwright MCP extension",
72
+ connect: () => mcpServer.wrapInProcess(new import_browserServerBackend.BrowserServerBackend(config, extensionContextFactory))
73
+ }
74
+ ];
75
+ const factory2 = {
76
+ name: "Playwright w/ switch",
77
+ nameInConfig: "playwright-switch",
78
+ version,
79
+ create: () => new import_proxyBackend.ProxyBackend(providers)
80
+ };
81
+ await mcpServer.start(factory2, config.server);
82
+ return;
83
+ }
84
+ const factory = {
85
+ name: "Playwright",
86
+ nameInConfig: "playwright",
87
+ version,
88
+ create: () => new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory)
70
89
  };
71
- await mcpServer.start(factory2, config.server);
72
- return;
73
- }
74
- const factory = {
75
- name: "Playwright",
76
- nameInConfig: "playwright",
77
- version: packageJSON.version,
78
- create: () => new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory)
79
- };
80
- await mcpServer.start(factory, config.server);
81
- });
90
+ await mcpServer.start(factory, config.server);
91
+ });
92
+ }
82
93
  function setupExitWatchdog() {
83
94
  let isExiting = false;
84
95
  const handleExit = async () => {
@@ -93,4 +104,7 @@ function setupExitWatchdog() {
93
104
  process.on("SIGINT", handleExit);
94
105
  process.on("SIGTERM", handleExit);
95
106
  }
96
- void import_utilsBundle.program.parseAsync(process.argv);
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ decorateCommand
110
+ });
package/lib/program.js CHANGED
@@ -48,6 +48,8 @@ var import_testRunner = require("./runner/testRunner");
48
48
  var import_reporters = require("./runner/reporters");
49
49
  var import_exports = require("./mcp/sdk/exports");
50
50
  var import_testBackend = require("./mcp/test/testBackend");
51
+ var import_program3 = require("./mcp/program");
52
+ const packageJSON = require("../package.json");
51
53
  function addTestCommand(program3) {
52
54
  const command = program3.command("test [test-filter...]");
53
55
  command.description("run tests with Playwright Test");
@@ -141,8 +143,13 @@ Arguments [dir]:
141
143
  Examples:
142
144
  $ npx playwright merge-reports playwright-report`);
143
145
  }
144
- function addMCPServerCommand(program3) {
146
+ function addBrowserMCPServerCommand(program3) {
145
147
  const command = program3.command("run-mcp-server", { hidden: true });
148
+ command.description("Interact with the browser over MCP");
149
+ (0, import_program3.decorateCommand)(command, packageJSON.version);
150
+ }
151
+ function addTestMCPServerCommand(program3) {
152
+ const command = program3.command("run-test-mcp-server", { hidden: true });
146
153
  command.description("Interact with the test runner over MCP");
147
154
  command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);
148
155
  command.option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.");
@@ -152,7 +159,7 @@ function addMCPServerCommand(program3) {
152
159
  const backendFactory = {
153
160
  name: "Playwright Test Runner",
154
161
  nameInConfig: "playwright-test-runner",
155
- version: "0.0.0",
162
+ version: packageJSON.version,
156
163
  create: () => new import_testBackend.TestServerBackend(resolvedLocation, { muteConsole: options.port === void 0 })
157
164
  };
158
165
  const mdbUrl = await (0, import_exports.runMainBackend)(backendFactory, { port: options.port === void 0 ? void 0 : +options.port });
@@ -359,7 +366,8 @@ addTestCommand(import_program.program);
359
366
  addShowReportCommand(import_program.program);
360
367
  addMergeReportsCommand(import_program.program);
361
368
  addClearCacheCommand(import_program.program);
362
- addMCPServerCommand(import_program.program);
369
+ addBrowserMCPServerCommand(import_program.program);
370
+ addTestMCPServerCommand(import_program.program);
363
371
  addDevServerCommand(import_program.program);
364
372
  addTestServerCommand(import_program.program);
365
373
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright",
3
- "version": "1.56.0-alpha-1757023974000",
3
+ "version": "1.56.0-alpha-1757090131000",
4
4
  "description": "A high-level API to automate web browsers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "license": "Apache-2.0",
66
66
  "dependencies": {
67
- "playwright-core": "1.56.0-alpha-1757023974000"
67
+ "playwright-core": "1.56.0-alpha-1757090131000"
68
68
  },
69
69
  "optionalDependencies": {
70
70
  "fsevents": "2.3.2"
@@ -1,87 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var processUtils_exports = {};
30
- __export(processUtils_exports, {
31
- findBrowserProcess: () => findBrowserProcess,
32
- getBrowserExecPath: () => getBrowserExecPath
33
- });
34
- module.exports = __toCommonJS(processUtils_exports);
35
- var import_child_process = __toESM(require("child_process"));
36
- var import_registry = require("playwright-core/lib/server/registry/index");
37
- function getBrowserExecPath(channelOrName) {
38
- return import_registry.registry.findExecutable(channelOrName)?.executablePath("javascript");
39
- }
40
- function findBrowserProcess(execPath, arg) {
41
- switch (process.platform) {
42
- case "darwin":
43
- return findProcessMacos(execPath, arg);
44
- case "linux":
45
- return findProcessLinux(execPath, arg);
46
- case "win32":
47
- return findProcessWindows(execPath, arg);
48
- default:
49
- return null;
50
- }
51
- }
52
- function findProcessLinux(execPath, arg) {
53
- const psResult = import_child_process.default.spawnSync("ps", ["-eo", "pid=,args="]);
54
- return findMatchingLine(psResult.stdout.toString(), execPath, arg);
55
- }
56
- function findProcessMacos(execPath, arg) {
57
- const psResult = import_child_process.default.spawnSync("ps", ["-axo", "pid=,command="]);
58
- return findMatchingLine(psResult.stdout.toString(), execPath, arg);
59
- }
60
- function findProcessWindows(execPath, arg) {
61
- const filter = `$_.ExecutablePath -eq '${execPath}' -and $_.CommandLine.Contains('${arg}') -and $_.CommandLine -notmatch '--type'`;
62
- const ps = import_child_process.default.spawnSync(
63
- "powershell.exe",
64
- [
65
- "-NoProfile",
66
- "-Command",
67
- `Get-CimInstance Win32_Process | Where-Object { ${filter} } | Select-Object -Property ProcessId,CommandLine | ForEach-Object { "$($_.ProcessId) $($_.CommandLine)" }`
68
- ],
69
- { encoding: "utf8" }
70
- );
71
- if (ps.status !== 0)
72
- return null;
73
- return findMatchingLine(ps.stdout.toString(), execPath, arg);
74
- }
75
- function findMatchingLine(psOutput, execPath, arg) {
76
- const lines = psOutput.split("\n").map((l) => l.trim()).filter(Boolean);
77
- for (const line of lines) {
78
- if (line.includes(execPath) && line.includes(arg) && !line.includes("--type"))
79
- return line;
80
- }
81
- return null;
82
- }
83
- // Annotate the CommonJS export names for ESM import in node:
84
- 0 && (module.exports = {
85
- findBrowserProcess,
86
- getBrowserExecPath
87
- });