MarshallOfSound

#53813: fix: give captured page images their device scale factor

Merged
Created: Sep 10, 2026, 1:32:10 AM
Merged: Sep 10, 2026, 4:26:17 PM
2 comments
Target: main

Description of Change

Stacked on #53810.

capturePage(), the offscreen paint event and beginFrameSubscription() wrapped their bitmaps with CreateFrom1xBitmap, so the image always claimed a scale factor of 1. On a HiDPI display, or with offscreen.deviceScaleFactor, getSize() returned pixels and the image displayed at the wrong size.

  • Mark each image with the view's device scale factor. getSize(), crop() and resize() are now in DIPs; toBitmap(), toPNG(), toJPEG() and toDataURL() still return every pixel.
  • Fix nativeImage.toJPEG() returning an empty buffer for images with no 1x representation (already broken for createFromBitmap(..., { scaleFactor: 2 })). Separate commit, can be split out and backported.
  • Breaking change entry under 46.0.
400×300 window on a 2x display before after
getSize() 800×600 400×300
getScaleFactors() [1] [2]
toPNG() pixels 800×600 800×600

Checklist

  • PR description included
  • I have built and tested this PR
  • npm test passes
  • tests are changed or added
  • relevant API documentation is changed or added

Release Notes

Notes: webContents.capturePage(), the offscreen paint event and webContents.beginFrameSubscription() now return images with the page's device scale factor, so image.getSize() is in DIPs rather than pixels on HiDPI displays. Also fixed nativeImage.toJPEG() returning an empty buffer for images without a 1x representation.

Backports

No Backports Requested

This pull request doesn't have any backports requested or created for older release branches.

What are backports?

Backports are copies of changes made to the main branch that are applied to older release branches. They ensure that bug fixes and important changes are available in maintained older versions of Electron.

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron