@one2x/playwright 1.57.0-alpha.3 → 1.57.0-alpha.4

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.
@@ -166,7 +166,8 @@ function configFromCLIOptions(cliOptions) {
166
166
  contextOptions,
167
167
  cdpEndpoint: cliOptions.cdpEndpoint,
168
168
  cdpHeaders: cliOptions.cdpHeader,
169
- initScript: cliOptions.initScript
169
+ initScript: cliOptions.initScript,
170
+ autoScreenshot: cliOptions.autoScreenshot
170
171
  },
171
172
  server: {
172
173
  port: cliOptions.port,
@@ -197,6 +198,7 @@ function configFromEnv() {
197
198
  const options = {};
198
199
  options.allowedHosts = commaSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_HOSTNAMES);
199
200
  options.allowedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_ORIGINS);
201
+ options.autoScreenshot = envToBoolean(process.env.PLAYWRIGHT_MCP_AUTO_SCREENSHOT);
200
202
  options.blockedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_BLOCKED_ORIGINS);
201
203
  options.blockServiceWorkers = envToBoolean(process.env.PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERS);
202
204
  options.browser = envToString(process.env.PLAYWRIGHT_MCP_BROWSER);
@@ -374,6 +376,7 @@ function configFromURLParams(url) {
374
376
  const getParam = (name) => url.searchParams.get(name) || void 0;
375
377
  const options = {};
376
378
  options.allowedOrigins = semicolonSeparatedList(getParam("allowed-origins"));
379
+ options.autoScreenshot = queryToBoolean(getParam("auto-screenshot"));
377
380
  options.blockedOrigins = semicolonSeparatedList(getParam("blocked-origins"));
378
381
  options.blockServiceWorkers = queryToBoolean(getParam("block-service-workers"));
379
382
  options.browser = getParam("browser");
@@ -25,6 +25,7 @@ __export(response_exports, {
25
25
  module.exports = __toCommonJS(response_exports);
26
26
  var import_utilsBundle = require("playwright-core/lib/utilsBundle");
27
27
  var import_tab = require("./tab");
28
+ var import_screenshot = require("./tools/screenshot");
28
29
  const requestDebug = (0, import_utilsBundle.debug)("pw:mcp:request");
29
30
  class Response {
30
31
  constructor(context, toolName, toolArgs) {
@@ -33,6 +34,7 @@ class Response {
33
34
  this._images = [];
34
35
  this._includeSnapshot = "none";
35
36
  this._includeTabs = false;
37
+ this._includeAutoScreenshot = false;
36
38
  this._context = context;
37
39
  this.toolName = toolName;
38
40
  this.toolArgs = toolArgs;
@@ -65,6 +67,9 @@ class Response {
65
67
  setIncludeSnapshot(full) {
66
68
  this._includeSnapshot = full ?? "incremental";
67
69
  }
70
+ setIncludeAutoScreenshot() {
71
+ this._includeAutoScreenshot = true;
72
+ }
68
73
  setIncludeTabs() {
69
74
  this._includeTabs = true;
70
75
  }
@@ -73,6 +78,14 @@ class Response {
73
78
  this._tabSnapshot = await this._context.currentTabOrDie().captureSnapshot(this._includeSnapshot);
74
79
  for (const tab of this._context.tabs())
75
80
  await tab.updateTitle();
81
+ if (this._includeAutoScreenshot && this._context.config.browser?.autoScreenshot && this._context.config.imageResponses !== "omit" && this._context.currentTab()) {
82
+ const tab = this._context.currentTabOrDie();
83
+ await tab.page.waitForLoadState("networkidle", { timeout: 1e3 }).catch(() => {
84
+ });
85
+ const buffer = await tab.page.screenshot({ type: "jpeg", quality: 90, scale: "css" });
86
+ const scaledBuffer = (0, import_screenshot.scaleImageToFitMessage)(buffer, "jpeg");
87
+ this.addImage({ contentType: "image/jpeg", data: scaledBuffer });
88
+ }
76
89
  }
77
90
  tabSnapshot() {
78
91
  return this._tabSnapshot;
@@ -147,7 +147,7 @@ class Tab extends import_events.EventEmitter {
147
147
  this._clearCollectedArtifacts();
148
148
  const downloadEvent = (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForEvent("download").catch(import_log.logUnhandledError));
149
149
  try {
150
- await this.page.goto(url, { waitUntil: "domcontentloaded" });
150
+ await this.page.goto(url, { waitUntil: this.context.config.browser?.autoScreenshot ? "load" : "domcontentloaded" });
151
151
  } catch (_e) {
152
152
  const e = _e;
153
153
  const mightBeDownload = e.message.includes("net::ERR_ABORTED") || e.message.includes("Download is starting");
@@ -62,6 +62,7 @@ const evaluate = (0, import_tool.defineTabTool)({
62
62
  const result = await receiver._evaluateFunction(params.function);
63
63
  response.addResult(JSON.stringify(result, null, 2) || "undefined");
64
64
  });
65
+ response.setIncludeAutoScreenshot();
65
66
  }
66
67
  });
67
68
  var evaluate_default = [
@@ -72,6 +72,7 @@ const fillForm = (0, import_tool.defineTabTool)({
72
72
  response.addCode(`${locatorSource}.selectOption(${codegen.quote(field.value)});`);
73
73
  }
74
74
  }
75
+ response.setIncludeAutoScreenshot();
75
76
  }
76
77
  });
77
78
  var form_default = [
@@ -42,6 +42,7 @@ const pressKey = (0, import_tool.defineTabTool)({
42
42
  await tab.waitForCompletion(async () => {
43
43
  await tab.page.keyboard.press(params.key);
44
44
  });
45
+ response.setIncludeAutoScreenshot();
45
46
  }
46
47
  });
47
48
  const typeSchema = import_snapshot.elementSchema.extend({
@@ -76,6 +77,7 @@ const type = (0, import_tool.defineTabTool)({
76
77
  await locator.press("Enter");
77
78
  }
78
79
  });
80
+ response.setIncludeAutoScreenshot();
79
81
  }
80
82
  });
81
83
  var keyboard_default = [
@@ -69,6 +69,7 @@ const mouseClick = (0, import_tool.defineTabTool)({
69
69
  await tab.page.mouse.down();
70
70
  await tab.page.mouse.up();
71
71
  });
72
+ response.setIncludeAutoScreenshot();
72
73
  }
73
74
  });
74
75
  const mouseDrag = (0, import_tool.defineTabTool)({
@@ -98,6 +99,7 @@ const mouseDrag = (0, import_tool.defineTabTool)({
98
99
  await tab.page.mouse.move(params.endX, params.endY);
99
100
  await tab.page.mouse.up();
100
101
  });
102
+ response.setIncludeAutoScreenshot();
101
103
  }
102
104
  });
103
105
  var mouse_default = [
@@ -39,6 +39,7 @@ const navigate = (0, import_tool.defineTool)({
39
39
  await tab.navigate(params.url);
40
40
  response.setIncludeSnapshot();
41
41
  response.addCode(`await page.goto('${params.url}');`);
42
+ response.setIncludeAutoScreenshot();
42
43
  }
43
44
  });
44
45
  const goBack = (0, import_tool.defineTabTool)({
@@ -54,6 +55,7 @@ const goBack = (0, import_tool.defineTabTool)({
54
55
  await tab.page.goBack();
55
56
  response.setIncludeSnapshot();
56
57
  response.addCode(`await page.goBack();`);
58
+ response.setIncludeAutoScreenshot();
57
59
  }
58
60
  });
59
61
  var navigate_default = [
@@ -96,6 +96,7 @@ const click = (0, import_tool.defineTabTool)({
96
96
  response.addCode(`await page.${resolved}.dblclick(${optionsAttr});`);
97
97
  else
98
98
  response.addCode(`await page.${resolved}.click(${optionsAttr});`);
99
+ response.setIncludeAutoScreenshot();
99
100
  }
100
101
  });
101
102
  const drag = (0, import_tool.defineTabTool)({
@@ -128,6 +129,7 @@ const drag = (0, import_tool.defineTabTool)({
128
129
  });
129
130
  const optionsAttr = usedAllowIntercept ? ", { allowIntercept: true }" : "";
130
131
  response.addCode(`await page.${start.resolved}.dragTo(page.${end.resolved}${optionsAttr});`);
132
+ response.setIncludeAutoScreenshot();
131
133
  }
132
134
  });
133
135
  const hover = (0, import_tool.defineTabTool)({
@@ -152,6 +154,7 @@ const hover = (0, import_tool.defineTabTool)({
152
154
  });
153
155
  const optionsAttr = usedAllowIntercept ? "{ allowIntercept: true }" : "";
154
156
  response.addCode(`await page.${resolved}.hover(${optionsAttr});`);
157
+ response.setIncludeAutoScreenshot();
155
158
  }
156
159
  });
157
160
  const selectOptionSchema = elementSchema.extend({
@@ -173,6 +176,7 @@ const selectOption = (0, import_tool.defineTabTool)({
173
176
  await tab.waitForCompletion(async () => {
174
177
  await locator.selectOption(params.values);
175
178
  });
179
+ response.setIncludeAutoScreenshot();
176
180
  }
177
181
  });
178
182
  const pickLocator = (0, import_tool.defineTabTool)({
@@ -50,6 +50,7 @@ const browserTabs = (0, import_tool.defineTool)({
50
50
  case "close": {
51
51
  await context.closeTab(params.index);
52
52
  response.setIncludeSnapshot("full");
53
+ response.setIncludeAutoScreenshot();
53
54
  return;
54
55
  }
55
56
  case "select": {
@@ -57,6 +58,7 @@ const browserTabs = (0, import_tool.defineTool)({
57
58
  throw new Error("Tab index is required");
58
59
  await context.selectTab(params.index);
59
60
  response.setIncludeSnapshot("full");
61
+ response.setIncludeAutoScreenshot();
60
62
  return;
61
63
  }
62
64
  }
@@ -56,6 +56,7 @@ const wait = (0, import_tool.defineTool)({
56
56
  }
57
57
  response.addResult(`Waited for ${params.text || params.textGone || params.time}`);
58
58
  response.setIncludeSnapshot();
59
+ response.setIncludeAutoScreenshot();
59
60
  }
60
61
  });
61
62
  var wait_default = [
@@ -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("--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("--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-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 origins to allow the browser to request. Default is to allow all.", import_config.semicolonSeparatedList).option("--auto-screenshot", "automatically capture viewport screenshot after DOM changes").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("--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-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");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@one2x/playwright",
3
- "version": "1.57.0-alpha.3",
3
+ "version": "1.57.0-alpha.4",
4
4
  "description": "A high-level API to automate web browsers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -65,7 +65,7 @@
65
65
  "license": "Apache-2.0",
66
66
  "dependencies": {
67
67
  "content-type": "^1.0.5",
68
- "playwright-core": "npm:@one2x/playwright-core@1.57.0-alpha.3",
68
+ "playwright-core": "npm:@one2x/playwright-core@1.57.0-alpha.4",
69
69
  "raw-body": "^2.5.2"
70
70
  },
71
71
  "optionalDependencies": {