fix: a screenshot honours its scale: scale="css" is a picture in CSS pixels

PageDispatcher.op_screenshot sent omitDeviceScaleFactor false whatever the caller asked and never read `scale`: at a viewport of 1280x720 and a ratio of 1.25
page.screenshot(scale="css") was 1600x900, stock gives 1280x720. It now sends omitDeviceScaleFactor: scale == "css", as stock's Firefox page does. The element and
locator screenshots end in the same call, so they follow.
This commit is contained in:
feder-cr committed 2026-11-22 22:33:42 +01:00
1 parent b74a08c400
commit 85a01e4be0
1 file changed
+7 -1
+7 -1
View File
@@ -4098,7 +4098,13 @@ class PageDispatcher(Dispatcher):
else "image/png",
"clip": clip,
"quality": params.get("quality"),
"omitDeviceScaleFactor": False,
# ⛔ THE SCALE IS THE CALLER'S, and it is the engine that applies it: `"css"` is a picture in CSS pixels
# (1280x720 for a 1280x720 viewport at any ratio), `"device"` and no `scale` a picture in device pixels
# (1600x900 at 1.25). Stock Playwright's Firefox sends `omitDeviceScaleFactor: scale === "css"`; this sent
# False for everything and ignored `scale`, so `scale="css"` gave device pixels at any ratio but 1. The
# element's screenshot ends here too (`ElementHandleDispatcher.op_screenshot` hands its rectangle to this
# call with the caller's params), so the page, the full page, a clip and an element all agree.
"omitDeviceScaleFactor": params.get("scale") == "css",
}), timeout=self.frame._timeout(params)) or {}
# ⛔ BASE64 IN, BASE64 OUT. The client decodes it; decoding here and
# handing back bytes puts a str() of a bytes object in the answer.