playwright 1.57.0-alpha-2025-10-14 → 1.57.0-alpha-2025-10-15

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.
@@ -260,7 +260,7 @@ async function resolveFile(config, clientInfo, fileName, options) {
260
260
  fileName = fileName.split("\\").join("/");
261
261
  const resolvedFile = import_path.default.resolve(dir, fileName);
262
262
  if (!resolvedFile.startsWith(import_path.default.resolve(dir) + import_path.default.sep))
263
- throw new Error(`Resolved file path for ${fileName} is outside of the output directory`);
263
+ throw new Error(`Resolved file path ${resolvedFile} is outside of the output directory ${dir}. Use relative file names to stay within the output directory.`);
264
264
  return resolvedFile;
265
265
  }
266
266
  return import_path.default.join(dir, sanitizeForFilePath(fileName));
@@ -36,7 +36,7 @@ var import_tool = require("./tool");
36
36
  var javascript = __toESM(require("../codegen"));
37
37
  var import_utils = require("./utils");
38
38
  const pdfSchema = import_bundle.z.object({
39
- filename: import_bundle.z.string().optional().describe("File name to save the pdf to. Defaults to `page-{timestamp}.pdf` if not specified.")
39
+ filename: import_bundle.z.string().optional().describe("File name to save the pdf to. Defaults to `page-{timestamp}.pdf` if not specified. Prefer relative file names to stay within the output directory.")
40
40
  });
41
41
  const pdf = (0, import_tool.defineTabTool)({
42
42
  capability: "pdf",
@@ -28,16 +28,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var screenshot_exports = {};
30
30
  __export(screenshot_exports, {
31
- default: () => screenshot_default
31
+ default: () => screenshot_default,
32
+ scaleImageToFitMessage: () => scaleImageToFitMessage
32
33
  });
33
34
  module.exports = __toCommonJS(screenshot_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_utils = require("playwright-core/lib/utils");
37
+ var import_utilsBundle = require("playwright-core/lib/utilsBundle");
34
38
  var import_bundle = require("../../sdk/bundle");
35
39
  var import_tool = require("./tool");
36
40
  var javascript = __toESM(require("../codegen"));
37
- var import_utils = require("./utils");
41
+ var import_utils2 = require("./utils");
38
42
  const screenshotSchema = import_bundle.z.object({
39
43
  type: import_bundle.z.enum(["png", "jpeg"]).default("png").describe("Image format for the screenshot. Default is png."),
40
- filename: import_bundle.z.string().optional().describe("File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified."),
44
+ filename: import_bundle.z.string().optional().describe("File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified. Prefer relative file names to stay within the output directory."),
41
45
  element: import_bundle.z.string().optional().describe("Human-readable element description used to obtain permission to screenshot the element. If not provided, the screenshot will be taken of viewport. If element is provided, ref must be provided too."),
42
46
  ref: import_bundle.z.string().optional().describe("Exact target element reference from the page snapshot. If not provided, the screenshot will be taken of viewport. If ref is provided, element must be provided too."),
43
47
  fullPage: import_bundle.z.boolean().optional().describe("When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Cannot be used with element screenshots.")
@@ -57,12 +61,11 @@ const screenshot = (0, import_tool.defineTabTool)({
57
61
  if (params.fullPage && params.ref)
58
62
  throw new Error("fullPage cannot be used with element screenshots.");
59
63
  const fileType = params.type || "png";
60
- const fileName = await tab.context.outputFile(params.filename ?? (0, import_utils.dateAsFileName)(fileType), { origin: "llm", reason: "Saving screenshot" });
64
+ const fileName = await tab.context.outputFile(params.filename ?? (0, import_utils2.dateAsFileName)(fileType), { origin: "llm", reason: "Saving screenshot" });
61
65
  const options = {
62
66
  type: fileType,
63
67
  quality: fileType === "png" ? void 0 : 90,
64
68
  scale: "css",
65
- path: fileName,
66
69
  ...params.fullPage !== void 0 && { fullPage: params.fullPage }
67
70
  };
68
71
  const isElementScreenshot = params.element && params.ref;
@@ -74,15 +77,30 @@ const screenshot = (0, import_tool.defineTabTool)({
74
77
  else
75
78
  response.addCode(`await page.screenshot(${javascript.formatObject(options)});`);
76
79
  const buffer = ref ? await ref.locator.screenshot(options) : await tab.page.screenshot(options);
80
+ await (0, import_utils.mkdirIfNeeded)(fileName);
81
+ await import_fs.default.promises.writeFile(fileName, buffer);
77
82
  response.addResult(`Took the ${screenshotTarget} screenshot and saved it as ${fileName}`);
78
- if (!params.fullPage) {
79
- response.addImage({
80
- contentType: fileType === "png" ? "image/png" : "image/jpeg",
81
- data: buffer
82
- });
83
- }
83
+ response.addImage({
84
+ contentType: fileType === "png" ? "image/png" : "image/jpeg",
85
+ data: scaleImageToFitMessage(buffer, fileType)
86
+ });
84
87
  }
85
88
  });
89
+ function scaleImageToFitMessage(buffer, imageType) {
90
+ const image = imageType === "png" ? import_utilsBundle.PNG.sync.read(buffer) : import_utilsBundle.jpegjs.decode(buffer, { maxMemoryUsageInMB: 512 });
91
+ const pixels = image.width * image.height;
92
+ const shrink = Math.min(1568 / image.width, 1568 / image.height, Math.sqrt(1.15 * 1024 * 1024 / pixels));
93
+ if (shrink > 1)
94
+ return buffer;
95
+ const width = image.width * shrink | 0;
96
+ const height = image.height * shrink | 0;
97
+ const scaledImage = (0, import_utils.scaleImageToSize)(image, { width, height });
98
+ return imageType === "png" ? import_utilsBundle.PNG.sync.write(scaledImage) : import_utilsBundle.jpegjs.encode(scaledImage, 80).data;
99
+ }
86
100
  var screenshot_default = [
87
101
  screenshot
88
102
  ];
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ scaleImageToFitMessage
106
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright",
3
- "version": "1.57.0-alpha-2025-10-14",
3
+ "version": "1.57.0-alpha-2025-10-15",
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.57.0-alpha-2025-10-14"
67
+ "playwright-core": "1.57.0-alpha-2025-10-15"
68
68
  },
69
69
  "optionalDependencies": {
70
70
  "fsevents": "2.3.2"