add scale factor to set viewport for retina screenshots (#691)

* device scale

* fix node.js daemon

* fix cargo fmt formatting for scale factor code

* fixes
This commit is contained in:
Chris Tate
2026-03-09 11:10:22 -05:00
committed by GitHub
parent a0bd0c2f0f
commit 644a4f5b63
9 changed files with 157 additions and 11 deletions
+25 -3
View File
@@ -1465,11 +1465,33 @@ async function handleViewport(
command: ViewportCommand,
browser: BrowserManager
): Promise<Response> {
await browser.setViewport(command.width, command.height);
return successResponse(command.id, {
if (command.deviceScaleFactor && command.deviceScaleFactor !== 1) {
await browser.setViewport(command.width, command.height);
await browser.setDeviceScaleFactor(
command.deviceScaleFactor,
command.width,
command.height,
false
);
} else {
// deviceScaleFactor is 1 or undefined -- clear any previously-set CDP
// Emulation.setDeviceMetricsOverride so stale DPR doesn't persist.
try {
await browser.clearDeviceMetricsOverride();
} catch {
// Ignore if override was never set
}
await browser.setViewport(command.width, command.height);
}
const result: Record<string, unknown> = {
width: command.width,
height: command.height,
});
};
if (command.deviceScaleFactor !== undefined) {
result.deviceScaleFactor = command.deviceScaleFactor;
}
return successResponse(command.id, result);
}
async function handleUserAgent(