问题
How to record request and response body, chrome API onCompleted method is giving to record response header. How to do without opening developer tool?
I am developing a Chrome extension where I should capture total request and response. Currently, for the response, I'm able to capture response headers alone, is there a way to capture the entire response body? I have looked all the Chrome APIs and include onComplete method it is giving the option to capture response header only. Also, I want to capture this response body without opening the developer tools.
function recordData() {
chrome.webRequest.onCompleted.addListener(function(recordStatus) {
console.log("Recording Data" + recordStatus);
}, {
urls: ["http://*/*", "https://*/*"]
}, ["responseHeaders"]);
}
回答1:
I use a simple way to control this. Based on field requestId of both request and response.
Create a global Map, when event request header arrive, put it into the map with key requestId. remember to remove it from the map when finished, or your background page may crash as Out of Memory.
Chrome extensions - Other ways to read response bodies than chrome.devtools.network?
来源:https://stackoverflow.com/questions/48336167/get-request-and-response-body-from-chrome-api-oncompleted-method