Quick start pages() Return every open page in the browser context. newPage() Create a new page in the browser context. The initial URL for the new page. Omit it to create a blank page.
activePage() Return the page that is currently active. result Promise<Page | undefined>
The operation result.
setActivePage() Make a page the active page in the browser context. Resolves after the operation completes.
close() Close the remote browser context. Resolves after the operation completes.
addInitScript() Run a script before scripts on every newly created page. A function, JavaScript source string, or object with exactly one of path and content.
An optional JSON-serializable argument. Valid only when script is a function.
Resolves after the operation completes.
Set additional HTTP headers for every page in the context. HTTP header names and values.
Resolves after the operation completes.
getDomainPolicy() Return the context’s current domain policy. result Promise<DomainPolicy | null>
The operation result. Domains that the context may access.
Domains that the context must reject.
setDomainPolicy() Set or clear the context’s domain policy. The policy to apply, or null/None to clear it. Domains that the context may access.
Domains that the context must reject.
Resolves after the operation completes.
cookies() Return cookies, optionally filtered to one or more URLs. A URL or collection of URLs used to filter cookies.
The operation result. The Unix expiration time in seconds, or -1 for a session cookie.
Whether the cookie is restricted to HTTP requests.
Whether the cookie requires HTTPS.
The cookie SameSite policy: "Strict", "Lax", or "None".
addCookies() Add cookies to the browser context. The cookies to add. Each requires name, value, and either url or both domain and path.
Do not combine url with domain or path. -1 for a session cookie or a non-negative Unix timestamp in seconds.
Whether the cookie is restricted to HTTP requests.
The cookie SameSite policy: "Strict", "Lax", or "None". "None" requires a secure cookie.
Whether the cookie requires HTTPS.
The URL scope. Cannot be about:blank or a data: URL.
Resolves after the operation completes.
clearCookies() Clear cookies that match optional name, domain, and path filters. Options that configure this operation. A cookie domain or regular-expression filter.
A cookie name or regular-expression filter.
A cookie path or regular-expression filter.
Resolves after the operation completes.
Quick start pages() Return every open page in the browser context. new_page() Create a new page in the browser context. The initial URL for the new page. Omit it to create a blank page.
active_page() Return the page that is currently active. set_active_page() Make a page the active page in the browser context. Resolves after the operation completes.
close() Close the remote browser context. Resolves after the operation completes.
add_init_script() Run a script before scripts on every newly created page. JavaScript source or a path to a JavaScript file on the SDK caller’s machine.
Resolves after the operation completes.
Set additional HTTP headers for every page in the context. HTTP header names and values.
Resolves after the operation completes.
get_domain_policy() Return the context’s current domain policy. The operation result. Domains that the context may access.
Domains that the context must reject.
set_domain_policy() Set or clear the context’s domain policy. policy DomainPolicy | DomainPolicyInput | None
The policy to apply, or null/None to clear it. Domains that the context may access.
Domains that the context must reject.
Resolves after the operation completes.
cookies() Return cookies, optionally filtered to one or more URLs. urls str | Sequence[str] | None
A URL or collection of URLs used to filter cookies.
The operation result. The Unix expiration time in seconds, or -1 for a session cookie.
Whether the cookie is restricted to HTTP requests.
Whether the cookie requires HTTPS.
result.same_site Literal['Strict', 'Lax', 'None']
The cookie SameSite policy: "Strict", "Lax", or "None".
add_cookies() Add cookies to the browser context. The cookies to add. Each requires name, value, and either url or both domain and path.
Do not combine url with domain or path. -1 for a session cookie or a non-negative Unix timestamp in seconds.
Whether the cookie is restricted to HTTP requests.
cookies.same_site Literal['Strict', 'Lax', 'None']
The cookie SameSite policy: "Strict", "Lax", or "None". "None" requires a secure cookie.
Whether the cookie requires HTTPS.
The URL scope. Cannot be about:blank or a data: URL.
Resolves after the operation completes.
clear_cookies() Clear cookies that match optional name, domain, and path filters. name str | re.Pattern[str] | None
A cookie name or regular-expression filter.
domain str | re.Pattern[str] | None
A cookie domain or regular-expression filter.
path str | re.Pattern[str] | None
A cookie path or regular-expression filter.
Resolves after the operation completes.
Quick start Get the BrowserContext from the browser handle with browser.Context(). Except for the Clipboard() accessor, every method takes a context.Context as its first argument and returns an error as its last result. Pages() Return every open page in the browser context. NewPage() Create a new page in the browser context. The initial URL for the new page. Pass at most one URL; omit it to create a blank page.
ActivePage() Return the page that is currently active. The operation result. Returns nil when no page is active.
SetActivePage() Make a page the active page in the browser context. nil after the operation completes.
Close() Close the remote browser context. nil after the operation completes.
AddInitScript() Run a script before scripts on every newly created page. JavaScript source to evaluate. Go functions and file paths are not interpreted.
nil after the operation completes.
Set additional HTTP headers for every page in the context. HTTP header names and values. The type is a named map[string]string, so a plain map literal works.
nil after the operation completes.
GetDomainPolicy() Return the context’s current domain policy. The operation result. Returns nil when no policy is set. Domains that the context may access.
Domains that the context must reject.
SetDomainPolicy() Set or clear the context’s domain policy. The policy to apply, or nil to clear it. Domains that the context may access.
Domains that the context must reject.
nil after the operation completes.
Cookies() Return cookies, optionally filtered to one or more URLs. A collection of URLs used to filter cookies. Pass nil to return every cookie.
The operation result. The Unix expiration time in seconds, or -1 for a session cookie.
Whether the cookie is restricted to HTTP requests.
Whether the cookie requires HTTPS.
The cookie SameSite policy: CookieSameSiteStrict, CookieSameSiteLax, or
CookieSameSiteNone.
AddCookies() Add cookies to the browser context. The cookies to add. Each requires Name, Value, and either URL or both Domain and Path.
Do not combine URL with Domain or Path. Optional fields are pointers. -1 for a session cookie or a non-negative Unix timestamp in seconds.
Whether the cookie is restricted to HTTP requests.
The cookie SameSite policy: CookieParamSameSiteStrict, CookieParamSameSiteLax, or
CookieParamSameSiteNone. CookieParamSameSiteNone requires a secure cookie.
Whether the cookie requires HTTPS.
The URL scope. Cannot be about:blank or a data: URL.
nil after the operation completes.
ClearCookies() Clear cookies that match optional name, domain, and path filters. Options that configure this operation. Pass nil to clear every cookie. Build each filter with ExactCookie() for an exact string or RegexCookie() for a regular expression. nil after the operation completes.