-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Puppeteer takes partial page screenshot instead of full page #1273
Comments
Hi, Please try with, I believe this issue is with "waitUntil: 'networkidle0'" where it is not working as expected (wait until all page request -> response completes) |
Hi, @udaykanthr
For site, http://www.spiegel.de/ screenshot repeated some contents and doesn't have full content of page screenshot |
Regarding problem with images not being loaded. Im not sure if this is connected to your problem because i do not have time to try it now but there are some sites that are not loading images unless you scroll the page. Especially the modern sites that have a lot of images on the page (the reason why is that is pretty clear), i had almost the similar situation where i made some scroll function and everything worked fine... (maybe you can combine it with network requests also to be sure that its loaded) |
@udaykanthr I am still getting the same problem, note that I am using the viewport option in my code. |
I see the same problem. On code I have it as, This what I see on the terminal when custom viewport settings are given.
Maybe when you have a custom viewport it overrides the fullPage parameter? |
In my code I don't use setViewport, I use default values |
@udaykanthr I tried this using "networkidle2" in the 0.13 release but I still get the same result : ( |
@petarvasilev91, looks like this issue can now be resolved with the latest fix #1173 in version 0.13 NOTE: until now i tried using timeout for 60Secs, for taking screenshots for page with images and videos, which worked as expected, now i will try change my code to use waitForNavigation(). |
@udaykanthr with waitForNavigation() now I get timeout exceeded. Here is the code: ` (async () => {
})(); |
@marijanlekic And you said
Can you share your code of scroll function? Many thanks |
@petarvasilev91 Thanks. It works well, except that the latest puppeteer has a few changes of api that need to be applied to your code. |
We have an Angular Single Page App that sets up the Angular environment and then navigates between different views. The reason that the snapshot was not taken (and the Promise was failing) was because the second page was different to the first. So the condition in the NavigationWatcher.js needed changing from this._frame._loaderId === this._initialLoaderId to !this._frame._loaderId === this._initialLoaderId
|
Also experiencing Edit: It's probably cause I created a fake scrolling element using an overflowed element so the page didn't actually have height |
I am experiencing this issue, but only when running headfully. See I use WSL and though I was able to get puppeteer to work by specifying the path to Windows Chrome, if I tried to run it headlessly it always times out with no error. It works okay with "headless: false" so I just rolled with that because it doesn't matter to me. Then I captured a screenshot, and that worked too. But when I used setViewport() to emulate a mobile device the screenshots come out entirely transparent. I tried passing different args to setViewport, tried waitFor(10000) in various places. Tried slowmo. Nothing worked, so I decided to try it outside of WSL, but the behavior was the same. Then I tried setting "headless:true" and sure enough it works fine. So I'm guessing the root of the issue is some kind of race between setViewport and screenshot but only when running headfully. |
Due to viewport jumping all the time when: Is there I way to find the viewport dimensions when puppeteer takes screenshot ? |
Anyone still experiencing this?
|
(bump) Same here, still not getting full screen caps on very long pages. |
We're hitting the GPU memory limit on the chromium side. Instead of returning corrupted screenshots, we probably need to limit screenshot height to 2^14 and notify users that very long pages won't work. |
I also had partial screenshots issue on Centos7 + Chrome v.75. Downgrade chrome version to stable v.71 solved issue in my case. |
@udaykanthr using 1.18.1 and this code:
it still takes a partial screenshot for some reason... |
+1 for clipping |
Looks like it is really memory related. |
For testing: const puppeteer = require('puppeteer')
async function main() {
const browser = await puppeteer.launch({
args: ['--start-maximized'],
headless: false,
defaultViewport: null
})
const page = (await browser.pages())[0]
await page.goto('https://coinmarketcap.com/', { waitUntil: 'networkidle0' })
await page.evaluate(() => document.querySelector('.banner-alert-fixed-bottom').remove())
await screenshotDOMElements({
page,
path: 'element.png',
selector: 'table.dataTable > tbody > tr:nth-child(-n+50)',
addHeight: true
})
await screenshotDOMElements({
page,
path: 'element2.png',
selector: 'table.dataTable > tbody > tr:nth-child(n+50)',
addHeight: true
})
console.log('Finished')
}
main()
.catch(error => {
console.error(error)
process.exit(1)
})
/**
* Takes a screenshot of a DOM elements on the page, with optional padding.
* @return {!Promise<!Buffer>}
*/
async function screenshotDOMElements({
page,
padding = 0,
path = null,
selector,
addWidth = false,
addHeight = false
} = {}) {
if (!selector) {
throw Error('Please provide a selector.')
}
const rect = await page.evaluate((selector, addWidth, addHeight) => {
let minX = Infinity
let minY = Infinity
let maxWidth = 0
let maxHeight = 0
const elements = document.querySelectorAll(selector)
if (elements) {
for (const element of elements) {
const {x, y, width, height} = element.getBoundingClientRect()
minX = Math.min(minX, x)
minY = Math.min(minY, y)
maxWidth = addWidth
? maxWidth + width
: Math.max(maxWidth, width)
maxHeight = addHeight
? maxHeight + height
: Math.max(maxHeight, height)
}
return {
left: minX,
top: minY,
width: maxWidth,
height: maxHeight
}
}
return null
}, selector, addWidth, addHeight)
if (!rect) {
throw Error(`Could not find element that matches selector: ${selector}.`)
}
return page.screenshot({
path,
clip: {
x: rect.left - padding,
y: rect.top - padding,
width: rect.width + padding * 2,
height: rect.height + padding * 2
}
})
} |
I resolve the problem of the screenshot getting the html element dimensions and passing it to the clip argument on the screenshot method, and setting the x and y options at 0,0
You will need consider edit the viewport for get a web or mobile view. |
@faqndo97 this does not solve for large elements. That's the particularity of this issue. |
Just use const el = await page.$('.box');
await el.snapshot({
path: './images/box.png'
}) |
I solved same problem with enlargement of the viewport: i needed several pages so i huge height got me my screenshots, |
Thanks for your help ! let contentHeight = await page.evaluate(() => {
return document.getElementsByTagName('html')[0].offsetHeight;
}) is useful for me ! |
I found a solution which is applicable to multiple sites using the page.setViewPort(...) method as given below:
|
This code is working for me const puppeteer = require('puppeteer'); async function run() { run(); source: https://www.scrapehero.com/how-to-take-screenshots-of-a-web-page-using-puppeteer/ |
One issue is Chromium returns value for For example, at Chromium 87, navigating to MDN https://developer.mozilla.org/en-US/ and running At DevTools CTRL+SHIFT+P running the command "Capture full size screenshot" will result in an image 39 less vertical pixels than expected. |
If anyone is having this issue still I have done the following to get a full-page screenshot.
|
I filed a Chrome bug for this https://bugs.chromium.org/p/chromium/issues/detail?id=1164757. |
This code works for me: const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Set width.
await page.setViewport({ width: 1920, height: 1 });
// Load page.
await page.goto('https://digg.com/', {
waitUntil: 'networkidle0', timeout: 0
});
// Get scroll height of the rendered page and set viewport
const bodyHeight = await page.evaluate(() => document.body.scrollHeight);
await page.setViewport({ width: 1920, height: bodyHeight });
// Screenshot and exit.
await page.screenshot({ path: 'screenshot.png', fullPage: true });
await browser.close();
})(); |
From what I can tell, I think the problem could be solved by a setting to throttle the screenshot process. mock-up be like await page.screenshot({
path: 'home_assistant.png',
fullPage: true,
delay: '500ms' // just wait between the fullPage resize and the actual screenshot creation
}); |
We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days. |
We are closing this issue. If the issue still persists in the latest version of Puppeteer, please reopen the issue and update the description. We will try our best to accomodate it! |
I am trying to take a full page screenshot of http://digg.com (mobile version) but it always takes a partial screenshot, it also happens on https://thenextweb.com/. Here is the code I am using:
The text was updated successfully, but these errors were encountered: