Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: browsercontext

[10:14] (extern: com.lehman.aussom.ABrowserContext) extends: object

The browsercontext class represents an isolated browser session with its own cookies, local storage, and permissions. Instances are obtained by calling browser.newContext() or browsertype.launchPersistentContext(). Each context is independent - cookies and auth state do not leak between contexts.

Methods

  • newPage ()

    Creates a new page within this browser context.

    • @r A new page object.
  • pages ()

    Returns a list of all open pages in this browser context.

    • @r A list of page objects.
  • close ()

    Closes this browser context and all pages within it.

    • @r This object.
  • browser ()

    Returns the browser that owns this context.

    • @r A browser object, or null if created outside of a browser (e.g. persistent context).
  • cookies (string Url = "")

    Returns cookies for the given URL, or all cookies if no URL is provided.

    • @p Url is an optional string URL to filter cookies by.
    • @r A list of cookie maps with keys: name, value, domain, path, expires, httpOnly, secure, sameSite.
  • addCookies (list Cookies)

    Adds cookies to this browser context. Affects all pages within the context. Each cookie map should include: name, value, and at least one of url or domain/path.

    • @p Cookies is a list of cookie maps.
    • @r This object.
  • clearCookies ()

    Removes all cookies from this browser context.

    • @r This object.
  • grantPermissions (list Permissions, string Origin = "")

    Grants the specified browser permissions to the given origin.

    • @p Permissions is a list of permission strings such as 'geolocation', 'camera', 'microphone', 'notifications'.
    • @p Origin is an optional string URL origin to grant permissions to.
    • @r This object.
  • clearPermissions ()

    Resets all permission overrides for this browser context.

    • @r This object.
  • setGeolocation (double Latitude, double Longitude, double Accuracy = 0.0)

    Overrides the geolocation for all pages in this browser context.

    • @p Latitude is a double with the latitude coordinate.
    • @p Longitude is a double with the longitude coordinate.
    • @p Accuracy is a double with the optional accuracy in meters (default 0.0).
    • @r This object.
  • setOffline (bool Offline)

    Enables or disables offline network emulation for this context.

    • @p Offline is a bool - true to simulate an offline network.
    • @r This object.
  • storageState ()

    Serializes the current cookies, localStorage, and IndexedDB state to a JSON string. Useful for saving and restoring authenticated sessions.

    • @r A string containing the JSON serialized storage state.
  • setDefaultTimeout (double Timeout)

    Sets the default timeout in milliseconds for all action methods on pages within this context. This overrides the Playwright default of 30000ms.

    • @p Timeout is a double with the timeout in milliseconds.
    • @r This object.
  • setDefaultNavigationTimeout (double Timeout)

    Sets the default navigation timeout in milliseconds for all pages within this context. This overrides the Playwright default of 30000ms.

    • @p Timeout is a double with the timeout in milliseconds.
    • @r This object.
  • setExtraHTTPHeaders (map Headers)

    Attaches extra HTTP headers that will be sent with every network request made from pages within this context.

    • @p Headers is a map of header name to header value strings.
    • @r This object.
  • addInitScript (string Script)

    Injects a JavaScript script into every new page and frame within this context before any other scripts execute.

    • @p Script is a string of JavaScript source code to inject.
    • @r This object.
  • waitForPage ()

    Waits for a new page to be created within this context and returns it. Useful when an action (e.g. clicking a link) opens a new tab.

    • @r A new page object.