Search code examples
javascriptgoogle-chromegoogle-chrome-extension

Intercept HTTP request body from chrome extension


I'm aware that chrome.webRequest.onBeforeRequest allows a request to be intercepted, analyzed and blocked, but it only allows access to the request headers, and not the request body (as far as i know).

Sample use case: think intercepting form values.

It seems there is a API change proposal here suggesting exactly this.

Is there another way this could be accomplished?

Thanks.


Solution

  • This functionality has been added to the API now, see the documentation.

    In order to access the body you need to do the following:

    chrome.webRequest.onBeforeRequest.addListener(
        function(details)
        {
            console.log(details.requestBody);
        },
        {urls: ["https://myurlhere.com/*"]},
        ['requestBody']
    );