playwright 1.58.0-alpha-2025-11-21 → 1.58.0-alpha-1763757971000

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,8 @@ __export(config_exports, {
38
38
  outputFile: () => outputFile,
39
39
  resolutionParser: () => resolutionParser,
40
40
  resolveCLIConfig: () => resolveCLIConfig,
41
- resolveConfig: () => resolveConfig
41
+ resolveConfig: () => resolveConfig,
42
+ semicolonSeparatedList: () => semicolonSeparatedList
42
43
  });
43
44
  module.exports = __toCommonJS(config_exports);
44
45
  var import_fs = __toESM(require("fs"));
@@ -60,6 +61,10 @@ const defaultConfig = {
60
61
  viewport: null
61
62
  }
62
63
  },
64
+ network: {
65
+ allowedOrigins: void 0,
66
+ blockedOrigins: void 0
67
+ },
63
68
  server: {},
64
69
  saveTrace: false,
65
70
  timeouts: {
@@ -88,6 +93,12 @@ async function validateConfig(config) {
88
93
  throw new Error(`Init script file does not exist: ${script}`);
89
94
  }
90
95
  }
96
+ if (config.browser.initPage) {
97
+ for (const page of config.browser.initPage) {
98
+ if (!await (0, import_util.fileExistsAsync)(page))
99
+ throw new Error(`Init page file does not exist: ${page}`);
100
+ }
101
+ }
91
102
  if (config.sharedBrowserContext && config.saveVideo)
92
103
  throw new Error("saveVideo is not supported when sharedBrowserContext is true");
93
104
  }
@@ -168,6 +179,10 @@ function configFromCLIOptions(cliOptions) {
168
179
  allowedHosts: cliOptions.allowedHosts
169
180
  },
170
181
  capabilities: cliOptions.caps,
182
+ network: {
183
+ allowedOrigins: cliOptions.allowedOrigins,
184
+ blockedOrigins: cliOptions.blockedOrigins
185
+ },
171
186
  saveSession: cliOptions.saveSession,
172
187
  saveTrace: cliOptions.saveTrace,
173
188
  saveVideo: cliOptions.saveVideo,
@@ -186,6 +201,8 @@ function configFromCLIOptions(cliOptions) {
186
201
  function configFromEnv() {
187
202
  const options = {};
188
203
  options.allowedHosts = commaSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_HOSTNAMES);
204
+ options.allowedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_ORIGINS);
205
+ options.blockedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_BLOCKED_ORIGINS);
189
206
  options.blockServiceWorkers = envToBoolean(process.env.PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERS);
190
207
  options.browser = envToString(process.env.PLAYWRIGHT_MCP_BROWSER);
191
208
  options.caps = commaSeparatedList(process.env.PLAYWRIGHT_MCP_CAPS);
@@ -285,6 +302,10 @@ function mergeConfig(base, overrides) {
285
302
  ...pickDefined(base),
286
303
  ...pickDefined(overrides),
287
304
  browser,
305
+ network: {
306
+ ...pickDefined(base.network),
307
+ ...pickDefined(overrides.network)
308
+ },
288
309
  server: {
289
310
  ...pickDefined(base.server),
290
311
  ...pickDefined(overrides.server)
@@ -295,6 +316,11 @@ function mergeConfig(base, overrides) {
295
316
  }
296
317
  };
297
318
  }
319
+ function semicolonSeparatedList(value) {
320
+ if (!value)
321
+ return void 0;
322
+ return value.split(";").map((v) => v.trim());
323
+ }
298
324
  function commaSeparatedList(value) {
299
325
  if (!value)
300
326
  return void 0;
@@ -364,5 +390,6 @@ function sanitizeForFilePath(s) {
364
390
  outputFile,
365
391
  resolutionParser,
366
392
  resolveCLIConfig,
367
- resolveConfig
393
+ resolveConfig,
394
+ semicolonSeparatedList
368
395
  });
@@ -75,7 +75,6 @@ class Context {
75
75
  const { browserContext } = await this._ensureBrowserContext();
76
76
  const page = await browserContext.newPage();
77
77
  this._currentTab = this._tabs.find((t) => t.page === page);
78
- await this._currentTab.initializedPromise;
79
78
  return this._currentTab;
80
79
  }
81
80
  async selectTab(index) {
@@ -169,6 +168,17 @@ class Context {
169
168
  await this.closeBrowserContext();
170
169
  Context._allContexts.delete(this);
171
170
  }
171
+ async _setupRequestInterception(context) {
172
+ if (this.config.network?.allowedOrigins?.length) {
173
+ await context.route("**", (route) => route.abort("blockedbyclient"));
174
+ for (const origin of this.config.network.allowedOrigins)
175
+ await context.route(originOrHostGlob(origin), (route) => route.continue());
176
+ }
177
+ if (this.config.network?.blockedOrigins?.length) {
178
+ for (const origin of this.config.network.blockedOrigins)
179
+ await context.route(originOrHostGlob(origin), (route) => route.abort("blockedbyclient"));
180
+ }
181
+ }
172
182
  async ensureBrowserContext() {
173
183
  const { browserContext } = await this._ensureBrowserContext();
174
184
  return browserContext;
@@ -189,6 +199,7 @@ class Context {
189
199
  import_playwright_core.selectors.setTestIdAttribute(this.config.testIdAttribute);
190
200
  const result = await this._browserContextFactory.createContext(this._clientInfo, this._abortController.signal, this._runningToolName);
191
201
  const { browserContext } = result;
202
+ await this._setupRequestInterception(browserContext);
192
203
  if (this.sessionLog)
193
204
  await InputRecorder.create(this, browserContext);
194
205
  for (const page of browserContext.pages())
@@ -213,6 +224,15 @@ class Context {
213
224
  };
214
225
  }
215
226
  }
227
+ function originOrHostGlob(originOrHost) {
228
+ try {
229
+ const url = new URL(originOrHost);
230
+ if (url.origin !== "null")
231
+ return `${url.origin}/**`;
232
+ } catch {
233
+ }
234
+ return `*://${originOrHost}/**`;
235
+ }
216
236
  class InputRecorder {
217
237
  constructor(context, browserContext) {
218
238
  this._context = context;
@@ -65,7 +65,7 @@ class Tab extends import_events.EventEmitter {
65
65
  page.setDefaultNavigationTimeout(this.context.config.timeouts.navigation);
66
66
  page.setDefaultTimeout(this.context.config.timeouts.action);
67
67
  page[tabSymbol] = this;
68
- this.initializedPromise = this._initialize();
68
+ this._initializedPromise = this._initialize();
69
69
  }
70
70
  static forPage(page) {
71
71
  return page[tabSymbol];
@@ -151,9 +151,11 @@ class Tab extends import_events.EventEmitter {
151
151
  return this === this.context.currentTab();
152
152
  }
153
153
  async waitForLoadState(state, options) {
154
+ await this._initializedPromise;
154
155
  await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForLoadState(state, options).catch(import_log.logUnhandledError));
155
156
  }
156
157
  async navigate(url) {
158
+ await this._initializedPromise;
157
159
  this._clearCollectedArtifacts();
158
160
  const downloadEvent = (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForEvent("download").catch(import_log.logUnhandledError));
159
161
  try {
@@ -175,14 +177,15 @@ class Tab extends import_events.EventEmitter {
175
177
  await this.waitForLoadState("load", { timeout: 5e3 });
176
178
  }
177
179
  async consoleMessages(type) {
178
- await this.initializedPromise;
180
+ await this._initializedPromise;
179
181
  return this._consoleMessages.filter((message) => type ? message.type === type : true);
180
182
  }
181
183
  async requests() {
182
- await this.initializedPromise;
184
+ await this._initializedPromise;
183
185
  return this._requests;
184
186
  }
185
187
  async captureSnapshot() {
188
+ await this._initializedPromise;
186
189
  let tabSnapshot;
187
190
  const modalStates = await this._raceAgainstModalStates(async () => {
188
191
  const snapshot = await this.page._snapshotForAI({ track: "response" });
@@ -228,12 +231,15 @@ class Tab extends import_events.EventEmitter {
228
231
  ]);
229
232
  }
230
233
  async waitForCompletion(callback) {
234
+ await this._initializedPromise;
231
235
  await this._raceAgainstModalStates(() => (0, import_utils2.waitForCompletion)(this, callback));
232
236
  }
233
237
  async refLocator(params) {
238
+ await this._initializedPromise;
234
239
  return (await this.refLocators([params]))[0];
235
240
  }
236
241
  async refLocators(params) {
242
+ await this._initializedPromise;
237
243
  return Promise.all(params.map(async (param) => {
238
244
  try {
239
245
  const locator = this.page.locator(`aria-ref=${param.ref}`).describe(param.element);
@@ -250,7 +256,8 @@ class Tab extends import_events.EventEmitter {
250
256
  return;
251
257
  }
252
258
  await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => {
253
- return page.evaluate(() => new Promise((f) => setTimeout(f, 1e3)));
259
+ return page.evaluate(() => new Promise((f) => setTimeout(f, 1e3))).catch(() => {
260
+ });
254
261
  });
255
262
  }
256
263
  }
@@ -42,7 +42,7 @@ var import_proxyBackend = require("./sdk/proxyBackend");
42
42
  var import_browserServerBackend = require("./browser/browserServerBackend");
43
43
  var import_extensionContextFactory = require("./extension/extensionContextFactory");
44
44
  function decorateCommand(command, version) {
45
- command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).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("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).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("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").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("--save-video <size>", 'Whether to save the video of the session into the output directory. For example "--save-video=800x600"', import_config.resolutionParser.bind(null, "--save-video")).option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--shared-browser-context", "reuse the same browser context between all connected HTTP clients.").option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--test-id-attribute <attribute>", 'specify the attribute to use for test ids, defaults to "data-testid"').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 "1280x720"', import_config.resolutionParser.bind(null, "--viewport-size")).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) => {
45
+ command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).option("--allowed-origins <origins>", "semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all.\nImportant: *does not* serve as a security boundary and *does not* affect redirects. ", 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.\nImportant: *does not* serve as a security boundary and *does not* affect redirects.", 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("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).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("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").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("--save-video <size>", 'Whether to save the video of the session into the output directory. For example "--save-video=800x600"', import_config.resolutionParser.bind(null, "--save-video")).option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--shared-browser-context", "reuse the same browser context between all connected HTTP clients.").option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--test-id-attribute <attribute>", 'specify the attribute to use for test ids, defaults to "data-testid"').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 "1280x720"', import_config.resolutionParser.bind(null, "--viewport-size")).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) => {
46
46
  (0, import_watchdog.setupExitWatchdog)();
47
47
  if (options.vision) {
48
48
  console.error("The --vision option is deprecated, use --caps=vision instead");
@@ -51,6 +51,9 @@ class ProcessHost extends import_events.EventEmitter {
51
51
  async startRunner(runnerParams, options = {}) {
52
52
  (0, import_utils.assert)(!this.process, "Internal error: starting the same process twice");
53
53
  this.process = import_child_process.default.fork(require.resolve("../common/process"), {
54
+ // Note: we pass detached:false, so that workers are in the same process group.
55
+ // This way Ctrl+C or a kill command can shutdown all workers in case they misbehave.
56
+ // Otherwise user can end up with a bunch of workers stuck in a busy loop without self-destructing.
54
57
  detached: false,
55
58
  env: {
56
59
  ...process.env,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright",
3
- "version": "1.58.0-alpha-2025-11-21",
3
+ "version": "1.58.0-alpha-1763757971000",
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.58.0-alpha-2025-11-21"
67
+ "playwright-core": "1.58.0-alpha-1763757971000"
68
68
  },
69
69
  "optionalDependencies": {
70
70
  "fsevents": "2.3.2"