1 <h2 id=
"manifest">Manifest
</h2>
2 <p>You must declare the
"proxy" permission
3 in the
<a href=
"manifest">extension manifest
</a>
4 to use the proxy settings API.
6 <pre data-filename=
"manifest.json">
8 "name":
"My extension",
17 <h2 id=
"description">Objects and properties
</h2>
20 Proxy settings are defined in a
21 $(ref:proxy.ProxyConfig) object. Depending on
22 Chrome's proxy settings, the settings may contain
23 $(ref:proxy.ProxyRules) or a
24 $(ref:proxy.PacScript).
27 <h3 id=
"proxy_modes">Proxy modes
</h3>
30 A ProxyConfig object's
<code>mode
</code> attribute determines the overall
31 behavior of Chrome with regards to proxy usage. It can take the following
34 <dt><code>direct
</code></dt>
35 <dd>In
<code>direct
</code> mode all connections are created directly, without
36 any proxy involved. This mode allows no further parameters in the
37 <code>ProxyConfig
</code> object.
</dd>
39 <dt><code>auto_detect
</code></dt>
40 <dd>In
<code>auto_detect
</code> mode the proxy configuration is determined by
41 a PAC script that can be downloaded at
42 <a href=
"http://wpad/wpad.dat">http://wpad/wpad.dat
</a>.
43 This mode allows no further parameters in the
<code>ProxyConfig
</code>
46 <dt><code>pac_script
</code></dt>
47 <dd>In
<code>pac_script
</code> mode the proxy configuration is determined by
48 a PAC script that is either retrieved from the URL specified in the
49 $(ref:proxy.PacScript) object or
50 taken literally from the
<code>data
</code> element specified in the
51 $(ref:proxy.PacScript) object.
52 Besides this, this mode allows no further parameters in the
53 <code>ProxyConfig
</code> object.
</dd>
55 <dt><code>fixed_servers
</code></dt>
56 <dd>In
<code>fixed_servers
</code> mode the proxy configuration is codified in
57 a $(ref:proxy.ProxyRules)
58 object. Its structure is described in
<a href=
"#proxy_rules">Proxy rules
</a>.
59 Besides this, the
<code>fixed_servers
</code> mode allows no further parameters
60 in the
<code>ProxyConfig
</code> object.
</dd>
62 <dt><code>system
</code></dt>
63 <dd>In
<code>system
</code> mode the proxy configuration is taken from the
64 operating system. This mode allows no further parameters in the
65 <code>ProxyConfig
</code> object. Note that the
<code>system
</code> mode is
66 different from setting no proxy configuration. In the latter case, Chrome
67 falls back to the system settings only if no command-line options influence
68 the proxy configuration.
</dd>
72 <h3 id=
"proxy_rules">Proxy rules
</h3>
75 The $(ref:proxy.ProxyRules) object can contain
76 either a
<code>singleProxy
</code> attribute or a subset of
77 <code>proxyForHttp
</code>,
<code>proxyForHttps
</code>,
<code>proxyForFtp
</code>,
78 and
<code>fallbackProxy
</code>.
82 In the first case, HTTP, HTTPS and FTP traffic is proxied through the specified
83 proxy server. Other traffic is sent directly. In the latter case the behavior is
84 slightly more subtle: If a proxy server is configured for the HTTP, HTTPS or FTP
85 protocol, the respective traffic is proxied through the specified server. If no
86 such proxy server is specified or traffic uses a different protocol than HTTP,
87 HTTPS or FTP, the
<code>fallbackProxy
</code> is used. If no
88 <code>fallbackProxy
</code> is specified, traffic is sent directly without a
92 <h3 id=
"proxy_server_objects">Proxy server objects
</h3>
95 A proxy server is configured in a
96 $(ref:proxy.ProxyServer) object. The connection
97 to the proxy server (defined by the
<code>host
</code> attribute) uses the
98 protocol defined in the
<code>scheme
</code> attribute. If no
<code>scheme
</code>
99 is specified, the proxy connection defaults to
<code>http
</code>.
103 If no
<code>port
</code> is defined in a
104 $(ref:proxy.ProxyServer) object, the port is
105 derived from the scheme. The default ports are:
107 <tr><th>Scheme
</th><th>Port
</th></tr>
108 <tr><td>http
</td><td>80</td></tr>
109 <tr><td>https
</td><td>443</td></tr>
110 <tr><td>socks4
</td><td>1080</td></tr>
111 <tr><td>socks5
</td><td>1080</td></tr>
115 <h3 id=
"bypass_list">Bypass list
</h3>
118 Individual servers may be excluded from being proxied with the
119 <code>bypassList
</code>. This list may contain the following entries:
121 <dt><code>[
<em><scheme
></em>://]
<em><host-pattern
></em>[:
<em><port
></em>]
</code></dt>
122 <dd>Match all hostnames that match the pattern
<em><host-pattern
></em>.
123 A leading
<code>"."</code> is interpreted as a
<code>"*."</code>.
<br>
124 Examples:
<code>"foobar.com",
"*foobar.com",
"*.foobar.com",
"*foobar.com:99",
125 "https://x.*.y.com:99"</code>.
<br>
132 <td><code>".foobar.com"</code>
133 <td><code>"www.foobar.com"</code>
134 <td><code>"foobar.com"</code>
136 <td><code>"*.foobar.com"</code>
137 <td><code>"www.foobar.com"</code>
138 <td><code>"foobar.com"</code>
140 <td><code>"foobar.com"</code>
141 <td><code>"foobar.com"</code>
142 <td><code>"www.foobar.com"</code>
144 <td><code>"*foobar.com"</code>
145 <td><code>"foobar.com"</code>,
<code>"www.foobar.com"</code>,
146 <code>"foofoobar.com"</code>
151 <dt><code>[
<em><scheme
></em>://]
<em><ip-literal
></em>[:
<em><port
></em>]
</code></dt>
152 <dd>Match URLs that are IP address literals.
<br>
153 Conceptually this is the similar to the first case, but with special cases
154 to handle IP literal canonicalization. For example, matching
155 on
"[0:0:0::1]" is the same as matching on
"[::1]" because
156 the IPv6 canonicalization is done internally.
<br>
157 Examples:
<code>"127.0.1",
"[0:0::1]",
"[::1]",
"http://[::1]:99"</code></dd>
159 <dt><code><em><ip-literal
></em>/
<em><prefix-length-in-bits
></em></code></dt>
160 <dd>Match any URL containing an IP literal within the given range. The IP
161 range is specified using CIDR notation.
<br>
162 Examples:
<code>"192.168.1.1/16",
"fefe:13::abc/33"</code></dd>
164 <dt><code><local
></code></dt>
165 <dd>Match local addresses. An address is local if the host is
"127.0.0.1",
166 "::1", or
"localhost".
<br>
167 Example:
<code>"<local>"</code></dd>
171 <h2 id=
"overview-examples">Examples
</h2>
174 The following code sets a SOCKS
5 proxy for HTTP connections to all servers but
175 foobar.com and uses direct connections for all other protocols. The settings
176 apply to regular and incognito windows, as incognito windows inherit settings
177 from regular windows. Please also consult the
<a
178 href=
"types#ChromeSetting">Types API
</a> documentation.
183 mode:
"fixed_servers",
189 bypassList: [
"foobar.com"]
192 chrome.proxy.settings.set(
193 {value: config, scope: 'regular'},
198 The following code sets a custom PAC script.
205 data:
"function FindProxyForURL(url, host) {\n" +
206 " if (host == 'foobar.com')\n" +
207 " return 'PROXY blackhole:80';\n" +
208 " return 'DIRECT';\n" +
212 chrome.proxy.settings.set(
213 {value: config, scope: 'regular'},
218 The next snippet queries the currently effective proxy settings. The effective
219 proxy settings can be determined by another extension or by a policy. See the
<a
220 href=
"types#ChromeSetting">Types API
</a> documentation for details.
224 chrome.proxy.settings.get(
225 {'incognito': false},
226 function(config) {console.log(JSON.stringify(config));});
230 Note that the
<code>value
</code> object passed to
<code>set()
</code> is not
231 identical to the
<code>value
</code> object passed to callback function of
232 <code>get()
</code>. The latter will contain a
233 <code>rules.proxyForHttp.port
</code> element.