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.

How to correctly screenshot this type of website

See original GitHub issue

Steps to reproduce

Tell us about your environment:

What steps will reproduce the problem?

Please include code that reproduces the issue.

  1. I write normal screenshot function to screenshot the webpage. For static website, It worked perfectly fine. But, when I try to screenshot this website ( https://www.jackall.co.jp/rooster/), it didn’t screenshot correctly. How to deal with this kind of website?

Here are the code : let browser = await puppeteer.launch({executablePath: process.env.EXECUTABLE_PATH}); let page = await browser.newPage(); const override = Object.assign(page.viewport(), {width: width}); if(isAuthenticated){ await page.authenticate({username:body.authentication.username, password:body.authentication.password}); } await page.goto(url, {waitUntil: 'load',timeout: 0}); await page.setViewport(override); await page.screenshot({ path: ./${fileName},fullPage: true }); await page.close(); await browser.close();

What is the expected result?

https://pu-ai-bc-ruby.s3.ap-southeast-1.amazonaws.com/designs/jackallrgm[test]-00250/04ec906b1eaf12ead6b8ac961bd0b5fc/1360/41a55f7a5dcd6ca5c928749997999bab26feb82c5cfac774.png

What happens instead? https://pu-ai-bc-ruby.s3.ap-southeast-1.amazonaws.com/screenshots/a003eac153b830c35895df406c60169a/04ec906b1eaf12ead6b8ac961bd0b5fc/1360/103a21e452f05c2f39080967a95.png

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jsoversoncommented, Mar 28, 2019

It looks like you can get the same effect without worrying about that line by manually setting the clip dimensions to the size of the content:

const puppeteer = require('puppeteer');

(async function(){
  let browser = await puppeteer.launch({
    headless:false,
    defaultViewport: {
      width:1900,
      height:1080
    }
  });
  let page = await browser.newPage();
  await page.goto('https://www.jackall.co.jp/rooster/');
  const height = await page.evaluate(_ => {
    return document.body.scrollHeight;
  });
  await page.screenshot({ path: 'issue-4211.png', clip : { x: 0, y: 0, width:1900, height, scale: 1 }});
  await browser.close();
}())
1reaction
jsoversoncommented, Mar 27, 2019

This happens because Puppeteer overrides the device metrics to be the height of the scrollable content but the site was not built to handle that. You can see the effect (which is similar to your result) by emulating a device in devtools and setting the height to the maximum (9999).

Screen Shot 2019-03-27 at 3 22 31 PM

If Page.js:892 is commented out then the following script produces something better.

const puppeteer = require('puppeteer');

(async function(){
  let browser = await puppeteer.launch({headless:false, defaultViewport:null});
  let page = await browser.newPage();
  await page.goto('https://www.jackall.co.jp/rooster/');
  await page.evaluate(_ => {
    while (document.body.scrollHeight < (window.scrollY + window.innerHeight)) {
      window.scrollBy(0, window.innerHeight);
    }
  });
  await page.screenshot({ path: 'issue-4211.png', fullPage: true });
  await browser.close();
}())

issue-4211

It’s not uncommon to see sites break at extreme aspect ratios so the emulation should probably be an option that can be disabled.

Read more comments on GitHub >

github_iconTop Results From Across the Web

7 ways to easily capture perfect full page website screenshots
To actually capture a screenshot, you need to open the Toolbox, click the camera symbol, and then find the resulting image in your...
Read more >
How to take full webpage screenshots with Chrome - YouTube
Here are 2 ways you can capture full webpage screenshots with Chrome.One is built-in to Google Chrome so you can get screenshots of...
Read more >
How to Take a Full-Page Screenshot in Chrome and Firefox
Open Chrome's menu. · Head to More tools > Developer tools. · Click the three-dot icon from the top-right corner and select Run...
Read more >
How to take a full-page screenshot in Google Chrome -- 4 ways
Into the Run box that appears, type "screenshot" to bring up a bunch of related options. You'll want to find the Capture full...
Read more >
4 Kinds of Screenshots You Need to Start Using Immediately
Capture a multi-page PDF ... What's your favorite type of screenshot? ... What types of screenshots do you use and where do you...
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