get request and response body from Chrome API onCompleted method

非 Y 不嫁゛ 提交于 2021-01-28 08:40:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!