playwright 1.56.0-alpha-2025-09-05 → 1.56.0-alpha-2025-09-06

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) {
@@ -99,8 +98,11 @@ class IsolatedContextFactory extends BaseContextFactory {
99
98
  async _doObtainBrowser(clientInfo) {
100
99
  await injectCdpPort(this.config.browser);
101
100
  const browserType = playwright[this.config.browser.browserName];
101
+ const tracesDir = await (0, import_config.outputFile)(this.config, clientInfo.rootPath, `traces`);
102
+ if (this.config.saveTrace)
103
+ await startTraceServer(this.config, tracesDir);
102
104
  return browserType.launch({
103
- tracesDir: await startTraceServer(this.config, clientInfo.rootPath),
105
+ tracesDir,
104
106
  ...this.config.browser.launchOptions,
105
107
  handleSIGINT: false,
106
108
  handleSIGTERM: false
@@ -151,32 +153,39 @@ class PersistentContextFactory {
151
153
  await injectCdpPort(this.config.browser);
152
154
  (0, import_log.testDebug)("create browser context (persistent)");
153
155
  const userDataDir = this.config.browser.userDataDir ?? await this._createUserDataDir(clientInfo.rootPath);
154
- const tracesDir = await startTraceServer(this.config, clientInfo.rootPath);
156
+ const tracesDir = await (0, import_config.outputFile)(this.config, clientInfo.rootPath, `traces`);
157
+ if (this.config.saveTrace)
158
+ await startTraceServer(this.config, tracesDir);
155
159
  this._userDataDirs.add(userDataDir);
156
160
  (0, import_log.testDebug)("lock user data dir", userDataDir);
157
161
  const browserType = playwright[this.config.browser.browserName];
158
162
  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, {
163
+ const launchOptions = {
165
164
  tracesDir,
166
165
  ...this.config.browser.launchOptions,
167
166
  ...this.config.browser.contextOptions,
168
167
  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;
168
+ handleSIGTERM: false,
169
+ ignoreDefaultArgs: [
170
+ "--disable-extensions"
171
+ ],
172
+ assistantMode: true
173
+ };
174
+ try {
175
+ const browserContext = await browserType.launchPersistentContext(userDataDir, launchOptions);
176
+ const close = () => this._closeBrowserContext(browserContext, userDataDir);
177
+ return { browserContext, close };
178
+ } catch (error) {
179
+ if (error.message.includes("Executable doesn't exist"))
180
+ throw new Error(`Browser specified in your config is not installed. Either install it (likely) or change the config.`);
181
+ if (error.message.includes("ProcessSingleton") || error.message.includes("Invalid URL")) {
182
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
183
+ continue;
184
+ }
185
+ throw error;
186
+ }
179
187
  }
188
+ throw new Error(`Browser is already in use for ${userDataDir}, use --isolated to run multiple instances of the same browser`);
180
189
  }
181
190
  async _closeBrowserContext(browserContext, userDataDir) {
182
191
  (0, import_log.testDebug)("close browser context (persistent)");
@@ -195,12 +204,6 @@ class PersistentContextFactory {
195
204
  return result;
196
205
  }
197
206
  }
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
207
  async function injectCdpPort(browserConfig) {
205
208
  if (browserConfig.browserName === "chromium")
206
209
  browserConfig.launchOptions.cdpPort = await findFreePort();
@@ -215,15 +218,13 @@ async function findFreePort() {
215
218
  server.on("error", reject);
216
219
  });
217
220
  }
218
- async function startTraceServer(config, rootPath) {
221
+ async function startTraceServer(config, tracesDir) {
219
222
  if (!config.saveTrace)
220
- return void 0;
221
- const tracesDir = await (0, import_config.outputFile)(config, rootPath, `traces-${Date.now()}`);
223
+ return;
222
224
  const server = await (0, import_server.startTraceViewerServer)();
223
225
  const urlPrefix = server.urlPrefix("human-readable");
224
226
  const url = urlPrefix + "/trace/index.html?trace=" + tracesDir + "/trace.json";
225
227
  console.error("\nTrace viewer listening on " + url);
226
- return tracesDir;
227
228
  }
228
229
  function createHash(data) {
229
230
  return import_crypto.default.createHash("sha256").update(data).digest("hex").slice(0, 7);
@@ -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,
@@ -155,6 +155,10 @@ class Context {
155
155
  await context.route(`*://${origin}/**`, (route) => route.abort("blockedbyclient"));
156
156
  }
157
157
  }
158
+ async ensureBrowserContext() {
159
+ const { browserContext } = await this._ensureBrowserContext();
160
+ return browserContext;
161
+ }
158
162
  _ensureBrowserContext() {
159
163
  if (!this._browserContextPromise) {
160
164
  this._browserContextPromise = this._setupBrowserContext();
@@ -177,10 +181,10 @@ class Context {
177
181
  browserContext.on("page", (page) => this._onPageCreated(page));
178
182
  if (this.config.saveTrace) {
179
183
  await browserContext.tracing.start({
180
- name: "trace",
181
- screenshots: false,
184
+ name: "trace-" + Date.now(),
185
+ screenshots: true,
182
186
  snapshots: true,
183
- sources: false
187
+ _live: true
184
188
  });
185
189
  }
186
190
  return result;
@@ -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) {
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var tracing_exports = {};
20
+ __export(tracing_exports, {
21
+ default: () => tracing_default
22
+ });
23
+ module.exports = __toCommonJS(tracing_exports);
24
+ var import_bundle = require("../../sdk/bundle");
25
+ var import_tool = require("./tool");
26
+ const tracingStart = (0, import_tool.defineTool)({
27
+ capability: "tracing",
28
+ schema: {
29
+ name: "browser_start_tracing",
30
+ title: "Start tracing",
31
+ description: "Start trace recording",
32
+ inputSchema: import_bundle.z.object({}),
33
+ type: "readOnly"
34
+ },
35
+ handle: async (context, params, response) => {
36
+ const browserContext = await context.ensureBrowserContext();
37
+ const tracesDir = await context.outputFile(`traces`);
38
+ const name = "trace-" + Date.now();
39
+ await browserContext.tracing.start({
40
+ name,
41
+ screenshots: true,
42
+ snapshots: true,
43
+ _live: true
44
+ });
45
+ const traceLegend = `- Action log: ${tracesDir}/${name}.trace
46
+ - Network log: ${tracesDir}/${name}.network
47
+ - Resources with content by sha1: ${tracesDir}/resources`;
48
+ response.addResult(`Tracing started, saving to ${tracesDir}.
49
+ ${traceLegend}`);
50
+ browserContext.tracing[traceLegendSymbol] = traceLegend;
51
+ }
52
+ });
53
+ const tracingStop = (0, import_tool.defineTool)({
54
+ capability: "tracing",
55
+ schema: {
56
+ name: "browser_stop_tracing",
57
+ title: "Stop tracing",
58
+ description: "Stop trace recording",
59
+ inputSchema: import_bundle.z.object({}),
60
+ type: "readOnly"
61
+ },
62
+ handle: async (context, params, response) => {
63
+ const browserContext = await context.ensureBrowserContext();
64
+ await browserContext.tracing.stop();
65
+ const traceLegend = browserContext.tracing[traceLegendSymbol];
66
+ response.addResult(`Tracing stopped.
67
+ ${traceLegend}`);
68
+ }
69
+ });
70
+ var tracing_default = [
71
+ tracingStart,
72
+ tracingStop
73
+ ];
74
+ const traceLegendSymbol = Symbol("tracesDir");
@@ -45,8 +45,9 @@ var import_navigate = __toESM(require("./tools/navigate"));
45
45
  var import_network = __toESM(require("./tools/network"));
46
46
  var import_pdf = __toESM(require("./tools/pdf"));
47
47
  var import_snapshot = __toESM(require("./tools/snapshot"));
48
- var import_tabs = __toESM(require("./tools/tabs"));
49
48
  var import_screenshot = __toESM(require("./tools/screenshot"));
49
+ var import_tabs = __toESM(require("./tools/tabs"));
50
+ var import_tracing = __toESM(require("./tools/tracing"));
50
51
  var import_wait = __toESM(require("./tools/wait"));
51
52
  var import_verify = __toESM(require("./tools/verify"));
52
53
  const allTools = [
@@ -65,6 +66,7 @@ const allTools = [
65
66
  ...import_screenshot.default,
66
67
  ...import_snapshot.default,
67
68
  ...import_tabs.default,
69
+ ...import_tracing.default,
68
70
  ...import_wait.default,
69
71
  ...import_verify.default
70
72
  ];
@@ -40,7 +40,7 @@ var import_proxyBackend = require("./sdk/proxyBackend");
40
40
  var import_browserServerBackend = require("./browser/browserServerBackend");
41
41
  var import_extensionContextFactory = require("./extension/extensionContextFactory");
42
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("--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) => {
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
44
  setupExitWatchdog();
45
45
  if (options.vision) {
46
46
  console.error("The --vision option is deprecated, use --caps=vision instead");
@@ -85,8 +85,14 @@ function createServer(name, version, backend, runHeartbeat) {
85
85
  const capabilities = server.getClientCapabilities();
86
86
  let clientRoots = [];
87
87
  if (capabilities?.roots) {
88
- const { roots } = await server.listRoots(void 0, { timeout: 2e3 }).catch(() => ({ roots: [] }));
89
- clientRoots = roots;
88
+ for (let i = 0; i < 2; i++) {
89
+ try {
90
+ const { roots } = await server.listRoots(void 0, { timeout: 2e3 });
91
+ clientRoots = roots;
92
+ } catch (e) {
93
+ continue;
94
+ }
95
+ }
90
96
  }
91
97
  const clientVersion = server.getClientVersion() ?? { name: "unknown", version: "unknown" };
92
98
  await backend.initialize?.(server, clientVersion, clientRoots);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright",
3
- "version": "1.56.0-alpha-2025-09-05",
3
+ "version": "1.56.0-alpha-2025-09-06",
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-2025-09-05"
67
+ "playwright-core": "1.56.0-alpha-2025-09-06"
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
- });