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.

Error: Protocol error (Page.captureScreenshot): Unable to capture screenshot when taking screenshot of a large viewport

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 2.0.0
  • Platform / OS version: Windows 10 1903 x64
  • Node.js version: 10.17

What steps will reproduce the problem?

Please include code that reproduces the issue.

Here is a code snippet that sets large viewport and is trying to take screenshot of that

// test.js
const puppeteer = require('puppeteer');

class Server {
    async setup() {
        if (!this.browser) {
            this.browser = await puppeteer.launch();
        }
    }
    
    async export() {
        try {
            await this.setup();
    
            const me = this;
    
            const page = await this.browser.newPage();
    
            page.on('error', e => {
                throw e;
            });
    
            await page.setContent('<html><head></head><body><h1>test</h1></body></html>');
    
            await page.setViewport({
                width : 10000,
                height : 50000
            });
            await page.emulateMedia('print');
    
            await page.screenshot({
                deviceScaleFactor : 4
            });
    
            await this.browser.close();
    
            console.log('browser closed');
        }
        catch (e) {
            await this.browser.close();
            
            throw e;
        }
    }
}

const srv = new Server();

srv.export()
    .then(() => process.exit())
    .catch(e => {
        process.exit(1);
    });

What is the expected result? Screenshot taken

What happens instead? Exception thrown

Error: Protocol error (Page.captureScreenshot): Unable to capture screenshot
 at Promise (...server\node_modules\puppeteer\lib\Connection.js:183:56) 
 at new Promise (<anonymous>)
 at CDPSession.send (...server\node_modules\puppeteer\lib\Connection.js:182:12)
 at Page._screenshotTask (...server\node_modules\puppeteer\lib\Page.js:951:39)
 at process._tickCallback (internal/process/next_tick.js:68:7) -- ASYNC --
 at Page.<anonymous> (...server\node_modules\puppeteer\lib\helper.js:111:15)
 at Server.export (...server\src\utils\screenshot.js:34:24)
 at process._tickCallback (internal/process/next_tick.js:68:7)

Initially I got that exception from a puppeteer which was launched from node express request handler. It failed to take a screenshot of size 700x25000 with same exception. So I tried to figure what’s going on and wrote this test script, which worked just fine with same html and same size of the viewport. Then I tried to increase viewport to some ridiculous number and reproduced the problem.

So screenshot fails inside node express request handler on a viewport 700x25000 and fails outside of the node express but at much higher viewport size, like 10000x50000

So questions are:

  1. Is there a limit to screenshot size which can be taken?
  2. If so, how can I calculate that limit?
  3. Is there a safe value for viewport?
  4. Can you suggest a way to take screenshots of large pages? What comes to my mind is to play with trasnform: scale() to fit content into some reasonable viewport, e.g. UHD

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:37
  • Comments:30

github_iconTop GitHub Comments

6reactions
NikolaiSilvercommented, Aug 6, 2020

I have the same problem, any updates?

4reactions
ArtTkachenkocommented, May 5, 2022

Hi everyone! Seems to be i found problem, as i understand for browser rendering important free space in temp directory for shared memory (on centos it’s /temp or /dev/shm dir). In puppeteer launch options add dumpio:true -option, and if in time when puppeteer open page/render you’ve got error, something like this:

[WARNING:discardable_shared_memory_manager.cc(197)] Less than 64MB of free space in temporary directory for shared memory files: 29

or ERROR:file_io.cc(140)] write: No space left on device (28)

It’s mean that you should increase tmp directory size. To check how much memory you`ve got type in terminal command “df -h” and take a look to tmp dirs available size.

image

Hope it will help you. Cheers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Protocol error (Page.captureScreenshot): Target closed ...
Error : Protocol error (Page.captureScreenshot): Target closed. Solution I was facing issue because of the screenshot height and width.
Read more >
Puppeteer Screenshot Full Page Not Working. Possible Fixes ...
The problem with viewport units in Puppeteer is that although the library can simulate the viewport size, it can't really take a full-page...
Read more >
Page.captureScreenshot() fails when running --headless
Use "chrome-remote-interface" (nodejs module) to capture page screenshot (Page.captureScreenshot()), or follow the steps described on ...
Read more >
webdriverio/webdriverio - Gitter
... fail test the screenshot is taken as before but now am also seeing this error in my logs. " Error: Protocol error...
Read more >
Developers - Error: Protocol error (Page.captureScreenshot)
Error : Protocol error (Page.captureScreenshot): Unable to capture screenshot when taking screenshot of a large viewport.
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