Chrome 扩展程序获取 POST 请求数据

发布于 2025-01-10 06:07:42 字数 1070 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文