Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between fullPage and captureBeyondViewport

Tags:

puppeteer

The puppeteer function page.screenshot([options]) accepts two parameters:

  • fullPage When true, takes a screenshot of the full scrollable page. Defaults to false.

  • captureBeyondViewport When true, captures screenshot beyond the viewport. Whe false, falls back to old behaviour, and cuts the screenshot by the viewport size. Defaults to true.

To me this sounds like pretty much the same thing, besides the different default values. So I wonder what the difference is.

like image 582
Sebastian Avatar asked Sep 01 '25 16:09

Sebastian


1 Answers

These options might seem like siblings, but they are not and have very different behavior from each other and doesn't relate to each other at all.

fullPage

The fullPage option technically resizes the viewport to match the page layout width and height when taking a screenshot and then returns a viewport size to the previous value. So, that's how you get the whole page screenshot.

captureBeyondViewport

Not related to the issue, you might have cases when an element or even the whole page width or height is defined through viewport units. Look at this example (source):

<!DOCTYPE html>
<html>
    <body>
        <div 
            class="beyond-viewport-element" 
            style="height: 110vh; background-color: blue; border: 10px solid red"></div>
        <div 
            class="next-element" 
            style="height: 100px; background-color: yellow; border: 10px solid black"></div>
    </body> 
</html>

If you try to take the full-page screenshot, you will fail to take it fully because the .beyond-viewport-element will always be beyond the viewport, so to make sure that you capture elements beyond the viewport, set the captureBeyondViewport option to true.

like image 113
Dmytro Krasun Avatar answered Sep 06 '25 17:09

Dmytro Krasun