Skip to content

set device does not apply deviceScaleFactor - HiDPI screenshots not possible #255

@Shpigford

Description

@Shpigford

Summary

The set device command accepts Playwright device names (e.g., "Desktop Chrome HiDPI") but does not apply the deviceScaleFactor property from those device presets. This makes it impossible to capture true HiDPI/retina screenshots, which are essential for marketing materials.

Steps to Reproduce

# Start fresh session and set HiDPI device
agent-browser --session test-hidpi set device "Desktop Chrome HiDPI"

# Open any page
agent-browser --session test-hidpi open "https://example.com"

# Check the devicePixelRatio
agent-browser --session test-hidpi eval "window.devicePixelRatio"
# Returns: 1 (should be 2)

# Take screenshot
agent-browser --session test-hidpi screenshot ./test.png

# Check dimensions
sips -g pixelWidth -g pixelHeight ./test.png
# Returns: 1280x720 (should be 2560x1440 for 2x scale)

Expected Behavior

The "Desktop Chrome HiDPI" device in Playwright has these properties:

const { devices } = require('playwright');
console.log(devices['Desktop Chrome HiDPI']);
// {
//   "userAgent": "Mozilla/5.0 ...",
//   "viewport": { "width": 1280, "height": 720 },
//   "screen": { "width": 1792, "height": 1120 },
//   "deviceScaleFactor": 2,  // <-- This should be applied
//   "isMobile": false,
//   "hasTouch": false,
//   "defaultBrowserType": "chromium"
// }

When using set device "Desktop Chrome HiDPI":

  • window.devicePixelRatio should return 2
  • Screenshots should be 2560x1440 pixels (viewport × deviceScaleFactor)
  • UI elements should render at the same logical size but with 2x pixel density

Actual Behavior

  • window.devicePixelRatio returns 1
  • Screenshots are 1280x720 pixels (1x, not 2x)
  • The deviceScaleFactor from the device preset is ignored

It appears that set device only applies:

  • viewport (width/height)
  • userAgent (presumably)
  • deviceScaleFactor (not applied)
  • screen (unknown)
  • hasTouch (unknown)

Why This Matters

HiDPI screenshots are essential for:

  • Marketing materials - Product Hunt, landing pages, social media
  • Documentation - Retina-quality docs and tutorials
  • App Store assets - iOS/Mac App Store require high-res screenshots
  • Design handoffs - Crisp screenshots for design review

Without deviceScaleFactor support, users must bypass agent-browser entirely and use Playwright directly to capture marketing-quality screenshots.

Workaround

Use Playwright directly with deviceScaleFactor in the browser context:

import { chromium } from 'playwright';

const browser = await chromium.launch();
const context = await browser.newContext({
  viewport: { width: 1440, height: 900 },
  deviceScaleFactor: 2,  // This works in Playwright directly
});

const page = await context.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });
// Result: 2880x1800 pixels (true 2x retina)

Suggested Fix

When applying device settings in the browser context, include deviceScaleFactor:

// Pseudocode for what the fix might look like
const device = playwright.devices[deviceName];
const context = await browser.newContext({
  viewport: device.viewport,
  userAgent: device.userAgent,
  deviceScaleFactor: device.deviceScaleFactor,  // Add this
  screen: device.screen,
  hasTouch: device.hasTouch,
  isMobile: device.isMobile,
});

Feature Request: Direct deviceScaleFactor Setting

Additionally, it would be useful to set deviceScaleFactor directly without needing a device preset:

# Proposed new command
agent-browser set scale 2

# Or
agent-browser set deviceScaleFactor 2

This would allow users to combine custom viewports with custom scale factors:

agent-browser set viewport 1440 900
agent-browser set scale 2
agent-browser screenshot ./retina-screenshot.png
# Result: 2880x1800 pixels

Environment

  • agent-browser version: v1.1.1
  • Node.js version: v24.6.0
  • OS: macOS (Darwin 25.2.0)
  • Playwright version: (bundled with agent-browser)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions