OLD | NEW |
1 <h2 id="manifest">Manifest</h2> | 1 <h2 id="manifest">Manifest</h2> |
2 <p>You must declare the "webRequest" permission in the <a | 2 <p>You must declare the "webRequest" permission in the <a |
3 href="manifest">extension manifest</a> to use the web request | 3 href="manifest">extension manifest</a> to use the web request |
4 API, along with <a href="declare_permissions">host permissions</a> | 4 API, along with <a href="declare_permissions">host permissions</a> |
5 for any hosts whose network requests you want to access. If you want to | 5 for any hosts whose network requests you want to access. If you want to |
6 use the web request API in a blocking fashion, you need to request | 6 use the web request API in a blocking fashion, you need to request |
7 the "webRequestBlocking" permission in addition. | 7 the "webRequestBlocking" permission in addition. |
8 For example:</p> | 8 For example:</p> |
9 <pre data-filename="manifest.json"> | 9 <pre data-filename="manifest.json"> |
10 { | 10 { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 </p> | 117 </p> |
118 | 118 |
119 <p> | 119 <p> |
120 The webRequest API only exposes requests that the extension has | 120 The webRequest API only exposes requests that the extension has |
121 permission to see, given its | 121 permission to see, given its |
122 <a href="declare_permissions">host permissions</a>. | 122 <a href="declare_permissions">host permissions</a>. |
123 Moreover, only the following schemes are accessible: | 123 Moreover, only the following schemes are accessible: |
124 <code>http://</code>, | 124 <code>http://</code>, |
125 <code>https://</code>, | 125 <code>https://</code>, |
126 <code>ftp://</code>, | 126 <code>ftp://</code>, |
127 <code>file://</code>, or | 127 <code>file://</code>, |
| 128 <code>ws://</code> (<span class="availability">since Chrome 58</span>), |
| 129 <code>wss://</code> (<span class="availability">since Chrome 58</span>), or |
128 <code>chrome-extension://</code>. | 130 <code>chrome-extension://</code>. |
129 In addition, even certain requests with URLs using one of the above schemes | 131 In addition, even certain requests with URLs using one of the above schemes |
130 are hidden, e.g., | 132 are hidden, e.g., |
131 <code>chrome-extension://other_extension_id</code> where | 133 <code>chrome-extension://other_extension_id</code> where |
132 <code>other_extension_id</code> is not the ID of the extension to handle | 134 <code>other_extension_id</code> is not the ID of the extension to handle |
133 the request, | 135 the request, |
134 <code>https://www.google.com/chrome</code>, | 136 <code>https://www.google.com/chrome</code>, |
135 and others (this list is not complete). Also synchronous XMLHttpRequests from | 137 and others (this list is not complete). Also synchronous XMLHttpRequests from |
136 your extension are hidden from blocking event handlers in order to prevent | 138 your extension are hidden from blocking event handlers in order to prevent |
137 deadlocks. | 139 deadlocks. |
138 Note that for some of the supported schemes the set of available events might be | 140 Note that for some of the supported schemes the set of available events might be |
139 limited due to the nature of the corresponding protocol. | 141 limited due to the nature of the corresponding protocol. |
140 For example, for the <q>file:</q> scheme, only <code>onBeforeRequest</code>, | 142 For example, for the <q>file:</q> scheme, only <code>onBeforeRequest</code>, |
141 <code>onResponseStarted</code>, <code>onCompleted</code>, and | 143 <code>onResponseStarted</code>, <code>onCompleted</code>, and |
142 <code>onErrorOccurred</code> may be dispatched. | 144 <code>onErrorOccurred</code> may be dispatched. |
143 </p> | 145 </p> |
144 | 146 |
| 147 <p> |
| 148 <span class="availability">Starting from Chrome 58</span>, the webRequest API |
| 149 supports intercepting the WebSocket handshake request. Since the handshake is |
| 150 done by means of an HTTP upgrade request, its flow fits into HTTP-oriented |
| 151 webRequest model. Note that the API does <b>not intercept</b>: |
| 152 <ul> |
| 153 <li>Individual messages sent over an established WebSocket connection.</li> |
| 154 <li>WebSocket closing connection.</li> |
| 155 </ul> |
| 156 Redirects are <b>not supported</b> for WebSocket requests. |
| 157 </p> |
| 158 |
145 <h2 id="concepts">Concepts</h2> | 159 <h2 id="concepts">Concepts</h2> |
146 | 160 |
147 <p>As the following sections explain, events in the web request API use request | 161 <p>As the following sections explain, events in the web request API use request |
148 IDs, and you can optionally specify filters and extra information when you | 162 IDs, and you can optionally specify filters and extra information when you |
149 register event listeners.</p> | 163 register event listeners.</p> |
150 | 164 |
151 <h3 id="Request IDs">Request IDs</h3> | 165 <h3 id="Request IDs">Request IDs</h3> |
152 | 166 |
153 <p>Each request is identified by a request ID. This ID is unique within a | 167 <p>Each request is identified by a request ID. This ID is unique within a |
154 browser session and the context of an extension. It remains constant during the | 168 browser session and the context of an extension. It remains constant during the |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } | 319 } |
306 } | 320 } |
307 return {requestHeaders: details.requestHeaders}; | 321 return {requestHeaders: details.requestHeaders}; |
308 }, | 322 }, |
309 {urls: ["<all_urls>"]}, | 323 {urls: ["<all_urls>"]}, |
310 ["blocking", "requestHeaders"]); | 324 ["blocking", "requestHeaders"]); |
311 </pre> | 325 </pre> |
312 | 326 |
313 <p> For more example code, see the <a href="samples#search:webrequest">web reque
st | 327 <p> For more example code, see the <a href="samples#search:webrequest">web reque
st |
314 samples</a>.</p> | 328 samples</a>.</p> |
OLD | NEW |