Chrome 扩展程序获取 POST 请求数据
我正在尝试使用 chrome 扩展获取 POST
请求的 formData
。我正在使用以下 manifest.json
文件和 background.js
文件。但是,当我 console.log requestBody 时,我看不到网站发送的 formData。如何获取表单元素?
manifest.json
{
"manifest_version": 2,
"name": "Form Data",
"description": "Looks at some form data.",
"version": "0.9",
"background": {
"scripts": ["background.js"]
},
"permissions": [
"webRequest",
"webRequestBlocking",
"<all_urls>"
]
}
background.js
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if(details.method == "POST")
console.log(JSON.stringify(details));
},
{urls: ["<all_urls>"]},
["requestBody"]
);
响应示例:
{"frameId":0,"initiator":"https://example.com","method":"POST","parentFrameId":-1,"requestBody":{"raw":[{"bytes":{}}]},"requestId":"13910","tabId":430,"timeStamp":1645826234368.5469,"type":"xmlhttprequest","url":"https://www.example.com/api/v4/login"}
I am trying to get the formData
of a POST
request with a chrome extension. I am using the following manifest.json
file and background.js
file. However, when I console.log the requestBody I cannot see the formData which was sent by the website. How can I get the form elements?
manifest.json
{
"manifest_version": 2,
"name": "Form Data",
"description": "Looks at some form data.",
"version": "0.9",
"background": {
"scripts": ["background.js"]
},
"permissions": [
"webRequest",
"webRequestBlocking",
"<all_urls>"
]
}
background.js
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if(details.method == "POST")
console.log(JSON.stringify(details));
},
{urls: ["<all_urls>"]},
["requestBody"]
);
Example Response:
{"frameId":0,"initiator":"https://example.com","method":"POST","parentFrameId":-1,"requestBody":{"raw":[{"bytes":{}}]},"requestId":"13910","tabId":430,"timeStamp":1645826234368.5469,"type":"xmlhttprequest","url":"https://www.example.com/api/v4/login"}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论