-
Notifications
You must be signed in to change notification settings - Fork 76
fix: fix pixel ratio mismatch on pages with out of process iframes #1315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c652087
7305272
055e1a9
ac59f9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,30 @@ module.exports = class ScreenShooter { | |
| } | ||
|
|
||
| async capture(page, opts = {}) { | ||
| const { allowViewportOverflow, compositeImage, screenshotDelay, selectorToScroll } = opts; | ||
| const { | ||
| allowViewportOverflow, | ||
| compositeImage, | ||
| screenshotDelay, | ||
| selectorToScroll, | ||
| preferredPixelRatio, | ||
| reprepareScreenshot, | ||
| } = opts; | ||
| const viewportOpts = { allowViewportOverflow, compositeImage }; | ||
| const cropImageOpts = { screenshotDelay, compositeImage, selectorToScroll }; | ||
|
|
||
| const capturedImage = await this._browser.captureViewportImage(page, screenshotDelay); | ||
| if (reprepareScreenshot) { | ||
| const currentPixelRatio = await this._browser.evalScript("window.devicePixelRatio"); | ||
|
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
With Useful? React with 👍 / 👎. |
||
|
|
||
| if (currentPixelRatio !== (preferredPixelRatio ?? page.pixelRatio)) { | ||
| Object.assign(page, await reprepareScreenshot(currentPixelRatio)); | ||
| delete opts.preferredPixelRatio; | ||
| delete opts.reprepareScreenshot; | ||
|
|
||
| return this.capture(page, opts); | ||
| } | ||
| } | ||
|
|
||
| const viewport = Viewport.create(page, capturedImage, viewportOpts); | ||
| await viewport.handleImage(capturedImage); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When headful Chrome is configured using the supported
mobileEmulation: { deviceName: "..." }form,deviceMetricsis absent, so this returnsundefinedand the code never installs the preferred-DPR retry path. On an OOPIF page exhibiting the mismatch addressed by this change,prepareScreenshotmay use the pre-capture DPR while the screenshot is produced after Chrome switches DPR, leaving named-device users with incorrectly scaled and cropped screenshots. Obtain the initial DPR from the browser or otherwise resolve the named profile rather than requiring explicitdeviceMetrics.pixelRatio.Useful? React with 👍 / 👎.