This code works fine:
const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('); await page.setViewport({width: 1280, height: 978, deviceScaleFactor: 1}); await page.screenshot({path: 'example2.jpg'}); await browser.close(); But if I change deviceScaleFactor to 2 (because I'm on a retina screen) I get this error: Error running your code. Error: Protocol error (Page.captureScreenshot): Target closed.
Any ideas why? Seems to work if I change the URL to example.com as well, but not if I try other websites.
1 Answer
This error no longer appears as of Puppeteer v1.5.0.
The website that you were trying to access had maximum-scale=1 in the source code:
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> Therefore, deviceScaleFactor: 2 appears to have been failing due to this fact.