CHROME WebRequest API 示例错误:“onBeforeRequest";只能在扩展过程中使用 [英] CHROME WebRequest APIs example error: "onBeforeRequest" can only be used in extension processes

查看:42
本文介绍了CHROME WebRequest API 示例错误:“onBeforeRequest";只能在扩展过程中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试测试 WebRequest APIs,但抛出错误:

I try to test a example of WebRequest APIs, but throw error:

"onBeforeRequest" 只能在扩展进程中使用.manifest.json:

"onBeforeRequest" can only be used in extension processes. manifest.json:

{
    "name": "example",
   "version": "1.0",
  "permissions": [
    "experimental",
    "http://*/*", "https://*/*"
  ],
    "content_scripts": [ {
      "js": [ "foo.js" ],
      "matches": [ "http://*/*", "https://*/*" ],
      "run_at": "document_start"
   } ]
}

foo.js 正是示例 1

推荐答案

Chrome 扩展功能(包括 webRequest API)不能在内容脚本中使用(在您的示例中为 foo.js).如果您希望从内容脚本中使用 webRequest,您可以使用 对话的">消息功能背景页面.后台页面可以直接使用 webRequest 并将响应(如果有)中继回内容脚本.

Chrome extension functions (which includes the webRequest API) cannot be used in content scripts (foo.js in your example). If you wish to use webRequest from a content script, you can use the messaging functionality to talk to the extension's background page. The background page can use webRequest directly and relay the response (if any) back to the content script.

这篇关于CHROME WebRequest API 示例错误:“onBeforeRequest";只能在扩展过程中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆