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.

response.buffer() Error After 'requestfinished' Event

See original GitHub issue

I use puppeteer to download video from one site. on the page requestfinished event, all the video has download, so I call var buffer = await response.buffer(); to get the video data.

Downloader.prototype.onResponse = async function(response) {
  let url = response.url();
  let [path, quote] = url.split('?');
  if(path.endsWith('.flv')) {
    let buffer = await response.buffer();
    await this.saveFlv(path, buffer);
  }
}

that works ok, but it occur error occasionally.

  <rejected> { Error: Protocol error (Network.getResponseBody): Target closed.
    at Promise (/Users/kim/code/node_modules/puppeteer/lib/Connection.js:184:56)
    at new Promise (<anonymous>)
    at CDPSession.send (/Users/kim/code/node_modules/puppeteer/lib/Connection.js:183:12)
    at _contentPromise._bodyLoadedPromise.then (/Users/kim/code/node_modules/puppeteer/lib/NetworkManager.js:597:45)
    at <anonymous>
  message: 'Protocol error (Network.getResponseBody): Target closed.' } }  reason: { Error: Protocol error (Network.getResponseBody): Target closed.
    at Promise (/Users/kim/code/node_modules/puppeteer/lib/Connection.js:184:56)
    at new Promise (<anonymous>)
    at CDPSession.send (/Users/kim/code/node_modules/puppeteer/lib/Connection.js:183:12)
    at _contentPromise._bodyLoadedPromise.then (/Users/kim/code/node_modules/puppeteer/lib/NetworkManager.js:597:45)
    at <anonymous>
  message: 'Protocol error (Network.getResponseBody): Target closed.' }

I think it is because the devtools session closed before the requestfinished event. please give me some suggestion. thanks. the version is puppeteer@1.13.0, node v8.11.4 on mac.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
lidanchengcommented, Mar 19, 2019

@aslushnikov thanks for your response. I add some debug log in the WebSocketTransport.js:

    this._ws.addEventListener('close', event => {
      if (this.onclose) {
        console.log("ws close >:", event);
        this.onclose.call(null);
      }
    });

run the code, finally I got the output:

protocol: '',
     _binaryType: 'nodebuffer',
     _closeFrameReceived: false,
     _closeFrameSent: false,
     _closeMessage: '',
     _closeTimer: null,
     _closeCode: 1009,
     _receiver: 
      Receiver {
        ...
        _maxPayload: 104857600,
        _bufferedBytes: 65526,
        _buffers: [Array],
        _compressed: false,
        _payloadLength: 107789193,
        ...
         },

the code 1009 means CLOSE_TOO_LARGE, so I change the WebSocket constructor in WebSocketTransport like this:

 const ws = new WebSocket(url, [], { perMessageDeflate: false , maxPayload:300 * 1024 * 1024});

then I never see the error.

0reactions
stale[bot]commented, Jul 27, 2022

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

response.buffer() Error After 'requestfinished' Event #4174
I use puppeteer to download video from one site. on the page requestfinished event, all the video has download, so I call var...
Read more >
How to get the download stream (buffer) using puppeteer?
I tried (unsuccessfully) to use the page.on("response") event to retrieve the raw response content, acording the following snippet: const bucket ...
Read more >
Does The HTTP Response Stream Need Error Event Handlers ...
When you start programming in Node.js, one of the first things you discover is that a Node.js application is "amusingly" brittle; ...
Read more >
Request | Playwright - CukeTest
If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new request is issued to a...
Read more >
Request (Playwright - Main Library 0.162.3 API) - javadoc.io
the page.on('requestfailed') event is emitted. NOTE HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request....
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