proxy

翻译不完整。 请帮助我们翻译这篇文章!

Warning
不推荐使用 proxy.register() 或者 proxy.unregister() 方法使用 Proxy Auto-Configuration (PAC) file. 这个 API 将会在 Firefox 68 中废弃并且在 Firefox 71中删除.

使用proxy API来代理web请求。你可以使用proxy.onRequest事件监听器来拦截web请求,并且返回一个可以描述是否代理并且怎样代理它们的对象。

proxy.onRequest的好处在于,用于实现你拦截策略的代码在你的扩展的后台脚本运行,所以,它可以让WebExtension APIs能够完全的访问你的扩展(举例来说,可以访问你扩展的storage和像dns等类似的网络api)

除了这个api,扩展也能够使用browserSettings.proxyConfig属性来重新编辑你全局的proxy设置

Chrome浏览器提供了一个叫做'proxy'api扩展,它的功能跟这个api类似,在chrome的api中也可以用来实现一个拦截策略。然而,Chrome 的API的设计跟这个API设计完全不同。因为这个API跟谷歌的proxyAPI完全不同, 这个API只能通过'browser'命名空间访问

如果你想用这个API你需要得到'proxy'的permission.并且,如果你想拦截一个请求,你同样也需要当前拦截请求的url的 host permission

Types

proxy.ProxyInfo
Describes a proxy.
proxy.RequestDetails

Contains information about a web request that the browser is about to make.

Properties

proxy.settings
Get and set proxy settings.

Functions

proxy.register()
Registers the given proxy script.
proxy.unregister()
Unregisters the proxy script.

Events

proxy.onError
Fired when the system encounters an error running the PAC script or the onRequest listener.
proxy.onRequest
Fired when a web request is about to be made, giving the extension an opportunity to proxy it.

Example extensions

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaSafariFirefox for Android
onErrorChrome No support NoEdge No support NoFirefox Full support 60
Full support 60
No support 55 — 71
Alternate Name
Alternate Name Uses the non-standard name: onProxyError
Opera No support NoSafari No support NoFirefox Android Full support 60
Full support 60
Full support 55
Alternate Name
Alternate Name Uses the non-standard name: onProxyError
onRequestChrome No support NoEdge No support NoFirefox Full support 60
Notes
Full support 60
Notes
Notes Before version 78, the tabId and windowId filter properties are ignored.
Opera No support NoSafari No support NoFirefox Android Full support 60
ProxyInfoChrome No support NoEdge No support NoFirefox Full support 60Opera No support NoSafari No support NoFirefox Android Full support 60
RequestDetailsChrome No support NoEdge No support NoFirefox Full support 60Opera No support NoSafari No support NoFirefox Android Full support 60
register
Deprecated
Chrome No support NoEdge No support NoFirefox No support 56 — 71
No support 56 — 71
Full support 55
Alternate Name
Alternate Name Uses the non-standard name: registerProxyScript
Opera No support NoSafari No support NoFirefox Android Full support 56
Full support 56
Full support 55
Alternate Name
Alternate Name Uses the non-standard name: registerProxyScript
settingsChrome No support NoEdge No support NoFirefox Full support 60
Notes
Full support 60
Notes
Notes In version 59, this property was listed as proxyConfig in the browserSettings namespace, but it had a bug that made it mostly unusable.
Opera No support NoSafari No support NoFirefox Android No support No
unregister
Deprecated
Chrome No support NoEdge No support NoFirefox No support 56 — 71Opera No support NoSafari No support NoFirefox Android Full support 56

Legend

Full support  
Full support
No support  
No support
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
Uses a non-standard name.
Uses a non-standard name.