Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing browser request docs #1603

Merged
merged 24 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ The `request` that the browser performs can be retrieved from the [Response](htt

## Supported APIs

| Method | Playwright Relevant Distinctions |
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| [request.allHeaders()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/allheaders) {{< docs/bwipt id="965" >}} | Returns an object of headers associated to the request including headers added by the browser. |
| [request.frame()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/frame) | The [Frame](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/frame/) that initiated the request |
| [request.headers()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/headers) | Returns an object of headers associated to the request. |
| [request.headersArray()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/headersarray) | An array with all the request HTTP headers |
| [request.headerValue(name)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/headervalue) | Returns the value of the header matching the name. The name is case insensitive. |
| [request.isNavigationRequest()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/isnavigationrequest) | Returns a boolean stating whether the request is for a navigation. |
| [request.method()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/method) | Request's method (GET, POST, etc.). |
| [request.postData()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/postdata) | Contains the request's post body, if any. |
| [request.postDataBuffer()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/postdatabuffer) | Request's post body in a binary form, if any. |
| [request.resourceType()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/resourcetype) | Contains the request's resource type as it was perceived by the rendering engine. |
| <a href="https://playwright.dev/docs/api/class-request#request-response" target="_blank" >request.response()</a> | - |
| [request.size()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/size) | Unlike Playwright, this method returns an object containing the sizes of request headers and body. |
| <a href="https://playwright.dev/docs/api/class-request#request-timing" target="_blank" >request.timing()</a> | - |
| <a href="https://playwright.dev/docs/api/class-request#request-url" target="_blank" >request.url()</a> | - |
| Method | Playwright Relevant Distinctions |
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| [request.allHeaders()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/allheaders) {{< docs/bwipt id="965" >}} | Returns an object of headers associated to the request including headers added by the browser. |
| [request.frame()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/frame) | The [Frame](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/frame/) that initiated the request |
| [request.headers()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/headers) | Returns an object of headers associated to the request. |
| [request.headersArray()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/headersarray) | An array with all the request HTTP headers |
| [request.headerValue(name)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/headervalue) | Returns the value of the header matching the name. The name is case insensitive. |
| [request.isNavigationRequest()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/isnavigationrequest) | Returns a boolean stating whether the request is for a navigation. |
| [request.method()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/method) | Request's method (GET, POST, etc.). |
| [request.postData()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/postdata) | Contains the request's post body, if any. |
| [request.postDataBuffer()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/postdatabuffer) | Request's post body in a binary form, if any. |
| [request.resourceType()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/resourcetype) | Contains the request's resource type as it was perceived by the rendering engine. |
| [request.response()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/response) | Returns the matching [Response](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/response) object |
inancgumus marked this conversation as resolved.
Show resolved Hide resolved
| [request.size()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/request/size) | Unlike Playwright, this method returns an object containing the sizes of request headers and body. |
| <a href="https://playwright.dev/docs/api/class-request#request-timing" target="_blank" >request.timing()</a> | - |
| <a href="https://playwright.dev/docs/api/class-request#request-url" target="_blank" >request.url()</a> | - |

### Example

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: 'response()'
description: 'Browser module: Request.response method'
---

# response()

Returns the matching [Response](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/response) object, or `null` if the response was not received due to error.

### Returns

| Type | Description |
| --------------------------- | ------------------------------------------------------------------------------ |
| `Promise<Response \| null>` | The `Response` object, or `null` if the response was not received due to error |

### Example

{{< code >}}

```javascript
import { browser } from 'k6/experimental/browser';

export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};

export default async function () {
const page = await browser.newPage();

try {
const res = await page.goto('https://test.k6.io/');
const req = res.request();

const response = await req.response();
// ...
} finally {
await page.close();
}
}
```

{{< /code >}}