OLD | NEW |
(Empty) | |
| 1 <!-- BEGIN AUTHORED CONTENT --> |
| 2 <p id="classSummary"> |
| 3 Use the <code>chrome.proxy</code> module to manage Chrome's |
| 4 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 |
| 6 configuration. |
| 7 </p> |
| 8 <h2 id="manifest">Manifest</h2> |
| 9 <p>You must declare the "proxy" permission |
| 10 in the <a href="manifest.html">extension manifest</a> |
| 11 to use the proxy settings API. |
| 12 For example:</p> |
| 13 <pre>{ |
| 14 "name": "My extension", |
| 15 ... |
| 16 <b>"permissions": [ |
| 17 "proxy" |
| 18 ]</b>, |
| 19 ... |
| 20 }</pre> |
| 21 <h2 id="description">Objects and properties</h2> |
| 22 <p> |
| 23 Proxy settings are defined in a |
| 24 <a href="#type-proxy.ProxyConfig"><code>ProxyConfig</code></a> object. Depending
on |
| 25 Chrome's proxy settings, the settings may contain |
| 26 <a href="#type-proxy.ProxyRules"><code>ProxyRules</code></a> or a <a |
| 27 href="#type-proxy.PacScript"><code>PacScript</code></a>. |
| 28 </p> |
| 29 <h3 id="proxy_modes">Proxy modes</h3> |
| 30 <p> |
| 31 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 |
| 33 values: |
| 34 <dl> |
| 35 <dt><code>direct</code></dt> |
| 36 <dd>In <code>direct</code> mode all connections are created directly, without |
| 37 any proxy involved. This mode allows no further parameters in the |
| 38 <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> |
| 44 object.</dd> |
| 45 <dt><code>pac_script</code></dt> |
| 46 <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 |
| 48 <a href="#type-proxy.PacScript"><code>PacScript</code></a> object or |
| 49 taken literally from the <code>data</code> element specified in the |
| 50 <a href="#type-proxy.PacScript"><code>PacScript</code></a> object. |
| 51 Besides this, this mode allows no further parameters in the |
| 52 <code>ProxyConfig</code> object.</dd> |
| 53 <dt><code>fixed_servers</code></dt> |
| 54 <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
> |
| 56 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 |
| 58 in the <code>ProxyConfig</code> object.</dd> |
| 59 <dt><code>system</code></dt> |
| 60 <dd>In <code>system</code> mode the proxy configuration is taken from the |
| 61 operating system. This mode allows no further parameters in the |
| 62 <code>ProxyConfig</code> object. Note that the <code>system</code> mode is |
| 63 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 |
| 65 the proxy configuration.</dd> |
| 66 </dl> |
| 67 </p> |
| 68 <h3 id="proxy_rules">Proxy rules</h3> |
| 69 <p> |
| 70 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 |
| 72 <code>proxyForHttp</code>, <code>proxyForHttps</code>, <code>proxyForFtp</code>, |
| 73 and <code>fallbackProxy</code>. |
| 74 </p> |
| 75 <p> |
| 76 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 |
| 78 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 |
| 80 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 |
| 82 <code>fallbackProxy</code> is specified, traffic is sent directly without a |
| 83 proxy server. |
| 84 </p> |
| 85 <h3 id="proxy_server_objects">Proxy server objects</h3> |
| 86 <p> |
| 87 A proxy server is configured in a |
| 88 <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 |
| 90 protocol defined in the <code>scheme</code> attribute. If no <code>scheme</code> |
| 91 is specified, the proxy connection defaults to <code>http</code>. |
| 92 </p> |
| 93 <p> |
| 94 If no <code>port</code> is defined in a |
| 95 <a href="#type-proxy.ProxyServer"><code>ProxyServer</code></a> object, the port
is |
| 96 derived from the scheme. The default ports are: |
| 97 <table> |
| 98 <tr><th>Scheme</th><th>Port</th></tr> |
| 99 <tr><td>http</td><td>80</td></tr> |
| 100 <tr><td>https</td><td>443</td></tr> |
| 101 <tr><td>socks4</td><td>1080</td></tr> |
| 102 <tr><td>socks5</td><td>1080</td></tr> |
| 103 </table> |
| 104 </p> |
| 105 <h3 id="bypass_list">Bypass list</h3> |
| 106 <p> |
| 107 Individual servers may be excluded from being proxied with the |
| 108 <code>bypassList</code>. This list may contain the following entries: |
| 109 <dl> |
| 110 <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> |
| 112 Examples: <code>"foobar.com", "*foobar.com", "*.foobar.com", "*foobar.com:99", |
| 113 "https://x.*.y.com:99"</code></dd> |
| 114 <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> |
| 116 Conceptually this is the similar to the first case, but with special cases |
| 117 to handle IP literal canonicalization. For example, matching |
| 118 on "[0:0:0::1]" is the same as matching on "[::1]" because |
| 119 the IPv6 canonicalization is done internally.<br> |
| 120 Examples: <code>"127.0.1", "[0:0::1]", "[::1]", "http://[::1]:99"</code></dd> |
| 121 <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 |
| 123 range is specified using CIDR notation.<br> |
| 124 Examples: <code>"192.168.1.1/16", "fefe:13::abc/33"</code></dd> |
| 125 <dt><code><local></code></dt> |
| 126 <dd>Match local addresses. An address is local if the host is "127.0.0.1", |
| 127 "::1", or "localhost".<br> |
| 128 Example: <code>"<local>"</code></dd> |
| 129 </dl> |
| 130 <h2 id="overview-examples">Examples</h2> |
| 131 <p> |
| 132 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 |
| 134 apply to regular and incognito windows, as incognito windows inherit settings |
| 135 from regular windows. Please also consult the <a |
| 136 href="types.html#ChromeSetting">Types API</a> documentation. |
| 137 </p> |
| 138 <pre> |
| 139 var config = { |
| 140 mode: "fixed_servers", |
| 141 rules: { |
| 142 proxyForHttp: { |
| 143 scheme: "socks5", |
| 144 host: "1.2.3.4" |
| 145 }, |
| 146 bypassList: ["foobar.com"] |
| 147 } |
| 148 }; |
| 149 chrome.proxy.settings.set( |
| 150 {value: config, scope: 'regular'}, |
| 151 function() {}); |
| 152 </pre> |
| 153 <p> |
| 154 The following code sets a custom PAC script. |
| 155 </p> |
| 156 <pre> |
| 157 var config = { |
| 158 mode: "pac_script", |
| 159 pacScript: { |
| 160 data: "function FindProxyForURL(url, host) {\n" + |
| 161 " if (host == 'foobar.com')\n" + |
| 162 " return 'PROXY blackhole:80';\n" + |
| 163 " return 'DIRECT';\n" + |
| 164 "}" |
| 165 } |
| 166 }; |
| 167 chrome.proxy.settings.set( |
| 168 {value: config, scope: 'regular'}, |
| 169 function() {}); |
| 170 </pre> |
| 171 <p> |
| 172 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 |
| 174 href="types.html#ChromeSetting">Types API</a> documentation for details. |
| 175 </p> |
| 176 <pre> |
| 177 chrome.proxy.settings.get( |
| 178 {'incognito': false}, |
| 179 function(config) {console.log(JSON.stringify(config));}); |
| 180 </pre> |
| 181 <p> |
| 182 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 |
| 184 <code>get()</code>. The latter will contain a |
| 185 <code>rules.proxyForHttp.port</code> element. |
| 186 </p> |
| 187 <!-- END AUTHORED CONTENT --> |
OLD | NEW |