[英]Chrome.webRequest API - requestBody always undefined
I am trying to use the webrequest api in my Chrome extension. 我正在尝试在Chrome扩展程序中使用webrequest api。 Using the following block of code: 使用以下代码块:
$(document).ready(function(){
chrome.webRequest.onBeforeRequest.addListener(
function(details)
{
console.log(details.requestBody);
},
{urls: ["https://myurlhere.com/*"]}
);});
The console shows me that requestBody is undefined. 控制台告诉我requestBody未定义。 If I log details by itself, I can inspect the details object, but I can't seem to find requestBody object anywhere. 如果我自己记录细节,我可以检查详细信息对象,但我似乎无法在任何地方找到requestBody对象。
Is my syntax wrong? 我的语法错了吗? I did some searching and found a couple other examples and it seems like it should be working the way I have it. 我做了一些搜索,发现了其他一些例子,看起来应该按照我的方式工作。 Any help is appreciated. 任何帮助表示赞赏。
You must specify ['requestBody'] as the third parameter of addListener. 您必须将['requestBody']指定为addListener的第三个参数。 For example: 例如:
chrome.webRequest.onBeforeRequest.addListener(
function(details)
{
console.log(details.requestBody);
},
{urls: ["https://myurlhere.com/*"]},
['requestBody']
);
The documentation says: 文件说:
requestBody ( optional object ) requestBody(可选对象)
Contains the HTTP request body data. *Only provided if extraInfoSpec contains 'requestBody'.*
Note that adding requestBody
to addListener()
would work, provided the request actually has a request body. 请注意, 只要请求实际上有请求正文,将requestBody
添加到addListener()
就可以了。
Most HTTP requests do not have any request body. 大多数HTTP请求没有任何请求正文。 In other words, getting undefined
for e.requestBody
is normal if the request does not have a request body. 换句话说,如果请求没有请求主体, e.requestBody
获取undefined
是正常的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.