-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core(full-page-screenshot): use dpr 1 #11688
Changes from 5 commits
7ef20f5
05640d9
8213d7f
91bdf1d
6165bb1
dc1e1e7
9d7307a
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 |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
/* eslint-env jest */ | ||
|
||
const FullPageScreenshotGatherer = require('../../../gather/gatherers/full-page-screenshot.js'); | ||
const MAX_SCREENSHOT_HEIGHT = 16384; | ||
|
||
/** | ||
* @param {{contentSize: {width: number, height: number}, screenSize: {width?: number, height?: number, dpr: number}, screenshotData: string[]}} | ||
|
@@ -20,7 +19,7 @@ function createMockDriver({contentSize, screenSize, screenshotData}) { | |
return contentSize.width; | ||
} | ||
if (code === 'window.devicePixelRatio') { | ||
return screenSize ? screenSize.dpr : 1; | ||
return screenSize ? screenSize.dpr : 2; | ||
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. i don't understand this change to the default 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. good call. it's kind of a separate change. This is the mock driver so we're returning a DPR back to lighthouse. Since we're now emulating DPR 1 to take the screenshot.. I figured I'd just pretend the browser is a non-1 DPR just to keep things separate afaik this value is never even used....... ...... okay in that case i'll just delete this part of the mock. |
||
} | ||
if (code.includes('document.documentElement.clientWidth')) { | ||
return { | ||
|
@@ -131,11 +130,9 @@ describe('Full-page screenshot gatherer', () => { | |
'Emulation.setDeviceMetricsOverride', | ||
expect.objectContaining({ | ||
mobile: true, | ||
deviceScaleFactor: 2, | ||
deviceScaleFactor: 1, | ||
height: 1500, | ||
width: 500, | ||
screenHeight: 1500, | ||
screenWidth: 500, | ||
}) | ||
); | ||
|
||
|
@@ -147,8 +144,6 @@ describe('Full-page screenshot gatherer', () => { | |
deviceScaleFactor: 2, | ||
height: 500, | ||
width: 500, | ||
screenHeight: 500, | ||
screenWidth: 500, | ||
screenOrientation: { | ||
type: 'landscapePrimary', | ||
angle: 30, | ||
|
@@ -183,17 +178,18 @@ describe('Full-page screenshot gatherer', () => { | |
expect.objectContaining({ | ||
deviceScaleFactor: 1, | ||
height: FullPageScreenshotGatherer.MAX_SCREENSHOT_HEIGHT, | ||
screenHeight: FullPageScreenshotGatherer.MAX_SCREENSHOT_HEIGHT, | ||
}) | ||
); | ||
}); | ||
|
||
it('captures a smaller screenshot if the captured data URL is too large', async () => { | ||
const fpsGatherer = new FullPageScreenshotGatherer(); | ||
const pageContentHeight = 15000; | ||
|
||
const driver = createMockDriver({ | ||
contentSize: { | ||
width: 412, | ||
height: 15000, | ||
height: pageContentHeight, | ||
}, | ||
screenSize: { | ||
dpr: 2, | ||
|
@@ -216,17 +212,15 @@ describe('Full-page screenshot gatherer', () => { | |
expect(driver.sendCommand).toHaveBeenCalledWith( | ||
'Emulation.setDeviceMetricsOverride', | ||
expect.objectContaining({ | ||
deviceScaleFactor: 2, | ||
height: Math.floor(MAX_SCREENSHOT_HEIGHT / 2), | ||
screenHeight: Math.floor(MAX_SCREENSHOT_HEIGHT / 2), | ||
deviceScaleFactor: 1, | ||
height: pageContentHeight, | ||
}) | ||
); | ||
expect(driver.sendCommand).toHaveBeenCalledWith( | ||
'Emulation.setDeviceMetricsOverride', | ||
expect.objectContaining({ | ||
deviceScaleFactor: 2, | ||
deviceScaleFactor: 1, | ||
height: 5000, | ||
screenHeight: 5000, | ||
}) | ||
); | ||
|
||
|
@@ -235,10 +229,12 @@ describe('Full-page screenshot gatherer', () => { | |
|
||
it('returns null if the captured data URL is way too large', async () => { | ||
const fpsGatherer = new FullPageScreenshotGatherer(); | ||
const pageContentHeight = 15000; | ||
|
||
const driver = createMockDriver({ | ||
contentSize: { | ||
width: 412, | ||
height: 15000, | ||
height: pageContentHeight, | ||
}, | ||
screenSize: { | ||
dpr: 3, | ||
|
@@ -259,20 +255,20 @@ describe('Full-page screenshot gatherer', () => { | |
|
||
const result = await fpsGatherer.afterPass(passContext); | ||
|
||
// first attempt | ||
expect(driver.sendCommand).toHaveBeenCalledWith( | ||
'Emulation.setDeviceMetricsOverride', | ||
expect.objectContaining({ | ||
deviceScaleFactor: 3, | ||
height: Math.floor(MAX_SCREENSHOT_HEIGHT / 3), | ||
screenHeight: Math.floor(MAX_SCREENSHOT_HEIGHT / 3), | ||
deviceScaleFactor: 1, | ||
height: pageContentHeight, | ||
}) | ||
); | ||
// second attempt | ||
expect(driver.sendCommand).toHaveBeenCalledWith( | ||
'Emulation.setDeviceMetricsOverride', | ||
expect.objectContaining({ | ||
deviceScaleFactor: 3, | ||
deviceScaleFactor: 1, | ||
height: 5000, | ||
screenHeight: 5000, | ||
}) | ||
); | ||
|
||
|
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.
removing all of this is necessary? IIRC you suggested I add all the parameters in the original PR.
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.
yeah i was being overly cautious back then. i looked and neither CDT nor PPTR uses these props.
i tested this heavily after these changes and feel good that they aren't important.