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(
+1
View File
@@ -270,6 +270,7 @@ const viewportSchema = baseCommandSchema.extend({
action: z.literal('viewport'),
width: z.number().positive(),
height: z.number().positive(),
deviceScaleFactor: z.number().positive().optional(),
});
const userAgentSchema = baseCommandSchema.extend({
+1
View File
@@ -263,6 +263,7 @@ export interface ViewportCommand extends BaseCommand {
action: 'viewport';
width: number;
height: number;
deviceScaleFactor?: number;
}
// User agent