You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome扩展报错Uncaught TypeError:无法读取onAuthRequired属性求助

问题根源

你把webrequest.js同时配置成了内容脚本和后台脚本,这就是错误的核心原因:

  • 内容脚本是注入到网页上下文运行的,网页环境没有权限访问chrome.webRequest这类扩展专属API,所以执行到chrome.webRequest.onAuthRequired时会抛出Cannot read properties of undefined错误
  • 后台脚本运行在扩展独立的后台环境中,拥有完整的扩展API调用权限,因此后台控制台能正常输出日志

解决方法

直接修改manifest.json,移除content_scripts字段下对webrequest.js的引用——你的自动登录逻辑只需要在后台监听网络请求,完全不需要注入到网页中。

修改后的manifest.json如下:

{
  "manifest_version": 2,
  "name": "Authentication",
  "description": "This chrome extension is used to auto load the automation users while running the test on Jenkins",
  "version": "2.1.0",
  "author": "",
  "permissions": [
    "storage",
    "<all_urls>",
    "webRequest",
    "webRequestBlocking",
    "management"
  ],
  "background": {
    "scripts": ["webrequest.js"]
  },
  "icons": {
    "128": "/images/icon128.png",
    "48": "/images/icon48.png",
    "32": "/images/icon32.png",
    "16": "/images/icon16.png"
  }
}

验证方式

修改完成后重新加载扩展:

  • 主浏览器控制台不会再出现Uncaught TypeError错误
  • 通过「Inspect view: background page for the extension」查看后台控制台,依然能正常看到请求拦截、凭证传递的日志输出

内容的提问来源于stack exchange,提问作者himanshu gusain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 11:06:19