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