question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion: page.screenshot changes in v2.0.0

See original GitHub issue

Per upstream Chromium changes, page.screenshot now clips elements to the viewport as of Puppeteer v2.0.0.

https://github.com/GoogleChrome/puppeteer/commit/81d26002361f2485d4ae8a9758be25e65d4c1c01 rolled Chromium, and https://github.com/GoogleChrome/puppeteer/pull/5079 added a test based on the new behavior.

The good news is that with this change, document and overflow scroll clipping now work the same. It fixes issues with fixed-position headers, such as the bottom-sticking support and cookie banners on https://www.theguardian.com/us which would previously render in the middle of a screenshot. Generally, it makes page.screenshot work exactly like Chrome does (literally capturing a screenshot), rather than producing a result Chrome would not render in real scenarios.

Puppeteer scripts that relied on the old behavior can be updated to resize the viewport before calling page.screenshot.

But, it could be that people relied on the old behavior in some way for which the above workaround doesn’t help. This issue can be used to collect such use cases and identify alternative implementations.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:21
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
trotzigcommented, Oct 29, 2019

Hi there! 👋

First of all I’d like to stress how much I appreciate the work that you are doing. Puppeteer is by far the most developer-friendly and efficient way of automating a browser. 👏

I run Happo.io, a screenshot testing service. We do cross-browser testing with Chrome being one of the targets. Other browsers (like IE11, Edge, Safari, etc) we control via Selenium but Chrome is controlled via Puppeteer.

Most of our users have test suites that consist of individual components where few span more than the height of the viewport. But there are cases where components are taller than that, and we rely on Puppeteer giving us full screenshots of the components. Some of our users have full pages in their test suites, although that’s not the most common setup.

The workaround suggested where the screen size is adjusted before taking the screenshot isn’t always a good solution, for a few reasons:

  • elements styled with a vh unit in CSS will probably not look right. Imagine a large heading (hero style) which is made vertically centered through a 100vh flexbox container.
  • fixed/sticky elements might not be in the right place (as mentioned in the original comment)

Viewport-cropped screenshots is a problem in other browsers as well. With IE controlled through Selenium, we only get the viewport back in the screenshot. The workaround we have implemented there involves stitching together a full screenshot by scrolling through the page. That workaround has the added side-effect of making sticky/fixed elements appear several times, which we work around by hiding them after they’re first seen.

We could potentially adopt the “stitching” workaround described above for Chrome as well, but it would affect performance negatively. Since Happo is a tool people use in CI, and people don’t like waiting for CI, we have a tight budget for taking screenshots. Some of our users have 10000+ examples to screenshoot for each CI run and the screenshot phase is one of the slowest (50-250ms) in the Chrome runner.

I don’t have enough context to know if supporting the old screenshot behavior is even viable, but if I could be the PM here I’d love to see that happen! 😃

5reactions
trotzigcommented, Jan 11, 2021

Good news – the above referenced chromium bug has been fixed and merged. To get screenshots that aren’t cut off at the viewport edge you need to set the blink flag mainFrameClipsContent=false:

await puppeteer.launch({
  args: [
    '--blink-settings=mainFrameClipsContent=false',
  ],
});

I’m running through some regression tests on happo.io and it looks like things are working well and that the old behavior of capturing content outside the viewport is back again. 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selenium webdriver C# - Taking full page screenshot
"Full-page" screenshots are defined by WebDriver to include the entirety of the page ... GetPageOffset(); var prevPageOffset = 0; var currentPageOffset = 0; ......
Read more >
Page.screenshot() method - Puppeteer
type : Specify screenshot type, can be either jpeg or png . Defaults to 'png'. quality : The quality of the image, between...
Read more >
Fix Google Assistant screenshot settings - Android
If the Google Assistant won't take screenshots, try these steps to fix the issue: Step 1: Check your Android ... Step 2: Check...
Read more >
blurred screenshot - Articulate Storyline Discussions
Hello all, when I do a screenshot of a web page to add to my slide in Storyline 360 the screenshot is blurred...
Read more >
One simple trick to make your screenshots 80% smaller - GitLab
This means that the screenshot will perfectly capture every pixel on your screen, but having four 8-bit channels for red, green, blue and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found