从Chrome API onCompleted方法获取请求和响应正文 [英] get request and response body from Chrome API onCompleted method

查看:101
本文介绍了从Chrome API onCompleted方法获取请求和响应正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何记录请求和响应正文,Chrome API onCompleted 方法提供了记录响应标头的方法.不打开开发人员工具怎么办?

How to record request and response body, chrome API onCompleted method is giving to record response header. How to do without opening developer tool?

我正在开发一个Chrome扩展程序,我应该在其中捕获全部请求和响应.当前,对于响应,我能够单独捕获响应头,是否有办法捕获整个响应主体?我查看了所有的Chrome API,并包括了 onComplete 方法,该方法提供了仅捕获响应标头的选项.另外,我想在不打开开发人员工具的情况下捕获此响应正文.

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"]);
}

推荐答案

我使用一种简单的方法来控制它.基于请求和响应的字段 requestId .

创建一个全局Map,当事件请求标头到达时,使用键 requestId 将其放入地图中.请记住,完成后将其从地图上删除,否则您的背景页面可能会由于内存不足而崩溃.

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扩展程序-其他方式比chrome.devtools.network读取响应正文?

这篇关于从Chrome API onCompleted方法获取请求和响应正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆