network.responseCompleted event

The network.responseCompleted event of the network module fires when the browser has received the whole body of a response.

Event data

The params field in the event notification is an object with the following fields:

context

A string that contains the ID of the context in which the request was made, or null if the request wasn't made by a document in a context, for example a request made by a worker.

isBlocked

A boolean that indicates whether the request is blocked by an intercept. It is always false for this event because intercepts can't block a request after the browser has received the complete response, so the event never includes the intercepts field.

A string that contains the UUID that uniquely identifies the navigation that the request is part of, or null if the request isn't a navigation request. For example, the value is null when requesting a document's subresources, such as stylesheets and scripts, or when making a request with fetch(). If the navigation was started using the browsingContext.navigate or browsingContext.reload command, this ID matches the navigation value in the command's response. Other events related to this navigation share the same navigation ID, including events in the browsingContext and network modules.

redirectCount

A non-negative integer that contains the number of redirects the browser has followed for this request. It is 0 for the original request and increases by one with each redirect.

request

An object that describes the request. It contains the following fields:

bodySize

A non-negative integer that contains the size of the request body in bytes, or null if the request has no body.

cookies

An array of objects, each representing a cookie sent with the request. The array is empty if the request has no Cookie header. Each object contains the following fields and may additionally include browser-specific fields:

domain

A string that contains the domain of the cookie.

expiry Optional

A non-negative integer that contains the expiry time of the cookie, as seconds elapsed since the epoch. This field is omitted for a cookie that has no expiry time, such as a session cookie.

httpOnly

A boolean that indicates whether the cookie is hidden from page scripts by its HttpOnly attribute (true) or is accessible to them (false).

name

A string that contains the name of the cookie.

path

A string that contains the path of the cookie.

sameSite

A string that indicates the cookie's SameSite setting. It has one of the following values:

  • default: The cookie has no SameSite attribute or has an unrecognized value, so the browser's default behavior applies.
  • lax: The cookie has SameSite=Lax.
  • none: The cookie has SameSite=None.
  • strict: The cookie has SameSite=Strict.
secure

A boolean that indicates whether the cookie is restricted to secure connections by its Secure attribute (true) or can be sent over insecure connections (false).

size

A non-negative integer that contains the combined size of the cookie's name and value, in bytes.

value

An object that contains the value of the cookie. It contains the following fields:

type

A string that indicates how the cookie value is encoded. It has one of the following values:

  • base64: The value is Base64-encoded bytes because the bytes are not valid UTF-8.
  • string: The value is text decoded from UTF-8 bytes.
value

A string that contains the cookie value in the encoding specified by the type field.

destination

A string that contains the destination of the request, such as document, script, or style. The string is empty for requests made with fetch() or XMLHttpRequest.

headers

An array of objects, each representing a header of the request, including headers added with the network.setExtraHeaders command. Each object contains the following fields:

name

A string that contains the header name, such as Accept.

value

An object that contains the header value. It contains the following fields:

type

A string that indicates how the header value is encoded. It has one of the following values:

  • base64: The value is Base64-encoded bytes because the bytes are not valid UTF-8.
  • string: The value is text decoded from UTF-8 bytes.
value

A string that contains the header value in the encoding specified by the type field.

headersSize

A non-negative integer that contains the size of the request headers in bytes. For protocols that compress headers, such as HTTP/2, it represents the compressed size.

initiatorType

A string that indicates what started the request, such as fetch, link, or script. For a request with no initiator type, such as the request for a page loaded into a tab, the value is null instead of a string. See PerformanceResourceTiming.initiatorType for descriptions of common values.

method

A string that contains the HTTP request method, such as GET or POST.

request

A string that contains the ID of the request. The ID stays the same even when the request is redirected.

timings

An object that contains the times at which the stages of the request happened. The timeOrigin field contains a time in milliseconds since the epoch. The other fields in this object contain times in milliseconds relative to timeOrigin. A field is 0 if its stage hasn't happened, for example the redirect fields for a request that wasn't redirected. All the fields are 0 if the request wasn't made by a document or a worker. It contains the following fields:

connectEnd

A number that represents the time when the browser finished establishing the connection to the server, similar to PerformanceResourceTiming.connectEnd.

connectStart

A number that represents the time when the browser started establishing the connection to the server, similar to PerformanceResourceTiming.connectStart.

dnsEnd

A number that represents the time when the browser finished the domain name lookup, similar to PerformanceResourceTiming.domainLookupEnd.

dnsStart

A number that represents the time when the browser started the domain name lookup, similar to PerformanceResourceTiming.domainLookupStart.

fetchStart

A number that represents the time when the browser started fetching the resource after any redirects, similar to PerformanceResourceTiming.fetchStart.

redirectEnd

A number that represents the time when the browser received the last byte of the response to the last redirect, similar to PerformanceResourceTiming.redirectEnd.

redirectStart

A number that represents the time when the request that was redirected first started, similar to PerformanceResourceTiming.redirectStart.

requestStart

A number that represents the time when the browser started sending the request, similar to PerformanceResourceTiming.requestStart.

requestTime

A number that represents the time when the request started, similar to PerformanceEntry.startTime.

responseEnd

A number that represents the time when the browser received the last byte of the response, similar to PerformanceResourceTiming.responseEnd.

responseStart

A number that represents the time when the browser received the first byte of the response, similar to PerformanceResourceTiming.responseStart.

timeOrigin

A number that represents the time origin of the document or worker that made the request.

tlsStart

A number that represents the time when the browser started the TLS handshake to secure the connection, similar to PerformanceResourceTiming.secureConnectionStart.

url

A string that contains the URL of the request.

response

An object that describes the response. It contains the following fields:

authChallenges Optional

An array of objects, each representing an authentication challenge from the server. This field is included only when the response status is 401 or 407. The challenges come from the WWW-Authenticate header for 401 responses or the Proxy-Authenticate header for 407 responses. The array is empty if the response doesn't include the corresponding header. Each object contains the following fields:

realm

A string that contains the realm of the challenge, or an empty string if the challenge has no realm.

scheme

A string that contains the authentication scheme, such as Basic.

bodySize

A non-negative integer that contains the size of the response body, in bytes, before the browser decodes it (for example, before decompression), or null if the browser doesn't report it.

bytesReceived

A non-negative integer that contains the total number of bytes received for the response, including its headers. It is 0 for a response served from the browser's cache.

content

An object that describes the decoded response body. It contains the following field:

size

A non-negative integer that contains the size of the response body in bytes after the browser decodes it (for example, after decompression).

fromCache

A boolean that indicates whether the browser served the response from its cache.

  • true: The browser served the response from its cache without contacting the server.
  • false: The browser didn't serve the response from its cache. This includes cases where it contacted the server to revalidate a cached response.
headers

An array of objects, each representing a header of the response. Each object contains the following fields:

name

A string that contains the header name, such as Content-Type.

value

An object that contains the header value. It contains the following fields:

type

A string that indicates how the header value is encoded. It has one of the following values:

  • base64: The value is Base64-encoded bytes because the bytes are not valid UTF-8.
  • string: The value is text decoded from UTF-8 bytes.
value

A string that contains the header value in the encoding specified by the type field.

headersSize

A non-negative integer that contains the size of the response headers, in bytes, as received, or null if the browser doesn't report it.

mimeType

A string that contains the MIME type that the browser uses for the response, such as text/html or application/json. The value doesn't include MIME type parameters. It can differ from the Content-Type header, for example when the browser determines the type from the content. It can also be an empty string, for example for a redirect response.

protocol

A string that contains the protocol of the response, such as http/1.1 or h2. For a response that wasn't received over HTTP, it is the scheme of the response URL, such as data.

status

A non-negative integer that contains the HTTP status code of the response, such as 200.

statusText

A string that contains the status message of the response, such as OK.

url

A string that contains the URL of the response.

timestamp

A non-negative integer that represents the time when the event was fired, as milliseconds elapsed since the epoch.

userContext Optional

A string that contains the ID of the user context in which the request was made, or null if the request wasn't made by a document in a context.

Description

In the lifecycle of a request, this is the last event for a response that the browser received successfully. It fires after network.beforeRequestSent and network.responseStarted for the same request. If the request fails at any point, network.fetchError fires as the last event for the request.

When the server responds with a redirect, this event fires for the redirect response too. The browser then sends network.beforeRequestSent for the new URL. The request ID stays the same and redirectCount increases by one. The other events for the new URL follow.

The browser doesn't wait for the client after sending this event: a response can't be blocked at this point.

Examples

Following a request through a redirect

Assume you have a WebDriver BiDi connection, an active session, and a subscription to the network.beforeRequestSent, network.responseStarted, and network.responseCompleted events.

Suppose a tab has loaded https://example.com/. The page calls fetch("/old-items"). The server responds with a 302 redirect to /api/items.

The browser sends network.beforeRequestSent and network.responseStarted for /old-items, and then the following network.responseCompleted event for the redirect response (only some of the fields are shown):

json
{
  "type": "event",
  "method": "network.responseCompleted",
  "params": {
    "context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
    "isBlocked": false,
    "navigation": null,
    "redirectCount": 0,
    "request": {
      "method": "GET",
      "request": "b9e201af-6475-4bea-a174-51a8290f8087",
      "url": "https://example.com/old-items"
    },
    "response": {
      "headers": [
        {
          "name": "Location",
          "value": {
            "type": "string",
            "value": "/api/items"
          }
        }
      ],
      "status": 302,
      "statusText": "Found",
      "url": "https://example.com/old-items"
    },
    "timestamp": 1791903501504
  }
}

It then sends network.beforeRequestSent and network.responseStarted for /api/items, and finally the following network.responseCompleted event (only some of the fields are shown):

json
{
  "type": "event",
  "method": "network.responseCompleted",
  "params": {
    "context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
    "isBlocked": false,
    "navigation": null,
    "redirectCount": 1,
    "request": {
      "method": "GET",
      "request": "b9e201af-6475-4bea-a174-51a8290f8087",
      "url": "https://example.com/api/items"
    },
    "response": {
      "mimeType": "application/json",
      "status": 200,
      "statusText": "OK",
      "url": "https://example.com/api/items"
    },
    "timestamp": 1791903501505
  }
}

The request objects in both network.responseCompleted events have the same request ID, so you can tell that they belong to the same request. The redirectCount of 1 shows that the second response is the result of one redirect.

Specifications

Specification
WebDriver BiDi
# event-network-responseCompleted

Browser compatibility

See also