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