playwright 1.57.0-alpha-2025-10-13 → 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.
- package/lib/mcp/browser/config.js +1 -1
- package/lib/mcp/browser/response.js +6 -6
- package/lib/mcp/browser/tab.js +2 -2
- package/lib/mcp/browser/tools/pdf.js +1 -1
- package/lib/mcp/browser/tools/screenshot.js +29 -11
- package/lib/mcp/browser/tools/snapshot.js +1 -1
- package/lib/mcp/browser/tools/tabs.js +2 -2
- package/lib/worker/testInfo.js +7 -1
- package/package.json +2 -2
|
@@ -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
|
|
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));
|
|
@@ -31,7 +31,7 @@ class Response {
|
|
|
31
31
|
this._result = [];
|
|
32
32
|
this._code = [];
|
|
33
33
|
this._images = [];
|
|
34
|
-
this._includeSnapshot =
|
|
34
|
+
this._includeSnapshot = "none";
|
|
35
35
|
this._includeTabs = false;
|
|
36
36
|
this._context = context;
|
|
37
37
|
this.toolName = toolName;
|
|
@@ -62,15 +62,15 @@ class Response {
|
|
|
62
62
|
images() {
|
|
63
63
|
return this._images;
|
|
64
64
|
}
|
|
65
|
-
setIncludeSnapshot() {
|
|
66
|
-
this._includeSnapshot =
|
|
65
|
+
setIncludeSnapshot(full) {
|
|
66
|
+
this._includeSnapshot = full ?? "incremental";
|
|
67
67
|
}
|
|
68
68
|
setIncludeTabs() {
|
|
69
69
|
this._includeTabs = true;
|
|
70
70
|
}
|
|
71
71
|
async finish() {
|
|
72
|
-
if (this._includeSnapshot && this._context.currentTab())
|
|
73
|
-
this._tabSnapshot = await this._context.currentTabOrDie().captureSnapshot();
|
|
72
|
+
if (this._includeSnapshot !== "none" && this._context.currentTab())
|
|
73
|
+
this._tabSnapshot = await this._context.currentTabOrDie().captureSnapshot(this._includeSnapshot);
|
|
74
74
|
for (const tab of this._context.tabs())
|
|
75
75
|
await tab.updateTitle();
|
|
76
76
|
}
|
|
@@ -99,7 +99,7 @@ ${this._code.join("\n")}
|
|
|
99
99
|
\`\`\``);
|
|
100
100
|
response.push("");
|
|
101
101
|
}
|
|
102
|
-
if (this._includeSnapshot || this._includeTabs)
|
|
102
|
+
if (this._includeSnapshot !== "none" || this._includeTabs)
|
|
103
103
|
response.push(...renderTabsMarkdown(this._context.tabs(), this._includeTabs));
|
|
104
104
|
if (this._tabSnapshot?.modalStates.length) {
|
|
105
105
|
response.push(...(0, import_tab.renderModalStates)(this._context, this._tabSnapshot.modalStates));
|
package/lib/mcp/browser/tab.js
CHANGED
|
@@ -172,10 +172,10 @@ class Tab extends import_events.EventEmitter {
|
|
|
172
172
|
await this._initializedPromise;
|
|
173
173
|
return this._requests;
|
|
174
174
|
}
|
|
175
|
-
async captureSnapshot() {
|
|
175
|
+
async captureSnapshot(mode) {
|
|
176
176
|
let tabSnapshot;
|
|
177
177
|
const modalStates = await this._raceAgainstModalStates(async () => {
|
|
178
|
-
const snapshot = await this.page._snapshotForAI();
|
|
178
|
+
const snapshot = await this.page._snapshotForAI({ mode, track: "response" });
|
|
179
179
|
tabSnapshot = {
|
|
180
180
|
url: this.page.url(),
|
|
181
181
|
title: await this.page.title(),
|
|
@@ -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
|
|
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,
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
});
|
|
@@ -46,7 +46,7 @@ const snapshot = (0, import_tool.defineTool)({
|
|
|
46
46
|
},
|
|
47
47
|
handle: async (context, params, response) => {
|
|
48
48
|
await context.ensureTab();
|
|
49
|
-
response.setIncludeSnapshot();
|
|
49
|
+
response.setIncludeSnapshot("full");
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
const elementSchema = import_bundle.z.object({
|
|
@@ -49,14 +49,14 @@ const browserTabs = (0, import_tool.defineTool)({
|
|
|
49
49
|
}
|
|
50
50
|
case "close": {
|
|
51
51
|
await context.closeTab(params.index);
|
|
52
|
-
response.setIncludeSnapshot();
|
|
52
|
+
response.setIncludeSnapshot("full");
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
case "select": {
|
|
56
56
|
if (params.index === void 0)
|
|
57
57
|
throw new Error("Tab index is required");
|
|
58
58
|
await context.selectTab(params.index);
|
|
59
|
-
response.setIncludeSnapshot();
|
|
59
|
+
response.setIncludeSnapshot("full");
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
}
|
package/lib/worker/testInfo.js
CHANGED
|
@@ -107,11 +107,17 @@ class TestInfoImpl {
|
|
|
107
107
|
return import_path.default.join(this.project.snapshotDir, relativeTestFilePath + "-snapshots");
|
|
108
108
|
})();
|
|
109
109
|
this._attachmentsPush = this.attachments.push.bind(this.attachments);
|
|
110
|
-
|
|
110
|
+
const attachmentsPush = (...attachments) => {
|
|
111
111
|
for (const a of attachments)
|
|
112
112
|
this._attach(a, this._parentStep()?.stepId);
|
|
113
113
|
return this.attachments.length;
|
|
114
114
|
};
|
|
115
|
+
Object.defineProperty(this.attachments, "push", {
|
|
116
|
+
value: attachmentsPush,
|
|
117
|
+
writable: true,
|
|
118
|
+
enumerable: false,
|
|
119
|
+
configurable: true
|
|
120
|
+
});
|
|
115
121
|
this._tracing = new import_testTracing.TestTracing(this, workerParams.artifactsDir);
|
|
116
122
|
this.skip = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("skip", location, args));
|
|
117
123
|
this.fixme = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("fixme", location, args));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playwright",
|
|
3
|
-
"version": "1.57.0-alpha-2025-10-
|
|
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-
|
|
67
|
+
"playwright-core": "1.57.0-alpha-2025-10-15"
|
|
68
68
|
},
|
|
69
69
|
"optionalDependencies": {
|
|
70
70
|
"fsevents": "2.3.2"
|