I try to test a example of WebRequest APIs, but throw error:
“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 is exactly the example 1
Chrome extension functions (which includes the webRequest API) cannot be used in content scripts (
foo.jsin 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.