1

I am building a Chrome extension and trying to log some requests: the ones with POST parameters (plain text data)

This is the code I'm using:

var requestFilter = {urls: ["<all_urls>"]}; var extraInfoSpec = ['requestHeaders','requestBody','blocking']; // note: without 'requestBody' it works perfectly, but there's no POST data available. var handler = function( details ) { console.log(details); }; chrome.webRequest.onBeforeSendHeaders.addListener(handler, requestFilter, extraInfoSpec); 

I use requestHeaders and blocking for other things that are not in the example (don't worry about them now)

I am getting this error at page load: Uncaught Error: Invalid value for argument 2. Property '.1': Value must be one of: [requestHeaders, blocking].

I am develping under Chrome Version 36.0.1985.125 m

Form chrome webRequest documentation: Stable since Chrome 23. Contains the HTTP request body data. Only provided if extraInfoSpec contains 'requestBody'.

Any experience with this error? Any known solution? How can I solve this?

2
  • The code you posted - is it in the background page or the content page? Commented Jul 22, 2014 at 13:54
  • It's in functions.js (called from manifest in "scripts" param) Commented Jul 22, 2014 at 14:31

1 Answer 1

2

You are listening to the wrong event.

If you look at the documentation, onBeforeSendHeaders does not list requestBody in the callback details.

It is, however, available in onBeforeRequest.

So, if you need both the headers and the body, you have to correlate the two events by requestId.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.