CHROME WebRequest API示例错误:“onBeforeRequest”只能用于扩展过程 [英] CHROME WebRequest APIs example error: "onBeforeRequest" can only be used in extension processes
问题描述
我尝试测试一个 WebRequest
API ,但会抛出错误:
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屋!