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:
+25
-3
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user