Skip to content
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

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

Open
bmblb opened this issue Jan 25, 2020 · 35 comments

Comments

@bmblb
Copy link

bmblb commented Jan 25, 2020

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
@MissiaL
Copy link

MissiaL commented Feb 14, 2020

Any updates? I have the same problem
So. After my research, the working solution was to roll back to version 1.20.0

@brumeregan
Copy link

I'm also having this problem =(

@Mattwmaster58
Copy link

Mattwmaster58 commented Mar 14, 2020

My guess is that you are nearing the sending/receive limit of websocket messages. I don't know them off the top of my head, but I'm guessing it's either 100Mb or 256Mb.

@y573724537
Copy link

Any idea? I got this error too.

@y573724537
Copy link

puppeteer version: 2.1.0
OS: centos
Node.js version: v12.15.0

@Mattwmaster58
Copy link

If anyone wants to test my theory, I'd recommend looping around, taking a screenshot, logging the screenshot's size, and increasing the viewport.

@danstarns
Copy link

danstarns commented May 14, 2020

Puppeteer 3.0.4
FROM node:12-slim
Using --window-size=2480,3508
I tried --disable-dev-shm-usage No luck!

FIX:
I had content that contained <script> tags & puppeteer reasonably refused to render them

@fchwpo
Copy link

fchwpo commented Jun 30, 2020

Any update on this issue

@NikolaiSilver
Copy link

I have the same problem, any updates?

@snehalkulkarni20
Copy link

I am seeing similar issues. Any update on this ?

Puppeteer - latest version
Executing on Headless Chrome

Error: Protocol error (Page.captureScreenshot): Cannot take screenshot with 0 width. at /mnt/tmp/local.prod/source/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:208:63 at CDPSession.send (/mnt/tmp/local.prod/source/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:207:16) at Page._screenshotTask (/mnt/tmp/local.prod/source/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js:1092:43)

@StephenLover
Copy link

StephenLover commented Oct 7, 2020

Hi I am experiencing the same issue, any update?

Error: Error: Protocol error (Page.captureScreenshot): Unable to capture screenshot

@Mattwmaster58
Copy link

Here's where the error is raised in the Chrome source code, I think. This makes it seems like a Chrome issue.

@whoisjuan
Copy link

Seeing this error in long viewports as well.

@Ennazk
Copy link

Ennazk commented Dec 1, 2020

Same here. Can't take a screenshot of a large viewport.

@caramdache
Copy link

Same here.

@ArtTkachenko
Copy link

Same here.
Centos 7,
Puppeteer 8.0.0
Issue on production setup (2 cores, 7 gb RAM, not Docker container), locally and in Docker container will take bigger screenshots than on production.

Run puppeteer with puppeteer-cluster.
Puppeteer launch config:

{ dumpio: true, args: [ '--no-sandbox', '--disable-web-security', '--disable-gpu', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--full-memory-crash-report', '--enable-crash-reporter', '--crash-dumps-dir=/tmp/chrome', '--unlimited-storage', '--ignore-certificate-errors' ], defaultViewport: { width: 1920, height: 1080, deviceScaleFactor: 2 } }

Errors:

Protocol error (Page.captureScreenshot): Unable to capture screenshot)

From dumpio got next messages:

ERROR:browser_child_process_host_impl.cc(747)] Terminating child process for bad message: Received bad user message: Validation failed for viz.mojom.CopyOutputResultSender.0 [VALIDATION_ERROR_DESERIALIZATION_FAILED]
WARNING:gpu_process_host.cc(1296)] The GPU process has crashed 1 time(s)
Dec 02 03:25:44 app-charts-renderer-1 node[3164]

@ArtTkachenko
Copy link

@bmblb Did you solve (somehow) this issue?

@guilhermebentomarques
Copy link

same here

@Gvozdik-Darya
Copy link

the problem is still relevant

@ArtTkachenko
Copy link

Confirm, problem still actual.

@roysG
Copy link

roysG commented Apr 8, 2022

Still hapenning

@skinfans
Copy link

The problem is actual

@Zebraslive
Copy link

wtf. just randomly started happening. i was using my script literally minutes before and now i can't use it at all. no idea what's changed.

@ArtTkachenko
Copy link

ArtTkachenko commented 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.

@AmanSin001
Copy link

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.

This is working properly

@alexlonginc
Copy link

alexlonginc commented Jul 25, 2022

This doesn't address the underlying issue but I was getting this error and found that when I removed the fullPage: true parameter from the screenshot call the error went away and I was able to take screenshots without issue.

@ki412412
Copy link

I tried the same method as @alexlonginc mentioned and the error no longer occurred.

@OrKoN OrKoN added the confirmed label Sep 6, 2022
@OrKoN
Copy link
Collaborator

OrKoN commented Sep 6, 2022

I believe there could be a limit on the browser side about how big a screenshot can be. We will need to investigate.

@Frontesque
Copy link

This doesn't address the underlying issue but I was getting this error and found that when I removed the fullPage: true parameter from the screenshot call the error went away and I was able to take screenshots without issue.

thank you so much!!

@ki412412
Copy link

This issue is reported on the chrome dev community as well and it is still open.
https://bugs.chromium.org/p/chromium/issues/detail?id=770769&desc=2

@shubham-scaletech
Copy link

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.

I was running pupeteer on lambda function and i got same error. for me this worked. i increased ephemeral storage of lambda.

@OrKoN OrKoN added the P3 label Mar 21, 2024
@tedyyu
Copy link

tedyyu commented Apr 30, 2024

Still happens to "puppeteer": "^22.6.0" (npm) in 2024.

Removing fullPage:true will get a truncated screenshot, not as intended :-)

After wasting one day, I observed that it's related to the hardware. The same web page can be captured with fullPage screenshot on powerful machines but failed on another Azure B1s VM (1 vcpu, 1 GB memory). The same for Playwright. Therefore I can conclude it's a chromium issue.

@daveroberts
Copy link

The same web page can be captured with fullPage screenshot on powerful machines

@tedyyu : To be clear, do you mean powerful machines running in Azure, or not in the cloud?

@tedyyu
Copy link

tedyyu commented Apr 30, 2024

The same web page can be captured with fullPage screenshot on powerful machines

@tedyyu : To be clear, do you mean powerful machines running in Azure, or not in the cloud?

Hi,
It doesn't matter at all where the power machine is.
In my example, my ec2 VM (actually after I check, it's a t2.micro: 1vcpu, 1GiB running Ubuntu 20.04), which is not that powerful, works well, and my powerful M2 mac is good too.
Failed azure VM is Ubuntu 22.04, I have avoid to use it for taking screenshot of a long mobile page.

@epDHowwD
Copy link

No new info here, just summary with some details of what was already said.

Summary

I found in render.js (for me in /usr/local/lib/node_modules/svgexport/) one can change launch of puppeteer to add extra options:

  var browser = await puppeteer.launch({
    headless: true,
    dumpio: true,
    args: ['--no-sandbox', '--font-render-hinting=none', '--force-gpu-mem-available-mb=4096']
  });

Adding dumpio: true, helped me to see my particular problem when rendering (for me) x4 which was that the image was only partially rendered in this scale:

[0511/144557.523227:ERROR:tile_manager.cc(793)] WARNING: tile memory limits exceeded, some content may not draw

Adding '--force-gpu-mem-available-mb=4096' helped me to fix this. (This came from here).

Beginning with x7 I get a crash of the graphic driver:

[0511/150628.898206:ERROR:validation_errors.cc(76)] Invalid message: VALIDATION_ERROR_DESERIALIZATION_FAILED (viz.mojom.CopyOutputResultSender.0 )
[0511/150628.899182:ERROR:browser_child_process_host_impl.cc(726)] Terminating child process for bad message: Received bad user message: Validation failed for viz.mojom.CopyOutputResultSender.0  [VALIDATION_ERROR_DESERIALIZATION_FAILED (viz.mojom.CopyOutputResultSender.0 )]
[0511/150629.356837:WARNING:gpu_process_host.cc(1217)] The GPU process has crashed 1 time(s)
[0511/150629.716893:WARNING:gpu_process_host.cc(980)] Reinitialized the GPU process after a crash. The reported initialization time was 290 ms
[0511/150800.959810:ERROR:validation_errors.cc(76)] Invalid message: VALIDATION_ERROR_DESERIALIZATION_FAILED (viz.mojom.CopyOutputResultSender.0 )
[0511/150800.959883:ERROR:browser_child_process_host_impl.cc(726)] Terminating child process for bad message: Received bad user message: Validation failed for viz.mojom.CopyOutputResultSender.0  [VALIDATION_ERROR_DESERIALIZATION_FAILED (viz.mojom.CopyOutputResultSender.0 )]
[0511/150801.238527:WARNING:gpu_process_host.cc(1217)] The GPU process has crashed 2 time(s)
[0511/150801.587723:WARNING:gpu_process_host.cc(980)] Reinitialized the GPU process after a crash. The reported initialization time was 278 ms
Error: Protocol error (Page.captureScreenshot): Unable to capture screenshot

... just as said earlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests