Intercept HTTP request body from chrome extension

前端 未结 3 1145
清酒与你
清酒与你 2020-12-08 21:36

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, an

3条回答
  •  青春惊慌失措
    2020-12-08 21:53

    Here is what I did

    1. I used the requestBody to get the post requests body
    2. I used a decoder the parse the body into a string

    Here is an example

    chrome.webRequest.onBeforeRequest.addListener(
        function(details) {
            if(details.method == "POST")
            // Use this to decode the body of your post
                var postedString = decodeURIComponent(String.fromCharCode.apply(null,
                                          new Uint8Array(details.requestBody.raw[0].bytes)));
               console.log(postedString)
    
        },
        {urls: [""]},
        ["blocking", "requestBody"]
    );
    

提交回复
热议问题