chrome.proxy Stay organized with collections Save and categorize content based on your preferences.
Description
Use thechrome.proxy API to manage Chrome's proxy settings. This API relies on theChromeSetting prototype of the type API for getting and setting the proxy configuration.
Permissions
proxyYou must declare the "proxy" permission in theextension manifest to use the proxy settingsAPI. For example:
{"name":"My extension",..."permissions":["proxy"],...}Concepts and usage
Proxy settings are defined in aproxy.ProxyConfig object. Depending on Chrome's proxy settings,the settings may containproxy.ProxyRules or aproxy.PacScript.
Proxy modes
A ProxyConfig object'smode attribute determines the overall behavior of Chrome with regards toproxy usage. It can take the following values:
direct- In
directmode all connections are created directly, without any proxy involved. This mode allowsno further parameters in theProxyConfigobject. auto_detect- In
auto_detectmode the proxy configuration is determined by a PAC script that can be downloadedathttp://wpad/wpad.dat. This mode allows no further parameters in theProxyConfigobject. pac_script- In
pac_scriptmode the proxy configuration is determined by a PAC script that is either retrievedfrom the URL specified in theproxy.PacScriptobject or taken literally from thedataelementspecified in theproxy.PacScriptobject. Besides this, this mode allows no further parametersin theProxyConfigobject. fixed_servers- In
fixed_serversmode the proxy configuration is codified in aproxy.ProxyRulesobject. Itsstructure is described inProxy rules. Besides this, thefixed_serversmode allows no furtherparameters in theProxyConfigobject. system- In
systemmode the proxy configuration is taken from the operating system. This mode allows nofurther parameters in theProxyConfigobject. Note that thesystemmode is different fromsetting no proxy configuration. In the latter case, Chrome falls back to the system settings only ifno command-line options influence the proxy configuration.
Proxy rules
Theproxy.ProxyRules object can contain either asingleProxy attribute or a subset ofproxyForHttp,proxyForHttps,proxyForFtp, andfallbackProxy.
In the first case, HTTP, HTTPS and FTP traffic is proxied through the specified proxy server. Othertraffic is sent directly. In the latter case the behavior is slightly more subtle: If a proxy serveris configured for the HTTP, HTTPS or FTP protocol, the respective traffic is proxied through thespecified server. If no such proxy server is specified or traffic uses a different protocol thanHTTP, HTTPS or FTP, thefallbackProxy is used. If nofallbackProxy is specified, traffic is sentdirectly without a proxy server.
Proxy server objects
A proxy server is configured in aproxy.ProxyServer object. The connection to the proxy server(defined by thehost attribute) uses the protocol defined in thescheme attribute. If noscheme is specified, the proxy connection defaults tohttp.
If noport is defined in aproxy.ProxyServer object, the port is derived from the scheme.The default ports are:
| Scheme | Port |
|---|---|
| http | 80 |
| https | 443 |
| socks4 | 1080 |
| socks5 | 1080 |
Bypass list
Individual servers may be excluded from being proxied with thebypassList. This list may containthe following entries:
[SCHEME://]HOST_PATTERN[:PORT]Match all hostnames that match the pattern
HOST_PATTERN. A leading"."is interpreted as a"*.".Examples:
"foobar.com", "*foobar.com", "*.foobar.com", "*foobar.com:99", "https://x.*.y.com:99".Pattern Matches Does not match ".foobar.com""www.foobar.com""foobar.com""*.foobar.com""www.foobar.com""foobar.com""foobar.com""foobar.com""www.foobar.com""*foobar.com""foobar.com","www.foobar.com","foofoobar.com"[SCHEME://]IP_LITERAL[:PORT]Match URLs that are IP address literals. Conceptually this is the similar to the first case, butwith special cases to handle IP literal canonicalization. For example, matching on "[0:0:0::1]"is the same as matching on "[::1]" because the IPv6 canonicalization is done internally.
Examples:
127.0.1,[0:0::1],[::1]:80,https://[::1]:443IP_LITERAL/PREFIX_LENGTH_IN_BITSMatch any URL containing an IP literal (
IP_LITERAL) within the givenrange. The IP range (PREFIX_LENGTH_IN_BITS) is specified usingCIDRnotation.Match any URL containing an IP literal within the given range. The IP range is specified using CIDRnotation.Examples:
"192.168.1.1/16", "fefe:13::abc/33"<local>The literal string
<local>matches simple hostnames. A simple hostname is one that contains nodots and is not an IP literal. For instanceexampleandlocalhostare simple hostnames,whereasexample.com,example., and[::1]are not.Example:
"<local>"
Examples
The following code sets a SOCKS 5 proxy for HTTP connections to all servers but foobar.com and usesdirect connections for all other protocols. The settings apply to regular and incognito windows, asincognito windows inherit settings from regular windows. See also theTypes APIdocumentation.
varconfig={mode:"fixed_servers",rules:{proxyForHttp:{scheme:"socks5",host:"1.2.3.4"},bypassList:["foobar.com"]}};chrome.proxy.settings.set({value:config,scope:'regular'},function(){});The following code sets a custom PAC script.
varconfig={mode:"pac_script",pacScript:{data:"function FindProxyForURL(url, host) {\n"+" if (host == 'foobar.com')\n"+" return 'PROXY blackhole:80';\n"+" return 'DIRECT';\n"+"}"}};chrome.proxy.settings.set({value:config,scope:'regular'},function(){});The next snippet queries the current effective proxy settings. The effective proxy settings can bedetermined by another extension or by a policy. See theTypes API documentation for details.
chrome.proxy.settings.get({'incognito':false},function(config){console.log(JSON.stringify(config));});Note that thevalue object passed toset() is not identical to thevalue object passed tocallback function ofget(). The latter will contain arules.proxyForHttp.port element.
Types
Mode
Enum
"direct" "auto_detect" "pac_script" "fixed_servers" "system"
PacScript
An object holding proxy auto-config information. Exactly one of the fields should be non-empty.
Properties
- data
string optional
A PAC script.
- mandatory
boolean optional
If true, an invalid PAC script will prevent the network stack from falling back to direct connections. Defaults to false.
- url
string optional
URL of the PAC file to be used.
ProxyConfig
An object encapsulating a complete proxy configuration.
Properties
- mode
'direct' = Never use a proxy'auto_detect' = Auto detect proxy settings'pac_script' = Use specified PAC script'fixed_servers' = Manually specify proxy servers'system' = Use system proxy settings
- pacScript
PacScript optional
The proxy auto-config (PAC) script for this configuration. Use this for 'pac_script' mode.
- rules
ProxyRules optional
The proxy rules describing this configuration. Use this for 'fixed_servers' mode.
ProxyRules
An object encapsulating the set of proxy rules for all protocols. Use either 'singleProxy' or (a subset of) 'proxyForHttp', 'proxyForHttps', 'proxyForFtp' and 'fallbackProxy'.
Properties
- bypassList
string[] optional
List of servers to connect to without a proxy server.
- fallbackProxy
ProxyServer optional
The proxy server to be used for everthing else or if any of the specific proxyFor... is not specified.
- proxyForFtp
ProxyServer optional
The proxy server to be used for FTP requests.
- proxyForHttp
ProxyServer optional
The proxy server to be used for HTTP requests.
- proxyForHttps
ProxyServer optional
The proxy server to be used for HTTPS requests.
- singleProxy
ProxyServer optional
The proxy server to be used for all per-URL requests (that is http, https, and ftp).
ProxyServer
An object encapsulating a single proxy server's specification.
Properties
- host
string
The hostname or IP address of the proxy server. Hostnames must be in ASCII (in Punycode format). IDNA is not supported, yet.
- port
number optional
The port of the proxy server. Defaults to a port that depends on the scheme.
- scheme
Scheme optional
The scheme (protocol) of the proxy server itself. Defaults to 'http'.
Scheme
Enum
"http" "https" "quic" "socks4" "socks5"
Properties
settings
Proxy settings to be used. The value of this setting is a ProxyConfig object.
Events
onProxyError
chrome.proxy.onProxyError.addListener(
callback: function,
)
Notifies about proxy errors.
Parameters
- callback
function
The
callbackparameter looks like:(details: object) => void
- details
object
- details
string
Additional details about the error such as a JavaScript runtime error.
- error
string
The error description.
- fatal
boolean
If true, the error was fatal and the network transaction was aborted. Otherwise, a direct connection is used instead.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-11 UTC.