playwright 1.56.0-alpha-1756945786000 → 1.56.0-alpha-1757023974000

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.
@@ -20,12 +20,10 @@ var matcherHint_exports = {};
20
20
  __export(matcherHint_exports, {
21
21
  ExpectError: () => ExpectError,
22
22
  isJestError: () => isJestError,
23
- kNoElementsFoundError: () => kNoElementsFoundError,
24
23
  matcherHint: () => matcherHint
25
24
  });
26
25
  module.exports = __toCommonJS(matcherHint_exports);
27
26
  var import_utils = require("playwright-core/lib/utils");
28
- const kNoElementsFoundError = "<element(s) not found>";
29
27
  function matcherHint(state, locator, matcherName, expression, actual, matcherOptions, timeout, expectedReceivedString, preventExtraStatIndent = false) {
30
28
  let header = state.utils.matcherHint(matcherName, expression, actual, matcherOptions).replace(/ \/\/ deep equality/, "") + " failed\n\n";
31
29
  const extraSpace = preventExtraStatIndent ? "" : " ";
@@ -58,6 +56,5 @@ function isJestError(e) {
58
56
  0 && (module.exports = {
59
57
  ExpectError,
60
58
  isJestError,
61
- kNoElementsFoundError,
62
59
  matcherHint
63
60
  });
@@ -31,10 +31,7 @@ async function toBeTruthy(matcherName, receiver, receiverType, expected, arg, qu
31
31
  promise: this.promise
32
32
  };
33
33
  const timeout = options.timeout ?? this.timeout;
34
- const { matches: pass, log, timedOut, received } = await query(!!this.isNot, timeout).catch(async (error) => {
35
- await (0, import_browserBackend.runBrowserBackendOnError)(receiver.page(), () => error.message);
36
- throw error;
37
- });
34
+ const { matches: pass, log, timedOut, received, errorMessage } = await query(!!this.isNot, timeout);
38
35
  if (pass === !this.isNot) {
39
36
  return {
40
37
  name: matcherName,
@@ -43,15 +40,14 @@ async function toBeTruthy(matcherName, receiver, receiverType, expected, arg, qu
43
40
  expected
44
41
  };
45
42
  }
46
- const notFound = received === import_matcherHint.kNoElementsFoundError ? received : void 0;
47
43
  let printedReceived;
48
44
  let printedExpected;
49
45
  if (pass) {
50
46
  printedExpected = `Expected: not ${expected}`;
51
- printedReceived = `Received: ${notFound ? import_matcherHint.kNoElementsFoundError : expected}`;
47
+ printedReceived = errorMessage ?? `Received: ${expected}`;
52
48
  } else {
53
49
  printedExpected = `Expected: ${expected}`;
54
- printedReceived = `Received: ${notFound ? import_matcherHint.kNoElementsFoundError : received}`;
50
+ printedReceived = errorMessage ?? `Received: ${received}`;
55
51
  }
56
52
  const message = () => {
57
53
  const header = (0, import_matcherHint.matcherHint)(this, receiver, matcherName, "locator", arg, matcherOptions, timedOut ? timeout : void 0, `${printedExpected}
@@ -35,10 +35,7 @@ async function toEqual(matcherName, receiver, receiverType, query, expected, opt
35
35
  promise: this.promise
36
36
  };
37
37
  const timeout = options.timeout ?? this.timeout;
38
- const { matches: pass, received, log, timedOut } = await query(!!this.isNot, timeout).catch(async (error) => {
39
- await (0, import_browserBackend.runBrowserBackendOnError)(receiver.page(), () => error.message);
40
- throw error;
41
- });
38
+ const { matches: pass, received, log, timedOut, errorMessage } = await query(!!this.isNot, timeout);
42
39
  if (pass === !this.isNot) {
43
40
  return {
44
41
  name: matcherName,
@@ -52,7 +49,10 @@ async function toEqual(matcherName, receiver, receiverType, query, expected, opt
52
49
  let printedDiff;
53
50
  if (pass) {
54
51
  printedExpected = `Expected: not ${this.utils.printExpected(expected)}`;
55
- printedReceived = `Received: ${this.utils.printReceived(received)}`;
52
+ printedReceived = errorMessage ?? `Received: ${this.utils.printReceived(received)}`;
53
+ } else if (errorMessage) {
54
+ printedExpected = `Expected: ${this.utils.printExpected(expected)}`;
55
+ printedReceived = errorMessage;
56
56
  } else if (Array.isArray(expected) && Array.isArray(received)) {
57
57
  const normalizedExpected = expected.map((exp, index) => {
58
58
  const rec = received[index];
@@ -35,7 +35,6 @@ var import_fs = __toESM(require("fs"));
35
35
  var import_path = __toESM(require("path"));
36
36
  var import_utils = require("playwright-core/lib/utils");
37
37
  var import_matcherHint = require("./matcherHint");
38
- var import_expectBundle = require("../common/expectBundle");
39
38
  var import_util = require("../util");
40
39
  var import_expect = require("./expect");
41
40
  var import_globals = require("../common/globals");
@@ -75,17 +74,16 @@ async function toMatchAriaSnapshot(receiver, expectedParam, options = {}) {
75
74
  }
76
75
  }
77
76
  expected = unshift(expected);
78
- const { matches: pass, received, log, timedOut } = await receiver._expect("to.match.aria", { expectedValue: expected, isNot: this.isNot, timeout });
77
+ const { matches: pass, received, log, timedOut, errorMessage } = await receiver._expect("to.match.aria", { expectedValue: expected, isNot: this.isNot, timeout });
79
78
  const typedReceived = received;
80
79
  const matcherHintWithExpect = (expectedReceivedString) => {
81
80
  return (0, import_matcherHint.matcherHint)(this, receiver, matcherName, "locator", void 0, matcherOptions, timedOut ? timeout : void 0, expectedReceivedString);
82
81
  };
83
- const notFound = typedReceived === import_matcherHint.kNoElementsFoundError;
84
- if (notFound) {
82
+ if (errorMessage) {
85
83
  return {
86
84
  pass: this.isNot,
87
85
  message: () => matcherHintWithExpect(`Expected: ${this.utils.printExpected(expected)}
88
- Received: ${(0, import_expectBundle.EXPECTED_COLOR)("<element not found>")}`) + (0, import_util.callLogText)(log),
86
+ ${errorMessage}`) + (0, import_util.callLogText)(log),
89
87
  name: "toMatchAriaSnapshot",
90
88
  expected
91
89
  };
@@ -93,14 +91,13 @@ Received: ${(0, import_expectBundle.EXPECTED_COLOR)("<element not found>")}`) +
93
91
  const receivedText = typedReceived.raw;
94
92
  const message = () => {
95
93
  if (pass) {
96
- const receivedString = notFound ? receivedText : (0, import_expect.printReceivedStringContainExpectedSubstring)(receivedText, receivedText.indexOf(expected), expected.length);
94
+ const receivedString = (0, import_expect.printReceivedStringContainExpectedSubstring)(receivedText, receivedText.indexOf(expected), expected.length);
97
95
  const expectedReceivedString = `Expected: not ${this.utils.printExpected(expected)}
98
96
  Received: ${receivedString}`;
99
97
  return matcherHintWithExpect(expectedReceivedString) + (0, import_util.callLogText)(log);
100
98
  } else {
101
99
  const labelExpected = `Expected`;
102
- const expectedReceivedString = notFound ? `${labelExpected}: ${this.utils.printExpected(expected)}
103
- Received: ${receivedText}` : this.utils.printDiffOrStringify(expected, receivedText, labelExpected, "Received", false);
100
+ const expectedReceivedString = this.utils.printDiffOrStringify(expected, receivedText, labelExpected, "Received", false);
104
101
  return matcherHintWithExpect(expectedReceivedString) + (0, import_util.callLogText)(log);
105
102
  }
106
103
  };
@@ -41,11 +41,7 @@ async function toMatchText(matcherName, receiver, receiverType, query, expected,
41
41
  ].join("\n\n"));
42
42
  }
43
43
  const timeout = options.timeout ?? this.timeout;
44
- const { matches: pass, received, log, timedOut } = await query(!!this.isNot, timeout).catch(async (error) => {
45
- if (receiverType === "Locator")
46
- await (0, import_browserBackend.runBrowserBackendOnError)(receiver.page(), () => error.message);
47
- throw error;
48
- });
44
+ const { matches: pass, received, log, timedOut, errorMessage } = await query(!!this.isNot, timeout);
49
45
  if (pass === !this.isNot) {
50
46
  return {
51
47
  name: matcherName,
@@ -56,35 +52,32 @@ async function toMatchText(matcherName, receiver, receiverType, query, expected,
56
52
  }
57
53
  const stringSubstring = options.matchSubstring ? "substring" : "string";
58
54
  const receivedString = received || "";
59
- const notFound = received === import_matcherHint.kNoElementsFoundError;
60
55
  let printedReceived;
61
56
  let printedExpected;
62
57
  let printedDiff;
63
58
  if (pass) {
64
59
  if (typeof expected === "string") {
65
- if (notFound) {
66
- printedExpected = `Expected ${stringSubstring}: not ${this.utils.printExpected(expected)}`;
67
- printedReceived = `Received: ${received}`;
60
+ printedExpected = `Expected ${stringSubstring}: not ${this.utils.printExpected(expected)}`;
61
+ if (errorMessage) {
62
+ printedReceived = errorMessage;
68
63
  } else {
69
- printedExpected = `Expected ${stringSubstring}: not ${this.utils.printExpected(expected)}`;
70
64
  const formattedReceived = (0, import_expect.printReceivedStringContainExpectedSubstring)(receivedString, receivedString.indexOf(expected), expected.length);
71
65
  printedReceived = `Received string: ${formattedReceived}`;
72
66
  }
73
67
  } else {
74
- if (notFound) {
75
- printedExpected = `Expected pattern: not ${this.utils.printExpected(expected)}`;
76
- printedReceived = `Received: ${received}`;
68
+ printedExpected = `Expected pattern: not ${this.utils.printExpected(expected)}`;
69
+ if (errorMessage) {
70
+ printedReceived = errorMessage;
77
71
  } else {
78
- printedExpected = `Expected pattern: not ${this.utils.printExpected(expected)}`;
79
72
  const formattedReceived = (0, import_expect.printReceivedStringContainExpectedResult)(receivedString, typeof expected.exec === "function" ? expected.exec(receivedString) : null);
80
73
  printedReceived = `Received string: ${formattedReceived}`;
81
74
  }
82
75
  }
83
76
  } else {
84
77
  const labelExpected = `Expected ${typeof expected === "string" ? stringSubstring : "pattern"}`;
85
- if (notFound) {
78
+ if (errorMessage) {
86
79
  printedExpected = `${labelExpected}: ${this.utils.printExpected(expected)}`;
87
- printedReceived = `Received: ${received}`;
80
+ printedReceived = errorMessage;
88
81
  } else {
89
82
  printedDiff = this.utils.printDiffOrStringify(expected, receivedString, labelExpected, "Received string", false);
90
83
  }
@@ -38,6 +38,7 @@ 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");
41
42
  var import_log = require("../log");
42
43
  var import_config = require("./config");
43
44
  function contextFactory(config) {
@@ -118,7 +119,7 @@ class CdpContextFactory extends BaseContextFactory {
118
119
  super("cdp", config);
119
120
  }
120
121
  async _doObtainBrowser() {
121
- return playwright.chromium.connectOverCDP(this.config.browser.cdpEndpoint);
122
+ return playwright.chromium.connectOverCDP(this.config.browser.cdpEndpoint, { headers: this.config.browser.cdpHeaders });
122
123
  }
123
124
  async _doCreateContext(browser) {
124
125
  return this.config.browser.isolated ? await browser.newContext() : browser.contexts()[0];
@@ -155,27 +156,27 @@ class PersistentContextFactory {
155
156
  (0, import_log.testDebug)("lock user data dir", userDataDir);
156
157
  const browserType = playwright[this.config.browser.browserName];
157
158
  for (let i = 0; i < 5; i++) {
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
- }
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;
177
179
  }
178
- throw new Error(`Browser is already in use for ${userDataDir}, use --isolated to run multiple instances of the same browser`);
179
180
  }
180
181
  async _closeBrowserContext(browserContext, userDataDir) {
181
182
  (0, import_log.testDebug)("close browser context (persistent)");
@@ -194,6 +195,12 @@ class PersistentContextFactory {
194
195
  return result;
195
196
  }
196
197
  }
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
+ }
197
204
  async function injectCdpPort(browserConfig) {
198
205
  if (browserConfig.browserName === "chromium")
199
206
  browserConfig.launchOptions.cdpPort = await findFreePort();
@@ -30,6 +30,8 @@ var config_exports = {};
30
30
  __export(config_exports, {
31
31
  commaSeparatedList: () => commaSeparatedList,
32
32
  configFromCLIOptions: () => configFromCLIOptions,
33
+ dotenvFileLoader: () => dotenvFileLoader,
34
+ headerParser: () => headerParser,
33
35
  outputFile: () => outputFile,
34
36
  resolveCLIConfig: () => resolveCLIConfig,
35
37
  resolveConfig: () => resolveConfig,
@@ -40,6 +42,7 @@ var import_fs = __toESM(require("fs"));
40
42
  var import_os = __toESM(require("os"));
41
43
  var import_path = __toESM(require("path"));
42
44
  var import_playwright_core = require("playwright-core");
45
+ var import_utilsBundle = require("playwright-core/lib/utilsBundle");
43
46
  const defaultConfig = {
44
47
  browser: {
45
48
  browserName: "chromium",
@@ -137,7 +140,8 @@ function configFromCLIOptions(cliOptions) {
137
140
  userDataDir: cliOptions.userDataDir,
138
141
  launchOptions,
139
142
  contextOptions,
140
- cdpEndpoint: cliOptions.cdpEndpoint
143
+ cdpEndpoint: cliOptions.cdpEndpoint,
144
+ cdpHeaders: cliOptions.cdpHeader
141
145
  },
142
146
  server: {
143
147
  port: cliOptions.port,
@@ -150,6 +154,7 @@ function configFromCLIOptions(cliOptions) {
150
154
  },
151
155
  saveSession: cliOptions.saveSession,
152
156
  saveTrace: cliOptions.saveTrace,
157
+ secrets: cliOptions.secrets,
153
158
  outputDir: cliOptions.outputDir,
154
159
  imageResponses: cliOptions.imageResponses
155
160
  };
@@ -163,6 +168,7 @@ function configFromEnv() {
163
168
  options.browser = envToString(process.env.PLAYWRIGHT_MCP_BROWSER);
164
169
  options.caps = commaSeparatedList(process.env.PLAYWRIGHT_MCP_CAPS);
165
170
  options.cdpEndpoint = envToString(process.env.PLAYWRIGHT_MCP_CDP_ENDPOINT);
171
+ options.cdpHeader = headerParser(process.env.PLAYWRIGHT_MCP_CDP_HEADERS, {});
166
172
  options.config = envToString(process.env.PLAYWRIGHT_MCP_CONFIG);
167
173
  options.device = envToString(process.env.PLAYWRIGHT_MCP_DEVICE);
168
174
  options.executablePath = envToString(process.env.PLAYWRIGHT_MCP_EXECUTABLE_PATH);
@@ -178,6 +184,7 @@ function configFromEnv() {
178
184
  options.proxyBypass = envToString(process.env.PLAYWRIGHT_MCP_PROXY_BYPASS);
179
185
  options.proxyServer = envToString(process.env.PLAYWRIGHT_MCP_PROXY_SERVER);
180
186
  options.saveTrace = envToBoolean(process.env.PLAYWRIGHT_MCP_SAVE_TRACE);
187
+ options.secrets = dotenvFileLoader(process.env.PLAYWRIGHT_MCP_SECRETS_FILE);
181
188
  options.storageState = envToString(process.env.PLAYWRIGHT_MCP_STORAGE_STATE);
182
189
  options.userAgent = envToString(process.env.PLAYWRIGHT_MCP_USER_AGENT);
183
190
  options.userDataDir = envToString(process.env.PLAYWRIGHT_MCP_USER_DATA_DIR);
@@ -246,6 +253,19 @@ function commaSeparatedList(value) {
246
253
  return void 0;
247
254
  return value.split(",").map((v) => v.trim());
248
255
  }
256
+ function dotenvFileLoader(value) {
257
+ if (!value)
258
+ return void 0;
259
+ return import_utilsBundle.dotenv.parse(import_fs.default.readFileSync(value, "utf8"));
260
+ }
261
+ function headerParser(arg, previous) {
262
+ if (!arg)
263
+ return previous || {};
264
+ const result = previous || {};
265
+ const [name, value] = arg.split(":").map((v) => v.trim());
266
+ result[name] = value;
267
+ return result;
268
+ }
249
269
  function envToNumber(value) {
250
270
  if (!value)
251
271
  return void 0;
@@ -272,6 +292,8 @@ function sanitizeForFilePath(s) {
272
292
  0 && (module.exports = {
273
293
  commaSeparatedList,
274
294
  configFromCLIOptions,
295
+ dotenvFileLoader,
296
+ headerParser,
275
297
  outputFile,
276
298
  resolveCLIConfig,
277
299
  resolveConfig,
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var context_exports = {};
20
30
  __export(context_exports, {
@@ -26,6 +36,7 @@ var import_utilsBundle = require("playwright-core/lib/utilsBundle");
26
36
  var import_log = require("../log");
27
37
  var import_tab = require("./tab");
28
38
  var import_config = require("./config");
39
+ var codegen = __toESM(require("./codegen"));
29
40
  const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
30
41
  class Context {
31
42
  constructor(options) {
@@ -174,6 +185,14 @@ class Context {
174
185
  }
175
186
  return result;
176
187
  }
188
+ lookupSecret(secretName) {
189
+ if (!this.config.secrets?.[secretName])
190
+ return { value: secretName, code: codegen.quote(secretName) };
191
+ return {
192
+ value: this.config.secrets[secretName],
193
+ code: `process.env['${secretName}']`
194
+ };
195
+ }
177
196
  }
178
197
  class InputRecorder {
179
198
  constructor(context, browserContext) {
@@ -0,0 +1,87 @@
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
+ });
@@ -103,8 +103,19 @@ ${this._code.join("\n")}
103
103
  for (const image of this._images)
104
104
  content.push({ type: "image", data: image.data.toString("base64"), mimeType: image.contentType });
105
105
  }
106
+ this._redactSecrets(content);
106
107
  return { content, isError: this._isError };
107
108
  }
109
+ _redactSecrets(content) {
110
+ if (!this._context.config.secrets)
111
+ return;
112
+ for (const item of content) {
113
+ if (item.type !== "text")
114
+ continue;
115
+ for (const [secretName, secretValue] of Object.entries(this._context.config.secrets))
116
+ item.text = item.text.replaceAll(secretValue, `<secret>${secretName}</secret>`);
117
+ }
118
+ }
108
119
  }
109
120
  function renderTabSnapshot(tabSnapshot) {
110
121
  const lines = [];
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(form_exports);
34
34
  var import_bundle = require("../../sdk/bundle");
35
35
  var import_tool = require("./tool");
36
36
  var import_utils = require("./utils");
37
- var javascript = __toESM(require("../codegen"));
37
+ var codegen = __toESM(require("../codegen"));
38
38
  const fillForm = (0, import_tool.defineTabTool)({
39
39
  capability: "core",
40
40
  schema: {
@@ -56,14 +56,15 @@ const fillForm = (0, import_tool.defineTabTool)({
56
56
  const locator = await tab.refLocator({ element: field.name, ref: field.ref });
57
57
  const locatorSource = `await page.${await (0, import_utils.generateLocator)(locator)}`;
58
58
  if (field.type === "textbox" || field.type === "slider") {
59
- await locator.fill(field.value);
60
- response.addCode(`${locatorSource}.fill(${javascript.quote(field.value)});`);
59
+ const secret = tab.context.lookupSecret(field.value);
60
+ await locator.fill(secret.value);
61
+ response.addCode(`${locatorSource}.fill(${secret.code});`);
61
62
  } else if (field.type === "checkbox" || field.type === "radio") {
62
63
  await locator.setChecked(field.value === "true");
63
- response.addCode(`${locatorSource}.setChecked(${javascript.quote(field.value)});`);
64
+ response.addCode(`${locatorSource}.setChecked(${field.value});`);
64
65
  } else if (field.type === "combobox") {
65
66
  await locator.selectOption({ label: field.value });
66
- response.addCode(`${locatorSource}.selectOption(${javascript.quote(field.value)});`);
67
+ response.addCode(`${locatorSource}.selectOption(${codegen.quote(field.value)});`);
67
68
  }
68
69
  }
69
70
  }
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var keyboard_exports = {};
30
20
  __export(keyboard_exports, {
@@ -35,7 +25,6 @@ var import_bundle = require("../../sdk/bundle");
35
25
  var import_tool = require("./tool");
36
26
  var import_snapshot = require("./snapshot");
37
27
  var import_utils = require("./utils");
38
- var javascript = __toESM(require("../codegen"));
39
28
  const pressKey = (0, import_tool.defineTabTool)({
40
29
  capability: "core",
41
30
  schema: {
@@ -72,14 +61,15 @@ const type = (0, import_tool.defineTabTool)({
72
61
  },
73
62
  handle: async (tab, params, response) => {
74
63
  const locator = await tab.refLocator(params);
64
+ const secret = tab.context.lookupSecret(params.text);
75
65
  await tab.waitForCompletion(async () => {
76
66
  if (params.slowly) {
77
67
  response.setIncludeSnapshot();
78
- response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.pressSequentially(${javascript.quote(params.text)});`);
79
- await locator.pressSequentially(params.text);
68
+ response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.pressSequentially(${secret.code});`);
69
+ await locator.pressSequentially(secret.value);
80
70
  } else {
81
- response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.fill(${javascript.quote(params.text)});`);
82
- await locator.fill(params.text);
71
+ response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.fill(${secret.code});`);
72
+ await locator.fill(secret.value);
83
73
  }
84
74
  if (params.submit) {
85
75
  response.setIncludeSnapshot();
@@ -30,7 +30,7 @@ var import_proxyBackend = require("./sdk/proxyBackend");
30
30
  var import_browserServerBackend = require("./browser/browserServerBackend");
31
31
  var import_extensionContextFactory = require("./extension/extensionContextFactory");
32
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("--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("--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) => {
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
34
  setupExitWatchdog();
35
35
  if (options.vision) {
36
36
  console.error("The --vision option is deprecated, use --caps=vision instead");