effect-playwright
    Preparing search index...

    Interface BrowserContext

    Effect-friendly operations for an isolated Playwright browser context.

    When to use

    Use a context to isolate cookies, permissions, storage, pages, and tracing within one browser. Contexts created by Browser.newContext are scoped and close automatically when their scope ends.

    0.1.0

    interface BrowserContext {
        addCookies: (
            cookies: readonly {
                domain?: string;
                expires?: number;
                httpOnly?: boolean;
                name: string;
                partitionKey?: string;
                path?: string;
                sameSite?: "None" | "Strict" | "Lax";
                secure?: boolean;
                url?: string;
                value: string;
            }[],
        ) => Effect<void, PlaywrightError>;
        addInitScript: <Arg>(
            script:
                | PageFunction<Arg, unknown>
                | { content?: string; path?: string },
            arg?: Arg,
            options?: { exposeFunctions?: boolean },
        ) => Effect<void, PlaywrightError>;
        browser: () => Option<Playwright.Browser>;
        clearCookies: (
            options?: {
                domain?: string | RegExp;
                name?: string | RegExp;
                path?: string | RegExp;
            },
        ) => Effect<void, PlaywrightError>;
        clearPermissions: Effect<void, PlaywrightError>;
        clock: Playwright.Clock;
        close: Effect<void, PlaywrightError>;
        cookies: (urls?: string | string[]) => Effect<Cookie[], PlaywrightError>;
        credentials: Playwright.Credentials;
        eventStream: <
            K extends
                | "dialog"
                | "page"
                | "close"
                | "console"
                | "download"
                | "frameattached"
                | "framedetached"
                | "framenavigated"
                | "request"
                | "requestfailed"
                | "requestfinished"
                | "response"
                | "backgroundpage"
                | "pageclose"
                | "pageload"
                | "serviceworker"
                | "weberror",
        >(
            event: K,
        ) => Stream<
            ReturnType<
                {
                    backgroundpage: (page: Page) => Playwright.Page;
                    close: (context: BrowserContext) => Playwright.BrowserContext;
                    console: (a: ConsoleMessage) => ConsoleMessage;
                    dialog: (dialog: Dialog) => Playwright.Dialog;
                    download: (download: Download) => Playwright.Download;
                    frameattached: (frame: Frame) => Playwright.Frame;
                    framedetached: (frame: Frame) => Playwright.Frame;
                    framenavigated: (frame: Frame) => Playwright.Frame;
                    page: (page: Page) => Playwright.Page;
                    pageclose: (page: Page) => Playwright.Page;
                    pageload: (page: Page) => Playwright.Page;
                    request: (request: Request) => Playwright.Request;
                    requestfailed: (request: Request) => Playwright.Request;
                    requestfinished: (request: Request) => Playwright.Request;
                    response: (response: Response) => Playwright.Response;
                    serviceworker: (worker: Worker) => Playwright.Worker;
                    weberror: (a: WebError) => WebError;
                }[K],
            >,
        >;
        grantPermissions: (
            permissions: readonly string[],
            options?: { origin?: string },
        ) => Effect<void, PlaywrightError>;
        isClosed: () => boolean;
        newPage: Effect<Playwright.Page, PlaywrightError>;
        pages: () => Playwright.Page[];
        setDefaultNavigationTimeout: (timeout: number) => void;
        setDefaultTimeout: (timeout: number) => void;
        setExtraHTTPHeaders: (
            headers: { [key: string]: string },
        ) => Effect<void, PlaywrightError>;
        setGeolocation: (
            geolocation:
                | { accuracy?: number; latitude: number; longitude: number }
                | null,
        ) => Effect<void, PlaywrightError>;
        setOffline: (offline: boolean) => Effect<void, PlaywrightError>;
        setStorageState: (
            options:
                | string
                | {
                    cookies: {
                        domain: string;
                        expires: number;
                        httpOnly: boolean;
                        name: string;
                        path: string;
                        sameSite: "None"
                        | "Strict"
                        | "Lax";
                        secure: boolean;
                        value: string;
                    }[];
                    origins: {
                        localStorage: { name: string; value: string }[];
                        origin: string;
                    }[];
                },
        ) => Effect<void, PlaywrightError>;
        storageState: (
            options?: { credentials?: boolean; indexedDB?: boolean; path?: string },
        ) => Effect<
            {
                cookies: {
                    domain: string;
                    expires: number;
                    httpOnly: boolean;
                    name: string;
                    path: string;
                    sameSite: "None"
                    | "Strict"
                    | "Lax";
                    secure: boolean;
                    value: string;
                }[];
                origins: {
                    localStorage: { name: string; value: string }[];
                    origin: string;
                }[];
            },
            PlaywrightError,
        >;
        tracing: Playwright.Tracing;
    }
    Index
    eventStream: <
        K extends
            | "dialog"
            | "page"
            | "close"
            | "console"
            | "download"
            | "frameattached"
            | "framedetached"
            | "framenavigated"
            | "request"
            | "requestfailed"
            | "requestfinished"
            | "response"
            | "backgroundpage"
            | "pageclose"
            | "pageload"
            | "serviceworker"
            | "weberror",
    >(
        event: K,
    ) => Stream<
        ReturnType<
            {
                backgroundpage: (page: Page) => Playwright.Page;
                close: (context: BrowserContext) => Playwright.BrowserContext;
                console: (a: ConsoleMessage) => ConsoleMessage;
                dialog: (dialog: Dialog) => Playwright.Dialog;
                download: (download: Download) => Playwright.Download;
                frameattached: (frame: Frame) => Playwright.Frame;
                framedetached: (frame: Frame) => Playwright.Frame;
                framenavigated: (frame: Frame) => Playwright.Frame;
                page: (page: Page) => Playwright.Page;
                pageclose: (page: Page) => Playwright.Page;
                pageload: (page: Page) => Playwright.Page;
                request: (request: Request) => Playwright.Request;
                requestfailed: (request: Request) => Playwright.Request;
                requestfinished: (request: Request) => Playwright.Request;
                response: (response: Response) => Playwright.Response;
                serviceworker: (worker: Worker) => Playwright.Worker;
                weberror: (a: WebError) => WebError;
            }[K],
        >,
    >

    Streams browser-context events after adapting their payloads to wrapper values.

    Details

    Event listeners are removed when stream consumption ends. The stream also ends when the browser context closes.

    0.1.2

    addCookies: (
        cookies: readonly {
            domain?: string;
            expires?: number;
            httpOnly?: boolean;
            name: string;
            partitionKey?: string;
            path?: string;
            sameSite?: "None" | "Strict" | "Lax";
            secure?: boolean;
            url?: string;
            value: string;
        }[],
    ) => Effect<void, PlaywrightError>

    Sets the cookies for the browser context.

    addInitScript: <Arg>(
        script: PageFunction<Arg, unknown> | { content?: string; path?: string },
        arg?: Arg,
        options?: { exposeFunctions?: boolean },
    ) => Effect<void, PlaywrightError>

    Adds a script which would be evaluated in one of the following scenarios:

    • Whenever a page is created in the browser context or is navigated.
    • Whenever a child frame is attached or navigated. In this case, the script is evaluated in the context of the newly attached frame.
    browser: () => Option<Playwright.Browser>

    Returns the browser that the context belongs to.

    clearCookies: (
        options?: {
            domain?: string | RegExp;
            name?: string | RegExp;
            path?: string | RegExp;
        },
    ) => Effect<void, PlaywrightError>

    Clears the cookies from the browser context.

    clearPermissions: Effect<void, PlaywrightError>

    Clears the permissions from the browser context.

    Access the clock.

    close: Effect<void, PlaywrightError>

    Closes the browser context.

    0.1.0

    cookies: (urls?: string | string[]) => Effect<Cookie[], PlaywrightError>

    Returns the cookies for the browser context.

    credentials: Playwright.Credentials

    Access the virtual WebAuthn credentials manager.

    grantPermissions: (
        permissions: readonly string[],
        options?: { origin?: string },
    ) => Effect<void, PlaywrightError>

    Grants permissions to the browser context.

    isClosed: () => boolean

    Indicates that the browser context is in the process of closing or has already been closed.

    Opens a new page in the browser context.

    pages: () => Playwright.Page[]

    Returns the list of all open pages in the browser context.

    0.1.0

    setDefaultNavigationTimeout: (timeout: number) => void

    Sets the default navigation timeout for the browser context.

    setDefaultTimeout: (timeout: number) => void

    Sets the default timeout for the browser context.

    setExtraHTTPHeaders: (
        headers: { [key: string]: string },
    ) => Effect<void, PlaywrightError>

    Sets the extra HTTP headers for the browser context.

    setGeolocation: (
        geolocation:
            | { accuracy?: number; latitude: number; longitude: number }
            | null,
    ) => Effect<void, PlaywrightError>

    Sets the geolocation for the browser context.

    setOffline: (offline: boolean) => Effect<void, PlaywrightError>

    Sets the offline state for the browser context.

    setStorageState: (
        options:
            | string
            | {
                cookies: {
                    domain: string;
                    expires: number;
                    httpOnly: boolean;
                    name: string;
                    path: string;
                    sameSite: "None"
                    | "Strict"
                    | "Lax";
                    secure: boolean;
                    value: string;
                }[];
                origins: {
                    localStorage: { name: string; value: string }[];
                    origin: string;
                }[];
            },
    ) => Effect<void, PlaywrightError>

    Sets the storage state for the browser context.

    storageState: (
        options?: { credentials?: boolean; indexedDB?: boolean; path?: string },
    ) => Effect<
        {
            cookies: {
                domain: string;
                expires: number;
                httpOnly: boolean;
                name: string;
                path: string;
                sameSite: "None"
                | "Strict"
                | "Lax";
                secure: boolean;
                value: string;
            }[];
            origins: {
                localStorage: { name: string; value: string }[];
                origin: string;
            }[];
        },
        PlaywrightError,
    >

    Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB snapshot.

    Access the tracing.

    0.5.0