OLD | NEW |
1 <p id="classSummary"> | 1 <p id="classSummary"> |
2 Use the <code>chrome.webRequest</code> module to intercept, block, | 2 Use the <code>chrome.webRequest</code> module to intercept, block, |
3 or modify requests in-flight and to observe and analyze traffic. | 3 or modify requests in-flight and to observe and analyze traffic. |
4 </p> | 4 </p> |
5 | 5 |
6 <h2 id="manifest">Manifest</h2> | 6 <h2 id="manifest">Manifest</h2> |
7 <p>You must declare the "webRequest" permission in the <a | 7 <p>You must declare the "webRequest" permission in the <a |
8 href="manifest.html">extension manifest</a> to use the web request | 8 href="manifest.html">extension manifest</a> to use the web request |
9 API, along with <a href="manifest.html#permissions">host permissions</a> | 9 API, along with <a href="manifest.html#permissions">host permissions</a> |
10 for any hosts whose network requests you want to access. If you want to | 10 for any hosts whose network requests you want to access. If you want to |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 <p>Depending on the event type, you can specify strings in | 212 <p>Depending on the event type, you can specify strings in |
213 <code>opt_extraInfoSpec</code> to ask for additional information about the | 213 <code>opt_extraInfoSpec</code> to ask for additional information about the |
214 request. This is used to provide detailed information on request's data only | 214 request. This is used to provide detailed information on request's data only |
215 if explicitly requested.</p> | 215 if explicitly requested.</p> |
216 | 216 |
217 <h2 id="implementation">Implementation details</h2> | 217 <h2 id="implementation">Implementation details</h2> |
218 | 218 |
219 <p>Several implementation details can be important to understand when developing | 219 <p>Several implementation details can be important to understand when developing |
220 an extension that uses the web request API:</p> | 220 an extension that uses the web request API:</p> |
221 | 221 |
222 <h3>Conflict resolution</h3> | 222 <h3 id="conflict_resolution">Conflict resolution</h3> |
223 <p>In the current implementation of the web request API, a request is considered | 223 <p>In the current implementation of the web request API, a request is considered |
224 as cancelled if at least one extension instructs to cancel the request. If | 224 as cancelled if at least one extension instructs to cancel the request. If |
225 an extension cancels a request, all extensions are notified by an | 225 an extension cancels a request, all extensions are notified by an |
226 <code>onErrorOccurred</code> event. Only one extension is allowed to redirect a | 226 <code>onErrorOccurred</code> event. Only one extension is allowed to redirect a |
227 request or modify a header at a time. If more than one extension attempts to | 227 request or modify a header at a time. If more than one extension attempts to |
228 modify the request, the most recently installed extension wins and all others | 228 modify the request, the most recently installed extension wins and all others |
229 are ignored. An extension is not notified if its instruction to modify or | 229 are ignored. An extension is not notified if its instruction to modify or |
230 redirect has been ignored.</p> | 230 redirect has been ignored.</p> |
231 | 231 |
232 <h3>Caching</h3> | 232 <h3 id="caching">Caching</h3> |
233 <p> | 233 <p> |
234 Chrome employs two caches — an on-disk cache and a very fast in-memory | 234 Chrome employs two caches — an on-disk cache and a very fast in-memory |
235 cache. The lifetime of an in-memory cache is attached to the lifetime of a | 235 cache. The lifetime of an in-memory cache is attached to the lifetime of a |
236 render process, which roughly corresponds to a tab. Requests that are answered | 236 render process, which roughly corresponds to a tab. Requests that are answered |
237 from the in-memory cache are invisible to the web request API. If a request | 237 from the in-memory cache are invisible to the web request API. If a request |
238 handler changes its behavior (for example, the behavior according to which | 238 handler changes its behavior (for example, the behavior according to which |
239 requests are blocked), a simple page refresh might not respect this changed | 239 requests are blocked), a simple page refresh might not respect this changed |
240 behavior. To make sure the behavior change goes through, call | 240 behavior. To make sure the behavior change goes through, call |
241 <code>handlerBehaviorChanged()</code> to flush the in-memory cache. But don't do | 241 <code>handlerBehaviorChanged()</code> to flush the in-memory cache. But don't do |
242 it often; flushing the cache is a very expensive operation. You don't need to | 242 it often; flushing the cache is a very expensive operation. You don't need to |
243 call <code>handlerBehaviorChanged()</code> after registering or unregistering an | 243 call <code>handlerBehaviorChanged()</code> after registering or unregistering an |
244 event listener.</p> | 244 event listener.</p> |
245 | 245 |
246 <h3>Timestamps</h3> | 246 <h3 id="timestamps">Timestamps</h3> |
247 <p> | 247 <p> |
248 The <code>timestamp</code> property of web request events is only guaranteed to | 248 The <code>timestamp</code> property of web request events is only guaranteed to |
249 be <i>internally</i> consistent. Comparing one event to another event will give | 249 be <i>internally</i> consistent. Comparing one event to another event will give |
250 you the correct offset between them, but comparing them to the current time | 250 you the correct offset between them, but comparing them to the current time |
251 inside the extension (via <code>(new Date()).getTime()</code>, for instance) | 251 inside the extension (via <code>(new Date()).getTime()</code>, for instance) |
252 might give unexpected results. | 252 might give unexpected results. |
253 </p> | 253 </p> |
254 | 254 |
255 <h2 id="examples">Examples</h2> | 255 <h2 id="examples">Examples</h2> |
256 | 256 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 break; | 289 break; |
290 } | 290 } |
291 } | 291 } |
292 return {requestHeaders: details.requestHeaders}; | 292 return {requestHeaders: details.requestHeaders}; |
293 }, | 293 }, |
294 {urls: ["<all_urls>"]}, | 294 {urls: ["<all_urls>"]}, |
295 ["blocking", "requestHeaders"]); | 295 ["blocking", "requestHeaders"]); |
296 </pre> | 296 </pre> |
297 | 297 |
298 <p> For more example code, see the <a href="samples.html#webrequest">web request | 298 <p> For more example code, see the <a href="samples.html#webrequest">web request |
299 samples</a>.</p> | 299 samples</a>.</p> |
OLD | NEW |