Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -9,13 +9,17 @@ import HTMLCard from '@site/src/components/HTMLCard';

This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare environment or the service to your e2e test.

Each Playwright browser context has associated with it [APIRequestContext] instance which shares cookie storage with the browser context and can be accessed via [BrowserContext.APIRequest](/api/class-browsercontext.mdx#browser-context-request) or [Page.APIRequest](/api/class-page.mdx#page-request). It is also possible to create a new APIRequestContext instance manually by calling [ApiRequest.NewContextAsync()](/api/class-apirequest.mdx#api-request-new-context).
Each Playwright browser context has an associated [APIRequestContext], accessible via [BrowserContext.APIRequest](/api/class-browsercontext.mdx#browser-context-request) or [Page.APIRequest](/api/class-page.mdx#page-request) (these return the

**same instance** — `page.request` is a shortcut for `page.context().request`). You can also create a standalone, isolated instance with [ApiRequest.NewContextAsync()](/api/class-apirequest.mdx#api-request-new-context).

**Cookie management**

[APIRequestContext] returned by [BrowserContext.APIRequest](/api/class-browsercontext.mdx#browser-context-request) and [Page.APIRequest](/api/class-page.mdx#page-request) shares cookie storage with the corresponding [BrowserContext]. Each API request will have `Cookie` header populated with the values from the browser context. If the API response contains `Set-Cookie` header it will automatically update [BrowserContext] cookies and requests made from the page will pick them up. This means that if you log in using this API, your e2e test will be logged in and vice versa.
The [APIRequestContext] returned by [BrowserContext.APIRequest](/api/class-browsercontext.mdx#browser-context-request) and

[Page.APIRequest](/api/class-page.mdx#page-request) uses the same cookie jar as its [BrowserContext]:

If you want API requests to not interfere with the browser cookies you should create a new [APIRequestContext] by calling [ApiRequest.NewContextAsync()](/api/class-apirequest.mdx#api-request-new-context). Such `APIRequestContext` object will have its own isolated cookie storage.
If you want API requests that do **not** share cookies with the browser, create an isolated context via [ApiRequest.NewContextAsync()](/api/class-apirequest.mdx#api-request-new-context). Such `APIRequestContext` object will have its own isolated cookie storage.


---
Expand Down Expand Up @@ -565,6 +569,23 @@ await ApiRequestContext.StorageStateAsync(options);
**Returns**
- [string]<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="api-request-context-storage-state-return"/><a href="#api-request-context-storage-state-return" class="list-anchor">#</a>

---

## Properties

### Tracing {#api-request-context-tracing}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.60</font><x-search>apiRequestContext.Tracing</x-search>

**Usage**

```csharp
ApiRequestContext.Tracing
```

**Type**
- [Tracing]


[APIRequest]: /api/class-apirequest.mdx "APIRequest"
[APIRequestContext]: /api/class-apirequestcontext.mdx "APIRequestContext"
Expand Down
17 changes: 17 additions & 0 deletions dotnet/versioned_docs/version-stable/api/class-browser.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,23 @@ Browser.Version

## Events

### event Context {#browser-event-context}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.60</font><x-search>browser.event Context</x-search>

Emitted when a new browser context is created.

**Usage**

```csharp
Browser.Context += async (_, browserContext) => {};
```

**Event data**
- [BrowserContext]

---

### event Disconnected {#browser-event-disconnected}

<font size="2" style={{position: "relative", top: "-20px"}}>Added before v1.9</font><x-search>browser.event Disconnected</x-search>
Expand Down
111 changes: 102 additions & 9 deletions dotnet/versioned_docs/version-stable/api/class-browsercontext.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,6 @@ await page.GetByRole(AriaRole.Button).ClickAsync();
- `callback` [Action]&lt;BindingSource, T, [TResult]&gt;<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="browser-context-expose-binding-option-callback"/><a href="#browser-context-expose-binding-option-callback" class="list-anchor">#</a>

Callback function that will be called in the Playwright's context.
- `options` `BrowserContextExposeBindingOptions?` *(optional)*
- `Handle` [bool]? *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="browser-context-expose-binding-option-handle"/><a href="#browser-context-expose-binding-option-handle" class="list-anchor">#</a>

:::warning[Deprecated]
This option will be removed in the future.
:::


Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is supported. When passing by value, multiple arguments are supported.

**Returns**
- [Disposable]<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="browser-context-expose-binding-return"/><a href="#browser-context-expose-binding-return" class="list-anchor">#</a>
Expand Down Expand Up @@ -1147,6 +1138,74 @@ When no [Page.Dialog](/api/class-page.mdx#page-event-dialog) or [BrowserContext.

---

### event Download {#browser-context-event-download}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.60</font><x-search>browserContext.event Download</x-search>

Emitted when attachment download started in any page belonging to this context. User can access basic file operations on downloaded content via the passed [Download] instance. See also [Page.Download](/api/class-page.mdx#page-event-download) to receive events about a specific page.

**Usage**

```csharp
BrowserContext.Download += async (_, download) => {};
```

**Event data**
- [Download]

---

### event FrameAttached {#browser-context-event-frame-attached}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.60</font><x-search>browserContext.event FrameAttached</x-search>

Emitted when a frame is attached in any page belonging to this context. See also [Page.FrameAttached](/api/class-page.mdx#page-event-frame-attached) to receive events about a specific page.

**Usage**

```csharp
BrowserContext.FrameAttached += async (_, frame) => {};
```

**Event data**
- [Frame]

---

### event FrameDetached {#browser-context-event-frame-detached}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.60</font><x-search>browserContext.event FrameDetached</x-search>

Emitted when a frame is detached in any page belonging to this context. See also [Page.FrameDetached](/api/class-page.mdx#page-event-frame-detached) to receive events about a specific page.

**Usage**

```csharp
BrowserContext.FrameDetached += async (_, frame) => {};
```

**Event data**
- [Frame]

---

### event FrameNavigated {#browser-context-event-frame-navigated}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.60</font><x-search>browserContext.event FrameNavigated</x-search>

Emitted when a frame is navigated to a new url in any page belonging to this context. See also [Page.FrameNavigated](/api/class-page.mdx#page-event-frame-navigated) to receive events about navigations in a specific page.

**Usage**

```csharp
BrowserContext.FrameNavigated += async (_, frame) => {};
```

**Event data**
- [Frame]

---

### event Page {#browser-context-event-page}

<font size="2" style={{position: "relative", top: "-20px"}}>Added before v1.9</font><x-search>browserContext.event Page</x-search>
Expand Down Expand Up @@ -1178,6 +1237,40 @@ BrowserContext.Page += async (_, page) => {};

---

### event PageClose {#browser-context-event-page-close}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.60</font><x-search>browserContext.event PageClose</x-search>

Emitted when a page in this context is closed. See also [Page.Close](/api/class-page.mdx#page-event-close) to receive events about a specific page.

**Usage**

```csharp
BrowserContext.PageClose += async (_, page) => {};
```

**Event data**
- [Page]

---

### event PageLoad {#browser-context-event-page-load}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.60</font><x-search>browserContext.event PageLoad</x-search>

Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched in any page belonging to this context. See also [Page.Load](/api/class-page.mdx#page-event-load) to receive events about a specific page.

**Usage**

```csharp
BrowserContext.PageLoad += async (_, page) => {};
```

**Event data**
- [Page]

---

### event Request {#browser-context-event-request}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.12</font><x-search>browserContext.event Request</x-search>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ var page = defaultContext.Pages[0];
- `IsLocal` [bool]? *(optional)* <font size="2">Added in: v1.58</font><a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="browser-type-connect-over-cdp-option-is-local"/><a href="#browser-type-connect-over-cdp-option-is-local" class="list-anchor">#</a>

Tells Playwright that it runs on the same host as the CDP server. It will enable certain optimizations that rely upon the file system being the same between Playwright and the Browser.
- `NoDefaults` [bool]? *(optional)* <font size="2">Added in: v1.60</font><a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="browser-type-connect-over-cdp-option-no-defaults"/><a href="#browser-type-connect-over-cdp-option-no-defaults" class="list-anchor">#</a>

When true, Playwright will not apply its default overrides to the existing default browser context. Specifically, [AcceptDownloads](/api/class-browser.mdx#browser-new-context-option-accept-downloads) is left at the browser's setting, focus emulation is not enabled, and media emulation options (such as [ColorScheme](/api/class-browser.mdx#browser-new-context-option-color-scheme), [ReducedMotion](/api/class-browser.mdx#browser-new-context-option-reduced-motion), [ForcedColors](/api/class-browser.mdx#browser-new-context-option-forced-colors), and [Contrast](/api/class-browser.mdx#browser-new-context-option-contrast)) are not applied. Useful when attaching to a user's daily-driver browser where these overrides would interfere with existing browser state. New contexts created via [Browser.NewContextAsync()](/api/class-browser.mdx#browser-new-context) are not affected. Defaults to `false`.
- `SlowMo` [float]? *(optional)* <font size="2">Added in: v1.11</font><a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="browser-type-connect-over-cdp-option-slow-mo"/><a href="#browser-type-connect-over-cdp-option-slow-mo" class="list-anchor">#</a>

Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on. Defaults to 0.
Expand Down
7 changes: 6 additions & 1 deletion dotnet/versioned_docs/version-stable/api/class-frame.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ await page
An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls.

Learn more about [`aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked).
- `Description|DescriptionRegex` [string]? | [Regex]? *(optional)* <font size="2">Added in: v1.60</font><a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="frame-get-by-role-option-description"/><a href="#frame-get-by-role-option-description" class="list-anchor">#</a>

Option to match the [accessible description](https://w3c.github.io/accname/#dfn-accessible-description). By default, matching is case-insensitive and searches for a substring, use [Exact](/api/class-frame.mdx#frame-get-by-role-option-exact) to control this behavior.

Learn more about [accessible description](https://w3c.github.io/accname/#dfn-accessible-description).
- `Disabled` [bool]? *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="frame-get-by-role-option-disabled"/><a href="#frame-get-by-role-option-disabled" class="list-anchor">#</a>

An attribute that is usually set by `aria-disabled` or `disabled`.
Expand All @@ -505,7 +510,7 @@ await page

- `Exact` [bool]? *(optional)* <font size="2">Added in: v1.28</font><a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="frame-get-by-role-option-exact"/><a href="#frame-get-by-role-option-exact" class="list-anchor">#</a>

Whether [Name|NameRegex](/api/class-frame.mdx#frame-get-by-role-option-name) is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when [Name|NameRegex](/api/class-frame.mdx#frame-get-by-role-option-name) is a regular expression. Note that exact match still trims whitespace.
Whether [Name|NameRegex](/api/class-frame.mdx#frame-get-by-role-option-name) and [Description|DescriptionRegex](/api/class-frame.mdx#frame-get-by-role-option-description) are matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when the value is a regular expression. Note that exact match still trims whitespace.
- `Expanded` [bool]? *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="frame-get-by-role-option-expanded"/><a href="#frame-get-by-role-option-expanded" class="list-anchor">#</a>

An attribute that is usually set by `aria-expanded`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ await page
An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls.

Learn more about [`aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked).
- `Description|DescriptionRegex` [string]? | [Regex]? *(optional)* <font size="2">Added in: v1.60</font><a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="frame-locator-get-by-role-option-description"/><a href="#frame-locator-get-by-role-option-description" class="list-anchor">#</a>

Option to match the [accessible description](https://w3c.github.io/accname/#dfn-accessible-description). By default, matching is case-insensitive and searches for a substring, use [Exact](/api/class-framelocator.mdx#frame-locator-get-by-role-option-exact) to control this behavior.

Learn more about [accessible description](https://w3c.github.io/accname/#dfn-accessible-description).
- `Disabled` [bool]? *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="frame-locator-get-by-role-option-disabled"/><a href="#frame-locator-get-by-role-option-disabled" class="list-anchor">#</a>

An attribute that is usually set by `aria-disabled` or `disabled`.
Expand All @@ -222,7 +227,7 @@ await page

- `Exact` [bool]? *(optional)* <font size="2">Added in: v1.28</font><a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="frame-locator-get-by-role-option-exact"/><a href="#frame-locator-get-by-role-option-exact" class="list-anchor">#</a>

Whether [Name|NameRegex](/api/class-framelocator.mdx#frame-locator-get-by-role-option-name) is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when [Name|NameRegex](/api/class-framelocator.mdx#frame-locator-get-by-role-option-name) is a regular expression. Note that exact match still trims whitespace.
Whether [Name|NameRegex](/api/class-framelocator.mdx#frame-locator-get-by-role-option-name) and [Description|DescriptionRegex](/api/class-framelocator.mdx#frame-locator-get-by-role-option-description) are matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when the value is a regular expression. Note that exact match still trims whitespace.
- `Expanded` [bool]? *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="frame-locator-get-by-role-option-expanded"/><a href="#frame-locator-get-by-role-option-expanded" class="list-anchor">#</a>

An attribute that is usually set by `aria-expanded`.
Expand Down
Loading
Loading