Skip to content

[pull] main from microsoft:main #116

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

Merged
merged 10 commits into from
Jul 31, 2025
Merged
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
23 changes: 23 additions & 0 deletions docs/src/api/class-browsercontext.md
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,29 @@ its geolocation.

Whether to emulate network being offline for the browser context.


## async method: BrowserContext.setStorageState
* since: v1.55

Resets storage state in the context by clearing cookies, cache and storage, and then applying the new storage state.

### param: BrowserContext.setStorageState.storageState = %%-js-python-context-option-storage-state-%%
* since: v1.55

### param: BrowserContext.setStorageState.storageState = %%-csharp-java-context-option-storage-state-%%
* since: v1.55


## async method: BrowserContext.setStorageStatePath
* since: v1.55
* langs: csharp, java

Resets storage state in the context by clearing cookies, cache and storage, and then applying the new storage state from a file.

### param: BrowserContext.setStorageStatePath.storageStatePath = %%-csharp-java-context-option-storage-state-path-%%
* since: v1.55


## async method: BrowserContext.storageState
* since: v1.8
- returns: <[Object]>
Expand Down
231 changes: 84 additions & 147 deletions docs/src/getting-started-vscode-js.md

Large diffs are not rendered by default.

Binary file added docs/src/images/getting-started/debug-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/getting-started/fix-with-ai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/getting-started/global-setup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/getting-started/pick-locator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/getting-started/setup-tests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/getting-started/show-browser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/getting-started/trace-viewer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/src/running-tests-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ npx playwright test --last-failed

### Run tests in VS Code

Tests can be run right from VS Code using the [VS Code extension](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright). Once installed you can simply click the green triangle next to the test you want to run or run all tests from the testing sidebar. Check out our [Getting Started with VS Code](./getting-started-vscode.md#running-tests) guide for more details.
Tests can be run right from VS Code using the [VS Code extension](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright). Once installed you can simply click the green triangle next to the test you want to run or run all tests from the testing sidebar. Check out our [Getting Started with VS Code](./getting-started-vscode.md) guide for more details.

![Playwright VS Code extension](https://github.com/microsoft/playwright/assets/13063165/47726e70-683b-4bd5-94de-7d03dd45c30f)
![install playwright extension](./images/getting-started/vscode-extension.png)

## Debugging tests

Expand Down
58 changes: 58 additions & 0 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9273,6 +9273,64 @@ export interface BrowserContext {
*/
setOffline(offline: boolean): Promise<void>;

/**
* Resets storage state in the context by clearing cookies, cache and storage, and then applying the new storage
* state.
* @param storageState Learn more about [storage state and auth](https://playwright.dev/docs/auth).
*
* Populates context with given storage state. This option can be used to initialize context with logged-in
* information obtained via
* [browserContext.storageState([options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-storage-state).
*/
setStorageState(storageState: string|{
/**
* Cookies to set for context
*/
cookies: Array<{
name: string;

value: string;

/**
* Domain and path are required. For the cookie to apply to all subdomains as well, prefix ___domain with a dot, like
* this: ".example.com"
*/
___domain: string;

/**
* Domain and path are required
*/
path: string;

/**
* Unix time in seconds.
*/
expires: number;

httpOnly: boolean;

secure: boolean;

/**
* sameSite flag
*/
sameSite: "Strict"|"Lax"|"None";
}>;

origins: Array<{
origin: string;

/**
* localStorage to set for context
*/
localStorage: Array<{
name: string;

value: string;
}>;
}>;
}): Promise<void>;

/**
* Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB
* snapshot.
Expand Down
8 changes: 4 additions & 4 deletions packages/playwright-core/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
},
{
"name": "chromium-tip-of-tree",
"revision": "1354",
"revision": "1355",
"installByDefault": false,
"browserVersion": "140.0.7325.0"
"browserVersion": "140.0.7329.0"
},
{
"name": "chromium-tip-of-tree-headless-shell",
"revision": "1354",
"revision": "1355",
"installByDefault": false,
"browserVersion": "140.0.7325.0"
"browserVersion": "140.0.7329.0"
},
{
"name": "firefox",
Expand Down
18 changes: 11 additions & 7 deletions packages/playwright-core/src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { urlMatchesEqual } from '../utils/isomorphic/urlMatch';
import { isRegExp, isString } from '../utils/isomorphic/rtti';
import { rewriteErrorMessage } from '../utils/isomorphic/stackTrace';

import type { BrowserContextOptions, Headers, StorageState, WaitForEventOptions } from './types';
import type { BrowserContextOptions, Headers, SetStorageState, StorageState, WaitForEventOptions } from './types';
import type * as structs from '../../types/structs';
import type * as api from '../../types/types';
import type { URLMatch } from '../utils/isomorphic/urlMatch';
Expand Down Expand Up @@ -455,6 +455,10 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
return state;
}

async setStorageState(storageState: string | SetStorageState) {
await this._channel.setStorageState({ storageState: await prepareStorageState(this._platform, storageState) });
}

backgroundPages(): Page[] {
return [...this._backgroundPages];
}
Expand Down Expand Up @@ -527,13 +531,13 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
}
}

async function prepareStorageState(platform: Platform, options: BrowserContextOptions): Promise<channels.BrowserNewContextParams['storageState']> {
if (typeof options.storageState !== 'string')
return options.storageState as any;
async function prepareStorageState(platform: Platform, storageState: string | SetStorageState): Promise<NonNullable<channels.BrowserNewContextParams['storageState']>> {
if (typeof storageState !== 'string')
return storageState as any;
try {
return JSON.parse(await platform.fs().promises.readFile(options.storageState, 'utf8'));
return JSON.parse(await platform.fs().promises.readFile(storageState, 'utf8'));
} catch (e) {
rewriteErrorMessage(e, `Error reading storage state from ${options.storageState}:\n` + e.message);
rewriteErrorMessage(e, `Error reading storage state from ${storageState}:\n` + e.message);
throw e;
}
}
Expand All @@ -548,7 +552,7 @@ export async function prepareBrowserContextParams(platform: Platform, options: B
viewport: options.viewport === null ? undefined : options.viewport,
noDefaultViewport: options.viewport === null,
extraHTTPHeaders: options.extraHTTPHeaders ? headersObjectToArray(options.extraHTTPHeaders) : undefined,
storageState: await prepareStorageState(platform, options),
storageState: options.storageState ? await prepareStorageState(platform, options.storageState) : undefined,
serviceWorkers: options.serviceWorkers,
colorScheme: options.colorScheme === null ? 'no-override' : options.colorScheme,
reducedMotion: options.reducedMotion === null ? 'no-override' : options.reducedMotion,
Expand Down
Loading
Loading