• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<div id="pageData-name" class="pageData">Proxy Settings</div>
2
3<!-- BEGIN AUTHORED CONTENT -->
4<p id="classSummary">
5Use the <code>chrome.experimental.proxysettings</code> module to manage Chrome's
6proxy settings. This module is still experimental. For information on how to use
7experimental APIs, see the <a href="experimental.html">chrome.experimental.*
8  APIs</a> page.
9</p>
10
11<h2 id="manifest">Manifest</h2>
12<p>You must declare the "proxy" permission
13in the <a href="manifest.html">extension manifest</a>
14to use the proxy settings API.
15For example:</p>
16<pre>{
17  "name": "My extension",
18  ...
19  <b>"permissions": [
20    "experimental", "proxy"
21  ]</b>,
22  ...
23}</pre>
24
25<h2 id="description">Objects and properties</h2>
26
27<p>
28Proxy settings are defined in a
29<a href="#type-ProxyConfig"><code>ProxyConfig</code></a> object. Depending on
30Chrome's proxy settings, the settings may contain
31<a href="#type-ProxyRules"><code>ProxyRules</code></a> or a <a
32  href="#type-PacScript"><code>PacScript</code></a>.
33</p>
34
35<h3 id="proxy_modes">Proxy modes</h3>
36
37<p>
38A ProxyConfig object's <code>mode</code> attribute determines the overall
39behavior of Chrome with regards to proxy usage. It can take the following
40values:
41<dl>
42  <dt><code>direct</code></dt>
43  <dd>In <code>direct</code> mode all connections are created directly, without
44  any proxy involved. This mode allows no further parameters in the
45  <code>ProxyConfig</code> object.</dd>
46
47  <dt><code>auto_detect</code></dt>
48  <dd>In <code>auto_detect</code> mode the proxy configuration is determined by
49  a PAC script that can be downloaded at
50  <a href="http://wpad/wpad.dat">http://wpad/wpad.dat</a>.
51  This mode allows no further parameters in the <code>ProxyConfig</code>
52  object.</dd>
53
54  <dt><code>pac_script</code></dt>
55  <dd>In <code>pac_script</code> mode the proxy configuration is determined by
56  a PAC script that is either retrieved from the URL specified in the
57  <a href="#type-PacScript"><code>PacScript</code></a> object or
58  taken literally from the <code>data</code> element specified in the
59  <a href="#type-PacScript"><code>PacScript</code></a> object.
60  Besides this, this mode allows no further parameters in the
61  <code>ProxyConfig</code> object.</dd>
62
63  <dt><code>fixed_servers</code></dt>
64  <dd>In <code>fixed_servers</code> mode the proxy configuration is codified in
65  a <a href="#type-ProxyRules><code>ProxyRules"><code>ProxyRules</code></a>
66  object. Its structure is described in <a href="#proxy_rules">Proxy rules</a>.
67  Besides this, the <code>fixed_servers</code> mode allows no further parameters
68  in the <code>ProxyConfig</code> object.</dd>
69
70  <dt><code>system</code></dt>
71  <dd>In <code>system</code> mode the proxy configuration is taken from the
72  operating system. This mode allows no further parameters in the
73  <code>ProxyConfig</code> object. Note that the <code>system</code> mode is
74  different from setting no proxy configuration. In the latter case, Chrome
75  falls back to the system settings only if no command-line options influence
76  the proxy configuration.</dd>
77</dl>
78</p>
79
80<h3 id="proxy_rules">Proxy rules</h3>
81
82<p>
83The <a href="#type-ProxyRules"><code>ProxyRules</code></a> object can contain
84either a <code>singleProxy</code> attribute or a subset of
85<code>proxyForHttp</code>, <code>proxyForHttps</code>, <code>proxyForFtp</code>,
86and <code>fallbackProxy</code>.
87</p>
88
89<p>
90In the first case, HTTP, HTTPS and FTP traffic is proxied through the specified
91proxy server. Other traffic is sent directly. In the latter case the behavior is
92slightly more subtle: If a proxy server is configured for the HTTP, HTTPS or FTP
93protocol, the respective traffic is proxied through the specified server. If no
94such proxy server is specified or traffic uses a different protocol than HTTP,
95HTTPS or FTP, the <code>fallbackProxy</code> is used. If no
96<code>fallbackProxy</code> is specified, traffic is sent directly without a
97proxy server.
98</p>
99
100<h3 id="proxy_server_objects">Proxy server objects</h3>
101
102<p>
103A proxy server is configured in a
104<a href="#type-ProxyServer"><code>ProxyServer</code></a> object. The connection
105to the proxy server (defined by the <code>host</code> attribute) uses the
106protocol defined in the <code>scheme</code> attribute. If no <code>scheme</code>
107is specified, the proxy connection defaults to <code>http</code>.
108</p>
109
110<p>
111If no <code>port</code> is defined in a
112<a href="#type-ProxyServer"><code>ProxyServer</code></a> object, the port is
113derived from the scheme. The default ports are:
114<table>
115  <tr><th>Scheme</th><th>Port</th></tr>
116  <tr><td>http</td><td>80</td></tr>
117  <tr><td>https</td><td>443</td></tr>
118  <tr><td>socks4</td><td>1080</td></tr>
119  <tr><td>socks5</td><td>1080</td></tr>
120</table>
121</p>
122
123<h3 id="bypass_list">Bypass list</h3>
124
125<p>
126Individual servers may be excluded from being proxied with the
127<code>bypassList</code>. This list may contain the following entries:
128<dl>
129  <dt><code>[<em>&lt;scheme&gt;</em>://]<em>&lt;host-pattern&gt;</em>[:<em>&lt;port&gt;</em>]</code></dt>
130  <dd>Match all hostnames that match the pattern <em>&lt;host-pattern&gt;</em>.<br>
131  Examples: <code>"foobar.com", "*foobar.com", "*.foobar.com", "*foobar.com:99",
132    "https://x.*.y.com:99"</code></dd>
133
134  <dt><code>[<em>&lt;scheme&gt;</em>://]<em>&lt;ip-literal&gt;</em>[:<em>&lt;port&gt;</em>]</code></dt>
135  <dd>Match URLs that are IP address literals.<br>
136  Conceptually this is the similar to the first case, but with special cases
137  to handle IP literal canonicalization. For example, matching
138  on "[0:0:0::1]" is the same as matching on "[::1]" because
139  the IPv6 canonicalization is done internally.<br>
140  Examples: <code>"127.0.1", "[0:0::1]", "[::1]", "http://[::1]:99"</code></dd>
141
142  <dt><code><em>&lt;ip-literal&gt;</em>/<em>&lt;prefix-length-in-bits&gt;</em></code></dt>
143  <dd>Match any URL containing an IP literal within the given range. The IP
144  range is specified using CIDR notation.<br>
145  Examples: <code>"192.168.1.1/16", "fefe:13::abc/33"</code></dd>
146
147  <dt><code>&lt;local&gt;</code></dt>
148  <dd>Match local addresses. An address is local if the host is "127.0.0.1",
149  "::1", or "localhost".<br>
150  Example: <code>"&lt;local&gt;"</code></dd>
151</dl>
152
153
154<h2 id="precedence">Precedence</h2>
155
156<p>
157Chrome manages settings on different layers. The following list describes the
158layers that may influence the effective proxy settings, in increasing order of
159precedence.
160<ol>
161  <li>System settings provided by the operating system</li>
162  <li>Command line parameters</li>
163  <li>Preferences set by extensions</li>
164  <li>Policies</li>
165</ol>
166</p>
167
168<p>
169As the list implies, policies might overrule any changes that you specify with
170the proxy settings API.
171</p>
172
173<p>
174Chrome allows using different proxy settings for regular windows and incognito
175windows. The following example illustrates the behavior. Assume that no policy
176overrides the proxy settings and that an extension can set proxy settings for
177regular windows <b>(R)</b> and proxy settings for incognito windows <b>(I)</b>.
178</p>
179
180<p>
181<ul>
182  <li>If only <b>(R)</b> is set, these settings are effective for both regular
183  and incognito windows.</li>
184  <li>If only <b>(I)</b> is set, these settings are effective for only incognito
185  windows. Regular windows use the proxy settings determined by the lower layers
186  (command-line options and system settings).</li>
187  <li>If both <b>(R)</b> and <b>(I)</b> are set, the respective settings are
188  used for regular and incognito windows.</li>
189</ul>
190</p>
191
192<p>
193If two extensions want to set proxy settings, the extension installed last takes
194precedence over the other extensions. If the extension installed last sets only
195<b>(I)</b>, the settings of regular windows can be defined by more recently
196installed extensions.
197</p>
198
199
200
201<h2 id="overview-examples">Examples</h2>
202
203<p>
204The following code sets a SOCKS 5 proxy for HTTP connections to all servers but
205foobar.com and uses direct connections for all other protocols. The settings
206apply to regular and incognito windows.
207</p>
208
209<pre>
210var config = {
211  mode: "fixed_servers",
212  rules: {
213    httpProxy: {
214      scheme: "socks5",
215      host: "1.2.3.4"
216    },
217    bypassList: ["foobar.com"]
218  }
219};
220chrome.experimental.proxy.settings.set(
221    {'value': config, 'incognito': false},
222    function() {});
223</pre>
224
225<p>
226The following code sets a custom pac script.
227</p>
228
229<pre>
230var config = {
231  mode: "pac_script",
232  pacScript: {
233    data: "function FindProxyForURL(url, host) {\n" +
234          "  if (host == 'foobar.com')\n" +
235          "    return 'PROXY blackhole:80';\n" +
236          "  return 'DIRECT';\n" +
237          "}"
238  }
239};
240chrome.experimental.proxy.settings.set(
241    {'value': config, 'incognito': false},
242    function() {});
243</pre>
244
245<p>
246The next snippet queries the current proxy settings.
247</p>
248
249<pre>
250chrome.experimental.proxy.settings.get(
251    {'incognito': false},
252    function(config) {console.log(JSON.stringify(config));});
253</pre>
254
255<p>
256Note that the <code>value</code> object passed to <code>set()</code> is not
257identical to the <code>value</code> object passed to callback function of
258<code>get()</code>. The latter will contain a <code>rules.httpProxy.port</code>
259element.
260</p>
261
262<!-- END AUTHORED CONTENT -->
263