This event can be used to cancel the request. The event is triggered before the headers are sent to the network. This event is informational and handled asynchronously. It does not allow modifying or cancelling the request. Due to redirects and authentication requests this can happen multiple times per request. This event is intended to allow extensions to add, modify, and delete response headers, such as incoming Set-Cookie headers.
The caching directives are processed before this event is triggered, so modifying headers such as Cache-Control has no influence on the browser's cache. It also allows you to cancel or redirect the request. This event can be handled synchronously to provide authentication credentials. Note that extensions may provide invalid credentials. Take care not to enter an infinite loop by repeatedly providing invalid credentials. This can also be used to cancel the request. A redirection can be triggered by an HTTP response code or by an extension.
It does not allow you to modify or cancel the request. For HTTP requests, this means that the status line and response headers are available.
The web request API guarantees that for each request either onCompleted or onErrorOccurred is fired as the final event with one exception: If a request is redirected to a data: Internally, one URL request can be split into several HTTP requests for example to fetch individual byte ranges from a large file or can be handled by the network stack without communicating with the network.
For example, all headers that are related to caching are invisible to the extension. The following headers are currently not provided to the onBeforeSendHeaders event. This list is not guaranteed to be complete nor stable.
The webRequest API only exposes requests that the extension has permission to see, given its host permissions. Moreover, only the following schemes are accessible: In addition, even certain requests with URLs using one of the above schemes are hidden, e. Also synchronous XMLHttpRequests from your extension are hidden from blocking event handlers in order to prevent deadlocks. Note that for some of the supported schemes the set of available events might be limited due to the nature of the corresponding protocol.
For example, for the file: Note that the API does not intercept: Individual messages sent over an established WebSocket connection. Redirects are not supported for WebSocket requests. As the following sections explain, events in the web request API use request IDs, and you can optionally specify filters and extra information when you register event listeners.
Each request is identified by a request ID. This ID is unique within a browser session and the context of an extension. It remains constant during the the life cycle of a request and can be used to match events for the same request. To register an event listener for a web request, you use a variation on the usual addListener function. In addition to specifying a callback function, you have to specify a filter argument and you may specify an optional extra info argument. The three arguments to the web request API's addListener have the following definitions:.
Each addListener call takes a mandatory callback function as the first parameter. This callback function is passed a dictionary containing information about the current URL request.
That means that the request is blocked until the callback function returns. In this case, the callback can return a webRequest. BlockingResponse that determines the further life cycle of the request.
Depending on the context, this response allows cancelling or redirecting a request onBeforeRequest , cancelling a request or modifying headers onBeforeSendHeaders , onHeadersReceived , and cancelling a request or providing authentication credentials onAuthRequired.
RequestFilter filter allows limiting the requests for which events are triggered in various dimensions: Tab ID The identifier for one tab. Window ID The identifier for a window. This is used to provide detailed information on request's data only if explicitly requested.
Several implementation details can be important to understand when developing an extension that uses the web request API:. In the current implementation of the web request API, a request is considered as cancelled if at least one extension instructs to cancel the request.
If an extension cancels a request, all extensions are notified by an onErrorOccurred event. Only one extension is allowed to redirect a request or modify a header at a time. If more than one extension attempts to modify the request, the most recently installed extension wins and all others are ignored. An extension is not notified if its instruction to modify or redirect has been ignored. Chrome employs two caches — an on-disk cache and a very fast in-memory cache.
The lifetime of an in-memory cache is attached to the lifetime of a render process, which roughly corresponds to a tab. Generally, whenever a browser loads a new image, it will make a new HTTP request to the server. This doesn't always mean establishing a new TCP connection, because browsers will leave TCP connections open for reuse if they're to the same hostname.
However, these connections are managed by a 'connection pool'. Most browsers do not do HTTP pipelining , which means the connection waits for a response before sending a new request. This means your requests are queued.
If you need to load images from the same hostname this could have serious implications for your user experience. A strategy that people frequently use to mitigate this is to visually combine multiple images into a single image, which can then be served with a single HTTP request. This requires someone to lay out the images onto a larger canvas, at known pixel coordinates. The image is then positioned using CSS in the browser to reveal the individual images. DONE 4 The data transfer has been completed or something went wrong during the transfer e.
Method Meaning abort Cancels any network activity. The optional argument provides the request entity body. If header is already in the list of author request headers, the values are combined. Tue, 03 Mar For example an asynchronous initialization: For example we can set a request field called Cache-Control: GET Transfer a current representation of the target resource. POST Perform resource-specific processing on the request payload.
PUT Replace all current representations of the target resource with the request payload. GET Retrieves a resource. PUT Updates an existing resource. Tue, 15 Nov The port number may be omitted if the port is the standard port for the service requested. This is mainly for methods like PUT to only update a resource if it has not been modified since the user last updated it. Sat, 29 Oct Bytes are numbered from 0.
Responses Below is the captured response from a server. To be used for a Method not allowed Allow: It is measured in seconds Cache-Control: Quotes are necessary with special characters. Thu, 01 Dec Basic Refresh Used in redirection, or when a new resource has been created.
Proudly powered by WordPress. The open method has been successfully invoked. All redirects if any have been followed and all HTTP headers of the final response have been received.