-
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): add full page screenshot to artifacts #9064
Conversation
} else if (settings.emulatedFormFactor === 'desktop') { | ||
await emulation.enableDesktop(this); | ||
await emulation.enableDesktop(this, deviceMetricOverrides); |
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.
Would it be appropriate to hook the options on the driver itself?
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.
What do you mean by that?
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.
If the extra param could be removed in favor for having it as a prop on this
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.
I'm not sure we want to clutter driver with additional properties just for the method here. It's a pretty busy class already 😆
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.
Looks pretty good! I might argue that if we're commenting out the audit we should probably not land the gatherer config change either, but most of this depends on how quickly we'll follow this up with user-facing changes to leverage this.
data, | ||
width, | ||
height, | ||
// todo: do we need these? should we create a new type? should we make them optional on the existing type? should we try to provide accurate values? |
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.
IMO we should just nix these from the type
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.
Sounds good. It makes sense to have the timings for the filmstrip, but Filmstrip is a separate type from Screenshot.
async _takeScreenshot(passContext, maxScreenshotHeight) { | ||
const driver = passContext.driver; | ||
const metrics = await driver.sendCommand('Page.getLayoutMetrics'); | ||
const width = await driver.evaluateAsync(`window.innerWidth`) * 2; |
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.
why * 2
?
I thought we might want innerWidth * devicePixelRatio
but then we force the deviceScaleFactor
to 1 below so I'm not sure anymore
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.
Whoops, that slipped in when testing large screenshots.
|
||
const Gatherer = require('./gatherer.js'); | ||
|
||
// JPEG quality setting |
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.
can we link to that awesome exploration doc you made for how we landed on 30?
* @return {Promise<void>} | ||
*/ | ||
async beginEmulation(settings) { | ||
async beginEmulation(settings, deviceMetricOverrides) { |
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.
my initial thought looking at this was that I was worried about emulatedFormFactor
conflicting with deviceMetricOverrides
, maybe add a brief comment explaining the use case for deviceMetricOverrides?
creating a nexus 5x with arbitrary screen height seems counter-intuitive at first :)
const height = Math.min(metrics.contentSize.height, maxScreenshotHeight); | ||
|
||
await driver.beginEmulation(passContext.settings, { | ||
height, |
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.
mostly talking to the air here did we ever figure out what screenHeight
does separately from height
? desktop doesn't set screenHeight at the moment at all just wonder if that'll impact anything
it sets the screen rect but not sure what impact that has...
https://cs.chromium.org/chromium/src/content/renderer/render_widget_screen_metrics_emulator.cc?type=cs&sq=package:chromium&g=0&l=78-83
seems like it notifies some observers and kicks off orientation changes, but doesn't actually affect viewport size?
https://cs.chromium.org/chromium/src/content/renderer/render_widget.cc?type=cs&sq=package:chromium&g=0&l=2183
🤷♂
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.
screen size is the physical device size (DIP): https://cs.chromium.org/chromium/src/third_party/blink/public/web/web_device_emulation_params.h?l=26&rcl=c6f1509e8c13f8b0739c99b343d628a38f8a9da7
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.
FYI: command for viewing fullscreen image (after you run LH with -G
)
(echo -e '<img src=' && (jq .FullPageScreenshot.data latest-run/artifacts.json | tr -d '\n') && echo -e '>') | cat > /tmp/lhfull.html && google-chrome /tmp/lhfull.html
const height = Math.min(metrics.contentSize.height, maxScreenshotHeight); | ||
|
||
await driver.beginEmulation(passContext.settings, { | ||
height, |
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.
screen size is the physical device size (DIP): https://cs.chromium.org/chromium/src/third_party/blink/public/web/web_device_emulation_params.h?l=26&rcl=c6f1509e8c13f8b0739c99b343d628a38f8a9da7
* @return {Promise<LH.Artifacts.FullPageScreenshot>} | ||
*/ | ||
async afterPass(passContext) { | ||
let screenshot = await this._takeScreenshot(passContext, MAX_SCREENSHOT_HEIGHT); |
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.
should we scroll to the top of the page first? I think devtools does that.
{deviceMetrics, setTouchEmulationEnabled, userAgent, deviceMetricOverrides} | ||
) { | ||
if (deviceMetricOverrides) { | ||
deviceMetrics = Object.assign({}, deviceMetrics, deviceMetricOverrides); |
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.
deviceMetrics = Object.assign({}, deviceMetrics, deviceMetricOverrides); | |
deviceMetrics = {...deviceMetrics, ...deviceMetricOverrides}; |
// Network.enable must be called for UA overriding to work | ||
driver.sendCommand('Network.enable'), | ||
driver.sendCommand('Network.setUserAgentOverride', {userAgent: NEXUS5X_USERAGENT}), | ||
driver.sendCommand('Emulation.setTouchEmulationEnabled', {enabled: true}), | ||
driver.sendCommand('Network.setUserAgentOverride', {userAgent}), |
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.
should we be balancing domain enable / disable?
@@ -1423,13 +1423,15 @@ class Driver { | |||
|
|||
/** | |||
* @param {LH.Config.Settings} settings | |||
* @param {{height?: number, screenHeight: number?, deviceScaleFactor?: number}} [deviceMetricOverrides] |
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.
* @param {{height?: number, screenHeight: number?, deviceScaleFactor?: number}} [deviceMetricOverrides] | |
* @param {{height?: number, screenHeight?: number, deviceScaleFactor?: number}} [deviceMetricOverrides] |
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.
make expectations on the artifact too?
we did this in #10716 |
Capture a screenshot of the entire page, rather than just the above the fold content.
Splitting this off from this PR which actually uses the artifact.
What's the best way to test this? Add a new smoke test and unit test the gatherer with a mocked driver?
Related Issues/PRs
Part of #7327