pyppeteer / pyppeteer

Headless chrome/chromium automation library (unofficial port of puppeteer)
Other
3.53k stars 323 forks source link

Not able to load website properly #249

Open iSaluki opened 3 years ago

iSaluki commented 3 years ago

Earlier today I was using Pyppeteer to try and take a screenshot of a webpage after it loaded up. I was using the following code to do so:

import asyncio
import time
from pyppeteer import launch

async def main():
    browser = await launch()
    page = await browser.newPage()
    await page.goto('https://azgaar.github.io/Fantasy-Map-Generator')
    time.sleep(10)
    await page.screenshot({'path': 'image.png'})
    await browser.close()

asyncio.get_event_loop().run_until_complete(main())

I was expecting this to produce an image of a fantasy map, as you'd see if you went to [https://azgaar.github.io/Fantasy-Map-Generator](the link). However, this ended up taking a screenshot of the loading screen. I tried pushing the wait all the way up to 20 seconds, but saw no change. It took at most 2 seconds for me to load in normal chrome.

This was quite weird, so I decided to try and do the same thing with Puppeteer in JavaScript. When I used the exact same logic as shown in the above code, I got the expected output, of a map. I could also get it with the 2 second delay.

In the end, I wasn't able to get it working with Pyppeteer and ended up having to use Puppeteer, which does the job, but as it is a different language and requires NodeJS, will make my app more bloated and will also require more effort to maintain.

I haven't been able to identify the cause of this issue or any possible fixes, but I would appreciate it if anything could be done on your end.

mcolella14 commented 3 years ago

The bundled version of Chromium is super old, so I think that may be causing issues. I ran this with Chrome instead and the map seemed to load fine. You can do this by passing in the path to Chrome to launch like so:

browser = await launch(executablePath='/usr/bin/google-chrome')

I tend to just always use Chrome vs. Chromium because I've run into a few issues like this. This is kinda just a workaround though, so it might be worth trying to run headfully and see what's actually going wrong in the browser if you want to get down to the root of the problem/don't want to use Chrome.

iSaluki commented 3 years ago

Thanks for this. I think it is just the Chromium version, because it works fine in normal Chrome.