Skip to main content

Class: Context

Defined in: packages/testing/src/browser.ts:38

A browsing context (conceptually a browser tab) with its own sessionStorage and access to shared BroadcastChannel for cross-context communication.

Created via browser.context(origin). Each context is independent — sessionStorage is per-context, while BroadcastChannel and cookies are shared across all contexts from the same origin/browser.

Backward compatible with the previous plain-object return type: const { fetch, WebSocket } = browser.context(origin) still works.

Properties

BroadcastChannel()

readonly BroadcastChannel: (name) => BroadcastChannel

Defined in: packages/testing/src/browser.ts:46

BroadcastChannel constructor scoped to this context's origin

Parameters

name

string

Returns

BroadcastChannel


fetch()

readonly fetch: {(input, init?): Promise<Response>; (input, init?): Promise<Response>; (input, init?): Promise<Response>; }

Defined in: packages/testing/src/browser.ts:40

Cookie-aware, CORS-validating fetch scoped to this context's origin

Call Signature

(input, init?): Promise<Response>

MDN Reference

Parameters
input

URL | RequestInfo

init?

RequestInit<CfProperties<unknown>>

Returns

Promise<Response>

Call Signature

(input, init?): Promise<Response>

MDN Reference

Parameters
input

URL | RequestInfo

init?

RequestInit<RequestInitCfProperties>

Returns

Promise<Response>

Call Signature

(input, init?): Promise<Response>

MDN Reference

Parameters
input

string | Request<unknown, CfProperties<unknown>> | URL

init?

RequestInit<CfProperties<unknown>>

Returns

Promise<Response>


sessionStorage

readonly sessionStorage: Storage

Defined in: packages/testing/src/browser.ts:44

Per-context Storage (independent per context, like real sessionStorage)


WebSocket()

readonly WebSocket: (url, protocols?) => WebSocket

Defined in: packages/testing/src/browser.ts:42

Cookie-aware WebSocket constructor scoped to this context's origin

Parameters

url

string | URL

protocols?

string | string[]

Returns

WebSocket

Accessors

lastPreflight

Get Signature

get lastPreflight(): null | PreflightInfo

Defined in: packages/testing/src/browser.ts:84

Information about the last CORS preflight request (for testing/debugging)

Returns

null | PreflightInfo

Methods

close()

close(): void

Defined in: packages/testing/src/browser.ts:102

Close this context. Clears sessionStorage and closes all open BroadcastChannels.

Returns

void


closeChannels()

closeChannels(): void

Defined in: packages/testing/src/browser.ts:92

Close all open BroadcastChannels without clearing sessionStorage. Models a page reload where JS state is destroyed but storage persists.

Returns

void