Skip to content
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
2 changes: 1 addition & 1 deletion docs/src/api/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ Function to be evaluated in the page context.
* langs: js
- `exposeFunctions` <[boolean]>

When set to `true`, functions passed inside [`param: arg`] are exposed in the page and can be called from the page function. Calling one returns a [Promise] of its result. The page-side functions are scoped to the execution context they were passed to and disappear when the page navigates. Defaults to `false`, in which case functions are not serializable and passing one throws an error, as before.
When set to `true`, functions passed inside [`param: arg`] are exposed in the page and can be called from the page function. Calling one returns a [Promise] of its result. Under the hood, each function is exposed via [`method: Page.exposeFunction`], so it is technically accessible from all frames and worlds of the page. Exposed functions are cleared upon the top-level navigation. Defaults to `false`, in which case functions are not serializable and passing one throws an error.

## js-evalonselector-pagefunction
* langs: js
Expand Down
109 changes: 0 additions & 109 deletions docs/src/test-api/class-testconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,115 +68,6 @@ The structure of the git commit metadata is subject to change.
:::


## property: TestConfig.httpCache
* since: v1.62
- type: ?<[Object]>
- `dir` <[string]> Directory where the cache is stored, resolved relative to the configuration file.
- `match` ?<[string]|[RegExp]|[HttpCachePolicy]> Limits or customizes what is cached. A glob pattern or regular expression restricts caching to requests whose URL matches; a callback returns a per-request decision (see [HttpCachePolicy]). When omitted, every request is considered with the default behavior.
- `proxy` ?<[Object]> Upstream proxy for cache misses.
- `server` <[string]> Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example `http://myproxy.com:3128` or `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy.
- `bypass` ?<[string]> Optional comma-separated domains to bypass proxy.
- `username` ?<[string]> Optional username to use if HTTP proxy requires authentication.
- `password` ?<[string]> Optional password to use if HTTP proxy requires authentication.

Records network responses to disk and replays them on later runs, so large static
dependencies are downloaded from a remote server once instead of on every run. This is
most useful against a slow or remote environment such as staging.

When `httpCache` is set, Playwright starts a caching proxy for the run and routes all
browser traffic through it. On the first run, eligible responses are recorded under `dir`;
on subsequent runs they are served from disk without reaching the network. A single proxy
is shared by all workers, so a resource fetched by one worker is a cache hit for the rest,
and the cache persists across runs until you delete `dir`.

Loopback traffic (`localhost`, `127.0.0.1`) is never cached — a local dev server already
serves from disk, so there is nothing to optimize. The cache targets remote origins.

**What is cached by default**

With no `match`, the cache stores only **shared static assets**: successful `GET` requests
the browser makes for a static subresource — a script, stylesheet, image, font, or media
element — as reported by the request's `Sec-Fetch-Dest` metadata. These bytes do not depend
on who is signed in, so replaying them into a fresh browser context is always safe, which
keeps tests that each create their own context isolated by construction.

The following are therefore **not** cached by default:

* `fetch`/`XMLHttpRequest` (API) requests and top-level documents — their request
destination is not a static subresource. This is the dynamic, per-user surface.
* Any response marked `Cache-Control: no-store`.
* Any response carrying a personalization signal: `Cache-Control: private`, a `Set-Cookie`
header, or `Vary: Cookie`/`Vary: Authorization`.

The `Authorization` and `Cookie` request headers are deliberately ignored when deciding
what to cache. On a gated staging environment these are a shared environment credential
attached to every request, not a per-user identity, so caching on their presence would be
wrong.

Freshness directives (`max-age`, `no-cache`, `Expires`) are ignored: once a response is
recorded it is replayed until `dir` is deleted, keeping runs deterministic. `Vary` is
honored — responses are keyed by the request-header values they vary on, and `Vary: *` is
never stored.

**Customizing with `match`**

A string or [RegExp] restricts caching to requests whose URL matches; other requests pass
straight through to the network. For full control, pass a callback that returns a decision
object per request:

* `disposition` — `'cache'` force-stores the response and serves it back, `'no-cache'`
bypasses the cache entirely, and `'default'` (or an empty object) applies the rules above.
* `identity` — a stable principal id (such as a session token) that partitions the cache.
Entries recorded under one identity are never served to a request with a different one,
so per-user content can be cached without leaking across contexts. The value is hashed
into the cache key and never written to disk.

Set `proxy` to fetch cache misses through an upstream proxy — for example, to reach a
staging environment that is only accessible behind one. Browsers connect to the caching
proxy, which chains to `proxy` for anything not served from disk.

**Usage**

Cache shared static assets from a staging server with zero configuration:

```js title="playwright.config.ts"
import { defineConfig } from '@playwright/test';

export default defineConfig({
httpCache: { dir: './.network-cache' },
});
```

Fetch cache misses through an upstream proxy:

```js title="playwright.config.ts"
import { defineConfig } from '@playwright/test';

export default defineConfig({
httpCache: { dir: './.network-cache', proxy: { server: 'http://myproxy.com:3128' } },
});
```

Take control per request — force-cache a per-user API response with session isolation, and
bypass the cache for others:

```js title="playwright.config.ts"
import { defineConfig } from '@playwright/test';

export default defineConfig({
httpCache: {
dir: './.network-cache',
match: request => {
if (request.url.includes('/api/config'))
return { disposition: 'cache', identity: request.headers.get('authorization') };
if (request.url.includes('/telemetry'))
return { disposition: 'no-cache' };
return {};
},
},
});
```

## property: TestConfig.expect
* since: v1.10
- type: ?<[Object]>
Expand Down
36 changes: 36 additions & 0 deletions docs/src/test-api/class-testoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,42 @@ export default defineConfig({
});
```

## property: TestOptions.reuseContext
* since: v1.62
* discouraged: This option trades test isolation for speed and is intended for component tests that drive a story gallery. Leave it unset for end-to-end tests - a fresh browser context per test is one of the core guarantees of Playwright Test.
- type: <[boolean]>

**Experimental.** When set to `true`, all tests in a worker process run in a single browser context that is reused between tests, instead of getting a brand new context per test. Defaults to `false`.

Between tests, Playwright resets the state that component tests typically touch: it clears cookies, cache, local storage and IndexedDB of visited origins, unregisters service workers, closes extra pages, removes routes, bindings and init scripts, and re-applies the configured storage state, viewport and emulation options.

This reset is best-effort, not a guarantee of isolation. State that is **not** reset includes:
* Permissions granted with [`method: BrowserContext.grantPermissions`] during a test.
* Runtime changes made through [`method: BrowserContext.setGeolocation`], [`method: BrowserContext.setOffline`] and [`method: BrowserContext.setExtraHTTPHeaders`].
* Browsing history, `window.name` and any browser-process-wide state.

Additional restrictions:
* The option is ignored when [`property: TestOptions.video`] recording is enabled.
* Only a few context options may differ between consecutive tests: `colorScheme`, `forcedColors`, `reducedMotion`, `contrast`, `screen`, `userAgent`, `viewport` and `testIdAttribute`. Changing any other option in [`method: Test.use`], for example `locale` or `storageState`, silently forces a fresh context and negates the speedup.
* Do not combine with [`property: TestOptions.connectOptions`] pointing multiple workers at a shared browser - workers would compete for the single reusable context.
* `recordHar` in [`property: TestOptions.contextOptions`] is not supported and produces no HAR file.

**Usage**

```js title="playwright.config.ts"
import { defineConfig } from '@playwright/test';

export default defineConfig({
projects: [
{
name: 'components',
testDir: './tests/components',
use: { reuseContext: true },
},
],
});
```

## property: TestOptions.screenshot
* since: v1.10
- type: <[Object]|[ScreenshotMode]<"off"|"on"|"only-on-failure"|"on-first-failure">>
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
{
"name": "webkit",
"revision": "2332",
"revision": "2333",
"installByDefault": true,
"revisionOverrides": {
"mac14": "2251",
Expand Down
4 changes: 1 addition & 3 deletions packages/playwright-core/src/server/bidi/bidiPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,11 @@ export class BidiPage implements PageDelegate {
}

async takeScreenshot(progress: Progress, format: string, documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, scale: 'css' | 'device'): Promise<Buffer> {
if (format === 'webp')
throw new Error('webp screenshots are not supported via WebDriver BiDi');
const rect = (documentRect || viewportRect)!;
const { data } = await progress.race(this._session.send('browsingContext.captureScreenshot', {
context: this._session.sessionId,
format: {
type: `image/${format === 'png' ? 'png' : 'jpeg'}`,
type: `image/${format === 'png' || format === 'webp' ? format : 'jpeg'}`,
quality: quality !== undefined ? quality / 100 : undefined,
},
origin: documentRect ? 'document' : 'viewport',
Expand Down
Loading
Loading