OLD | NEW |
1 <!-- BEGIN AUTHORED CONTENT --> | |
2 <p id="classSummary"> | 1 <p id="classSummary"> |
3 Use the <code>chrome.proxy</code> module to manage Chrome's | 2 Use the <code>chrome.proxy</code> module to manage Chrome's |
4 proxy settings. This module relies on the <a href="types.html#ChromeSetting"> | 3 proxy settings. This module relies on the <a href="types.html#ChromeSetting"> |
5 ChromeSetting prototype of the type API</a> for getting and setting the proxy | 4 ChromeSetting prototype of the type API</a> for getting and setting the proxy |
6 configuration. | 5 configuration. |
7 </p> | 6 </p> |
| 7 |
8 <h2 id="manifest">Manifest</h2> | 8 <h2 id="manifest">Manifest</h2> |
9 <p>You must declare the "proxy" permission | 9 <p>You must declare the "proxy" permission |
10 in the <a href="manifest.html">extension manifest</a> | 10 in the <a href="manifest.html">extension manifest</a> |
11 to use the proxy settings API. | 11 to use the proxy settings API. |
12 For example:</p> | 12 For example:</p> |
13 <pre>{ | 13 <pre>{ |
14 "name": "My extension", | 14 "name": "My extension", |
15 ... | 15 ... |
16 <b>"permissions": [ | 16 <b>"permissions": [ |
17 "proxy" | 17 "proxy" |
18 ]</b>, | 18 ]</b>, |
19 ... | 19 ... |
20 }</pre> | 20 }</pre> |
| 21 |
21 <h2 id="description">Objects and properties</h2> | 22 <h2 id="description">Objects and properties</h2> |
| 23 |
22 <p> | 24 <p> |
23 Proxy settings are defined in a | 25 Proxy settings are defined in a |
24 <a href="#type-proxy.ProxyConfig"><code>ProxyConfig</code></a> object. Depending
on | 26 <a href="#type-proxy.ProxyConfig"><code>ProxyConfig</code></a> object. Depending
on |
25 Chrome's proxy settings, the settings may contain | 27 Chrome's proxy settings, the settings may contain |
26 <a href="#type-proxy.ProxyRules"><code>ProxyRules</code></a> or a <a | 28 <a href="#type-proxy.ProxyRules"><code>ProxyRules</code></a> or a <a |
27 href="#type-proxy.PacScript"><code>PacScript</code></a>. | 29 href="#type-proxy.PacScript"><code>PacScript</code></a>. |
28 </p> | 30 </p> |
| 31 |
29 <h3 id="proxy_modes">Proxy modes</h3> | 32 <h3 id="proxy_modes">Proxy modes</h3> |
| 33 |
30 <p> | 34 <p> |
31 A ProxyConfig object's <code>mode</code> attribute determines the overall | 35 A ProxyConfig object's <code>mode</code> attribute determines the overall |
32 behavior of Chrome with regards to proxy usage. It can take the following | 36 behavior of Chrome with regards to proxy usage. It can take the following |
33 values: | 37 values: |
34 <dl> | 38 <dl> |
35 <dt><code>direct</code></dt> | 39 <dt><code>direct</code></dt> |
36 <dd>In <code>direct</code> mode all connections are created directly, without | 40 <dd>In <code>direct</code> mode all connections are created directly, without |
37 any proxy involved. This mode allows no further parameters in the | 41 any proxy involved. This mode allows no further parameters in the |
38 <code>ProxyConfig</code> object.</dd> | 42 <code>ProxyConfig</code> object.</dd> |
| 43 |
39 <dt><code>auto_detect</code></dt> | 44 <dt><code>auto_detect</code></dt> |
40 <dd>In <code>auto_detect</code> mode the proxy configuration is determined by | 45 <dd>In <code>auto_detect</code> mode the proxy configuration is determined by |
41 a PAC script that can be downloaded at | 46 a PAC script that can be downloaded at |
42 <a href="http://wpad/wpad.dat">http://wpad/wpad.dat</a>. | 47 <a href="http://wpad/wpad.dat">http://wpad/wpad.dat</a>. |
43 This mode allows no further parameters in the <code>ProxyConfig</code> | 48 This mode allows no further parameters in the <code>ProxyConfig</code> |
44 object.</dd> | 49 object.</dd> |
| 50 |
45 <dt><code>pac_script</code></dt> | 51 <dt><code>pac_script</code></dt> |
46 <dd>In <code>pac_script</code> mode the proxy configuration is determined by | 52 <dd>In <code>pac_script</code> mode the proxy configuration is determined by |
47 a PAC script that is either retrieved from the URL specified in the | 53 a PAC script that is either retrieved from the URL specified in the |
48 <a href="#type-proxy.PacScript"><code>PacScript</code></a> object or | 54 <a href="#type-proxy.PacScript"><code>PacScript</code></a> object or |
49 taken literally from the <code>data</code> element specified in the | 55 taken literally from the <code>data</code> element specified in the |
50 <a href="#type-proxy.PacScript"><code>PacScript</code></a> object. | 56 <a href="#type-proxy.PacScript"><code>PacScript</code></a> object. |
51 Besides this, this mode allows no further parameters in the | 57 Besides this, this mode allows no further parameters in the |
52 <code>ProxyConfig</code> object.</dd> | 58 <code>ProxyConfig</code> object.</dd> |
| 59 |
53 <dt><code>fixed_servers</code></dt> | 60 <dt><code>fixed_servers</code></dt> |
54 <dd>In <code>fixed_servers</code> mode the proxy configuration is codified in | 61 <dd>In <code>fixed_servers</code> mode the proxy configuration is codified in |
55 a <a href="#type-proxy.ProxyRules><code>ProxyRules"><code>ProxyRules</code></a
> | 62 a <a href="#type-proxy.ProxyRules><code>ProxyRules"><code>ProxyRules</code></a
> |
56 object. Its structure is described in <a href="#proxy_rules">Proxy rules</a>. | 63 object. Its structure is described in <a href="#proxy_rules">Proxy rules</a>. |
57 Besides this, the <code>fixed_servers</code> mode allows no further parameters | 64 Besides this, the <code>fixed_servers</code> mode allows no further parameters |
58 in the <code>ProxyConfig</code> object.</dd> | 65 in the <code>ProxyConfig</code> object.</dd> |
| 66 |
59 <dt><code>system</code></dt> | 67 <dt><code>system</code></dt> |
60 <dd>In <code>system</code> mode the proxy configuration is taken from the | 68 <dd>In <code>system</code> mode the proxy configuration is taken from the |
61 operating system. This mode allows no further parameters in the | 69 operating system. This mode allows no further parameters in the |
62 <code>ProxyConfig</code> object. Note that the <code>system</code> mode is | 70 <code>ProxyConfig</code> object. Note that the <code>system</code> mode is |
63 different from setting no proxy configuration. In the latter case, Chrome | 71 different from setting no proxy configuration. In the latter case, Chrome |
64 falls back to the system settings only if no command-line options influence | 72 falls back to the system settings only if no command-line options influence |
65 the proxy configuration.</dd> | 73 the proxy configuration.</dd> |
66 </dl> | 74 </dl> |
67 </p> | 75 </p> |
| 76 |
68 <h3 id="proxy_rules">Proxy rules</h3> | 77 <h3 id="proxy_rules">Proxy rules</h3> |
| 78 |
69 <p> | 79 <p> |
70 The <a href="#type-proxy.ProxyRules"><code>ProxyRules</code></a> object can cont
ain | 80 The <a href="#type-proxy.ProxyRules"><code>ProxyRules</code></a> object can cont
ain |
71 either a <code>singleProxy</code> attribute or a subset of | 81 either a <code>singleProxy</code> attribute or a subset of |
72 <code>proxyForHttp</code>, <code>proxyForHttps</code>, <code>proxyForFtp</code>, | 82 <code>proxyForHttp</code>, <code>proxyForHttps</code>, <code>proxyForFtp</code>, |
73 and <code>fallbackProxy</code>. | 83 and <code>fallbackProxy</code>. |
74 </p> | 84 </p> |
| 85 |
75 <p> | 86 <p> |
76 In the first case, HTTP, HTTPS and FTP traffic is proxied through the specified | 87 In the first case, HTTP, HTTPS and FTP traffic is proxied through the specified |
77 proxy server. Other traffic is sent directly. In the latter case the behavior is | 88 proxy server. Other traffic is sent directly. In the latter case the behavior is |
78 slightly more subtle: If a proxy server is configured for the HTTP, HTTPS or FTP | 89 slightly more subtle: If a proxy server is configured for the HTTP, HTTPS or FTP |
79 protocol, the respective traffic is proxied through the specified server. If no | 90 protocol, the respective traffic is proxied through the specified server. If no |
80 such proxy server is specified or traffic uses a different protocol than HTTP, | 91 such proxy server is specified or traffic uses a different protocol than HTTP, |
81 HTTPS or FTP, the <code>fallbackProxy</code> is used. If no | 92 HTTPS or FTP, the <code>fallbackProxy</code> is used. If no |
82 <code>fallbackProxy</code> is specified, traffic is sent directly without a | 93 <code>fallbackProxy</code> is specified, traffic is sent directly without a |
83 proxy server. | 94 proxy server. |
84 </p> | 95 </p> |
| 96 |
85 <h3 id="proxy_server_objects">Proxy server objects</h3> | 97 <h3 id="proxy_server_objects">Proxy server objects</h3> |
| 98 |
86 <p> | 99 <p> |
87 A proxy server is configured in a | 100 A proxy server is configured in a |
88 <a href="#type-proxy.ProxyServer"><code>ProxyServer</code></a> object. The conne
ction | 101 <a href="#type-proxy.ProxyServer"><code>ProxyServer</code></a> object. The conne
ction |
89 to the proxy server (defined by the <code>host</code> attribute) uses the | 102 to the proxy server (defined by the <code>host</code> attribute) uses the |
90 protocol defined in the <code>scheme</code> attribute. If no <code>scheme</code> | 103 protocol defined in the <code>scheme</code> attribute. If no <code>scheme</code> |
91 is specified, the proxy connection defaults to <code>http</code>. | 104 is specified, the proxy connection defaults to <code>http</code>. |
92 </p> | 105 </p> |
| 106 |
93 <p> | 107 <p> |
94 If no <code>port</code> is defined in a | 108 If no <code>port</code> is defined in a |
95 <a href="#type-proxy.ProxyServer"><code>ProxyServer</code></a> object, the port
is | 109 <a href="#type-proxy.ProxyServer"><code>ProxyServer</code></a> object, the port
is |
96 derived from the scheme. The default ports are: | 110 derived from the scheme. The default ports are: |
97 <table> | 111 <table> |
98 <tr><th>Scheme</th><th>Port</th></tr> | 112 <tr><th>Scheme</th><th>Port</th></tr> |
99 <tr><td>http</td><td>80</td></tr> | 113 <tr><td>http</td><td>80</td></tr> |
100 <tr><td>https</td><td>443</td></tr> | 114 <tr><td>https</td><td>443</td></tr> |
101 <tr><td>socks4</td><td>1080</td></tr> | 115 <tr><td>socks4</td><td>1080</td></tr> |
102 <tr><td>socks5</td><td>1080</td></tr> | 116 <tr><td>socks5</td><td>1080</td></tr> |
103 </table> | 117 </table> |
104 </p> | 118 </p> |
| 119 |
105 <h3 id="bypass_list">Bypass list</h3> | 120 <h3 id="bypass_list">Bypass list</h3> |
| 121 |
106 <p> | 122 <p> |
107 Individual servers may be excluded from being proxied with the | 123 Individual servers may be excluded from being proxied with the |
108 <code>bypassList</code>. This list may contain the following entries: | 124 <code>bypassList</code>. This list may contain the following entries: |
109 <dl> | 125 <dl> |
110 <dt><code>[<em><scheme></em>://]<em><host-pattern></em>[:<em><p
ort></em>]</code></dt> | 126 <dt><code>[<em><scheme></em>://]<em><host-pattern></em>[:<em><p
ort></em>]</code></dt> |
111 <dd>Match all hostnames that match the pattern <em><host-pattern></em>.<
br> | 127 <dd>Match all hostnames that match the pattern <em><host-pattern></em>.<
br> |
112 Examples: <code>"foobar.com", "*foobar.com", "*.foobar.com", "*foobar.com:99", | 128 Examples: <code>"foobar.com", "*foobar.com", "*.foobar.com", "*foobar.com:99", |
113 "https://x.*.y.com:99"</code></dd> | 129 "https://x.*.y.com:99"</code></dd> |
| 130 |
114 <dt><code>[<em><scheme></em>://]<em><ip-literal></em>[:<em><por
t></em>]</code></dt> | 131 <dt><code>[<em><scheme></em>://]<em><ip-literal></em>[:<em><por
t></em>]</code></dt> |
115 <dd>Match URLs that are IP address literals.<br> | 132 <dd>Match URLs that are IP address literals.<br> |
116 Conceptually this is the similar to the first case, but with special cases | 133 Conceptually this is the similar to the first case, but with special cases |
117 to handle IP literal canonicalization. For example, matching | 134 to handle IP literal canonicalization. For example, matching |
118 on "[0:0:0::1]" is the same as matching on "[::1]" because | 135 on "[0:0:0::1]" is the same as matching on "[::1]" because |
119 the IPv6 canonicalization is done internally.<br> | 136 the IPv6 canonicalization is done internally.<br> |
120 Examples: <code>"127.0.1", "[0:0::1]", "[::1]", "http://[::1]:99"</code></dd> | 137 Examples: <code>"127.0.1", "[0:0::1]", "[::1]", "http://[::1]:99"</code></dd> |
| 138 |
121 <dt><code><em><ip-literal></em>/<em><prefix-length-in-bits></em></
code></dt> | 139 <dt><code><em><ip-literal></em>/<em><prefix-length-in-bits></em></
code></dt> |
122 <dd>Match any URL containing an IP literal within the given range. The IP | 140 <dd>Match any URL containing an IP literal within the given range. The IP |
123 range is specified using CIDR notation.<br> | 141 range is specified using CIDR notation.<br> |
124 Examples: <code>"192.168.1.1/16", "fefe:13::abc/33"</code></dd> | 142 Examples: <code>"192.168.1.1/16", "fefe:13::abc/33"</code></dd> |
| 143 |
125 <dt><code><local></code></dt> | 144 <dt><code><local></code></dt> |
126 <dd>Match local addresses. An address is local if the host is "127.0.0.1", | 145 <dd>Match local addresses. An address is local if the host is "127.0.0.1", |
127 "::1", or "localhost".<br> | 146 "::1", or "localhost".<br> |
128 Example: <code>"<local>"</code></dd> | 147 Example: <code>"<local>"</code></dd> |
129 </dl> | 148 </dl> |
| 149 |
| 150 |
130 <h2 id="overview-examples">Examples</h2> | 151 <h2 id="overview-examples">Examples</h2> |
| 152 |
131 <p> | 153 <p> |
132 The following code sets a SOCKS 5 proxy for HTTP connections to all servers but | 154 The following code sets a SOCKS 5 proxy for HTTP connections to all servers but |
133 foobar.com and uses direct connections for all other protocols. The settings | 155 foobar.com and uses direct connections for all other protocols. The settings |
134 apply to regular and incognito windows, as incognito windows inherit settings | 156 apply to regular and incognito windows, as incognito windows inherit settings |
135 from regular windows. Please also consult the <a | 157 from regular windows. Please also consult the <a |
136 href="types.html#ChromeSetting">Types API</a> documentation. | 158 href="types.html#ChromeSetting">Types API</a> documentation. |
137 </p> | 159 </p> |
| 160 |
138 <pre> | 161 <pre> |
139 var config = { | 162 var config = { |
140 mode: "fixed_servers", | 163 mode: "fixed_servers", |
141 rules: { | 164 rules: { |
142 proxyForHttp: { | 165 proxyForHttp: { |
143 scheme: "socks5", | 166 scheme: "socks5", |
144 host: "1.2.3.4" | 167 host: "1.2.3.4" |
145 }, | 168 }, |
146 bypassList: ["foobar.com"] | 169 bypassList: ["foobar.com"] |
147 } | 170 } |
148 }; | 171 }; |
149 chrome.proxy.settings.set( | 172 chrome.proxy.settings.set( |
150 {value: config, scope: 'regular'}, | 173 {value: config, scope: 'regular'}, |
151 function() {}); | 174 function() {}); |
152 </pre> | 175 </pre> |
| 176 |
153 <p> | 177 <p> |
154 The following code sets a custom PAC script. | 178 The following code sets a custom PAC script. |
155 </p> | 179 </p> |
| 180 |
156 <pre> | 181 <pre> |
157 var config = { | 182 var config = { |
158 mode: "pac_script", | 183 mode: "pac_script", |
159 pacScript: { | 184 pacScript: { |
160 data: "function FindProxyForURL(url, host) {\n" + | 185 data: "function FindProxyForURL(url, host) {\n" + |
161 " if (host == 'foobar.com')\n" + | 186 " if (host == 'foobar.com')\n" + |
162 " return 'PROXY blackhole:80';\n" + | 187 " return 'PROXY blackhole:80';\n" + |
163 " return 'DIRECT';\n" + | 188 " return 'DIRECT';\n" + |
164 "}" | 189 "}" |
165 } | 190 } |
166 }; | 191 }; |
167 chrome.proxy.settings.set( | 192 chrome.proxy.settings.set( |
168 {value: config, scope: 'regular'}, | 193 {value: config, scope: 'regular'}, |
169 function() {}); | 194 function() {}); |
170 </pre> | 195 </pre> |
| 196 |
171 <p> | 197 <p> |
172 The next snippet queries the currently effective proxy settings. The effective | 198 The next snippet queries the currently effective proxy settings. The effective |
173 proxy settings can be determined by another extension or by a policy. See the <a | 199 proxy settings can be determined by another extension or by a policy. See the <a |
174 href="types.html#ChromeSetting">Types API</a> documentation for details. | 200 href="types.html#ChromeSetting">Types API</a> documentation for details. |
175 </p> | 201 </p> |
| 202 |
176 <pre> | 203 <pre> |
177 chrome.proxy.settings.get( | 204 chrome.proxy.settings.get( |
178 {'incognito': false}, | 205 {'incognito': false}, |
179 function(config) {console.log(JSON.stringify(config));}); | 206 function(config) {console.log(JSON.stringify(config));}); |
180 </pre> | 207 </pre> |
| 208 |
181 <p> | 209 <p> |
182 Note that the <code>value</code> object passed to <code>set()</code> is not | 210 Note that the <code>value</code> object passed to <code>set()</code> is not |
183 identical to the <code>value</code> object passed to callback function of | 211 identical to the <code>value</code> object passed to callback function of |
184 <code>get()</code>. The latter will contain a | 212 <code>get()</code>. The latter will contain a |
185 <code>rules.proxyForHttp.port</code> element. | 213 <code>rules.proxyForHttp.port</code> element. |
186 </p> | 214 </p> |
187 <!-- END AUTHORED CONTENT --> | |
OLD | NEW |