class: browsercontext
[26: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
Anew page object.
- @r
-
pages ()
Returns a list of all open pages in this browser context.
- @r
Alist of page objects.
- @r
-
close ()
Closes this browser context and all pages within it.
- @r
Thisobject.
- @r
-
browser ()
Returns the browser that owns this context.
- @r
Abrowser object, or null if created outside of a browser (e.g. persistent context).
- @r
-
cookies (
string Url = "")Returns cookies for the given URL, or all cookies if no URL is provided.
- @p
Urlis an optional string URL to filter cookies by. - @r
Alist of cookie maps with keys: name, value, domain, path, expires, httpOnly, secure, sameSite.
- @p
-
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
Cookiesis a list of cookie maps. - @r
Thisobject.
- @p
-
clearCookies ()
Removes all cookies from this browser context.
- @r
Thisobject.
- @r
-
grantPermissions (
list Permissions, string Origin = "")Grants the specified browser permissions to the given origin.
- @p
Permissionsis a list of permission strings such as 'geolocation', 'camera', 'microphone', 'notifications'. - @p
Originis an optional string URL origin to grant permissions to. - @r
Thisobject.
- @p
-
clearPermissions ()
Resets all permission overrides for this browser context.
- @r
Thisobject.
- @r
-
setGeolocation (
double Latitude, double Longitude, double Accuracy = 0.0)Overrides the geolocation for all pages in this browser context.
- @p
Latitudeis a double with the latitude coordinate. - @p
Longitudeis a double with the longitude coordinate. - @p
Accuracyis a double with the optional accuracy in meters (default 0.0). - @r
Thisobject.
- @p
-
setOffline (
bool Offline)Enables or disables offline network emulation for this context.
- @p
Offlineis a bool - true to simulate an offline network. - @r
Thisobject.
- @p
-
storageState ()
Serializes the current cookies, localStorage, and IndexedDB state to a JSON string. Useful for saving and restoring authenticated sessions.
- @r
Astring containing the JSON serialized storage state.
- @r
-
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
Timeoutis a double with the timeout in milliseconds. - @r
Thisobject.
- @p
-
setDefaultNavigationTimeout (
double Timeout)Sets the default navigation timeout in milliseconds for all pages within this context. This overrides the Playwright default of 30000ms.
- @p
Timeoutis a double with the timeout in milliseconds. - @r
Thisobject.
- @p
-
setExtraHTTPHeaders (
map Headers)Attaches extra HTTP headers that will be sent with every network request made from pages within this context.
- @p
Headersis a map of header name to header value strings. - @r
Thisobject.
- @p
-
addInitScript (
string Script)Injects a JavaScript script into every new page and frame within this context before any other scripts execute.
- @p
Scriptis a string of JavaScript source code to inject. - @r
Thisobject.
- @p
-
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
Anew page object.
- @r