chrome扩展onbeforesendheaders清单v3

f0ofjuux  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(470)

我正在使用清单版本3进行chrome扩展,我想使用onbeforesendheaders
在my content.js脚本中获取一些标题值。
我不知道如何设置我的清单来使用它,因为我必须在版本3上这样做

这是我的舱单

{
  "name": "Extension Title",
  "description": "Extension Description",
  "version": "1.0",
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["content.js"],
      "all_frames": true,
      "run_at": "document_start"
    }
  ],
  "manifest_version": 3,
  "background": {
    "service_worker": "background.js"
  },
  "permissions": [
    "cookies",
    "activeTab",
    "tabs",
    "storage",
    "webNavigation",
    "webRequest",
    "contextMenus"
  ],
  "host_permissions": [
    "*://*.example.com/"
  ],
  "action": {
    "default_title": "Extension Title Here",
    "default_popup": "popup.html",
    "default_icon": {
        "16": "images/icon16.png",
        "24": "images/icon24.png",
        "32": "images/icon32.png",
        "40": "images/icon32.png",
        "128": "images/icon32.png"
      }
  }
}

我的内容脚本

chrome.webRequest.onBeforeSendHeaders.addListener(
    (e) => {
        for (var n = 0; n < e.requestHeaders.length; n++){
            if ("example-header" == e.requestHeaders[n].name.toLowerCase()) {
                exampleHeader = e.requestHeaders[n].value;
                console.log(exampleHeader);
                break
            }
        }
    });

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题