2

I would like to access the request body of HTTP POST requests in the callback registered with onResourceRequested (I didn't find it in the documentation).

I would like to do something like this:

page.onResourceRequested = function(requestData, networkRequest) {
  var body = networkRequest.body // how to do that ?
  console.log(body)
}

How can I access the body of the request in the onResourceRequested callback ?

Michael
  • 41,026
  • 70
  • 193
  • 341

1 Answers1

1

The request body of POST requests are stored in the postData attribute of requestData object. You can retrieve it like so:

page.onResourceRequested = function(requestData, networkRequest) {
  var body = networkRequest.postData
  console.log(body)
}

To note, there doesn't seem to currently be a way to retrieve the request body for any other request methods such as PUT or PATCH.

Davy
  • 81
  • 1
  • 5