Interact with a Playwright BrowserContext.
There is no official documentation, since this is considered Playwright internal.
References:
Summary
Functions
Adds cookies into this browser context.
Adds a script which would be evaluated in one of the following scenarios
Removes cookies from this browser context.
Closes the browser context.
Returns cookies from this browser context.
Creates a new page in the browser context.
Registers a custom selector engine.
Types
@type add_cookies_opt() :: {:connection, GenServer.name()} | {:timeout, timeout()} | {:cookies, [term()]}
@type add_init_script_opt() :: {:connection, GenServer.name()} | {:timeout, timeout()} | {:content, binary()}
@type clear_cookies_opt() :: {:connection, GenServer.name()} | {:timeout, timeout()} | {:domain, term()} | {:name, term()} | {:path, term()}
@type close_opt() :: {:connection, GenServer.name()} | {:timeout, timeout()} | {:reason, binary()}
@type cookies_opt() :: {:connection, GenServer.name()} | {:timeout, timeout()} | {:urls, [binary()]}
@type new_page_opt() :: {:connection, GenServer.name()} | {:timeout, timeout()}
@type register_selector_engine_opt() :: {:connection, GenServer.name()} | {:timeout, timeout()} | {:selector_engine, keyword()}
Functions
@spec add_cookies(PlaywrightEx.guid(), [ add_cookies_opt() | PlaywrightEx.unknown_opt() ]) :: {:ok, any()} | {:error, any()}
Adds cookies into this browser context.
Reference: https://playwright.dev/docs/api/class-browsercontext#browser-context-add-cookies
Options
:connection(term/0) - The Connection process name. Defaults toPlaywrightEx.Supervisor.Connection. The default value isPlaywrightEx.Supervisor.Connection.:timeout(timeout/0) - Required. Maximum time for the operation (milliseconds).:cookies(list ofterm/0) - Required. Adds cookies into this browser context. All pages within this context will have these cookies installed.
@spec add_init_script(PlaywrightEx.guid(), [ add_init_script_opt() | PlaywrightEx.unknown_opt() ]) :: {:ok, any()} | {:error, any()}
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 any page in the browser context. In this case, the script is evaluated in the context of the newly attached frame.
The script is evaluated after the document was created but before any of its scripts were run.
This is useful to amend the JavaScript environment, e.g. to seed Math.random.
Reference: https://playwright.dev/docs/api/class-browsercontext#browser-context-add-init-script
Script Execution Order Is Not Defined
The order of evaluation of multiple scripts installed via
PlaywrightEx.BrowserContext.add_init_script/2 and
PlaywrightEx.Page.add_init_script/2 is not defined.
Options
:connection(term/0) - The Connection process name. Defaults toPlaywrightEx.Supervisor.Connection. The default value isPlaywrightEx.Supervisor.Connection.:timeout(timeout/0) - Required. Maximum time for the operation (milliseconds).:content(String.t/0) - Required. Raw JavaScript code to be evaluated in all pages before any scripts run.
@spec clear_cookies(PlaywrightEx.guid(), [ clear_cookies_opt() | PlaywrightEx.unknown_opt() ]) :: {:ok, any()} | {:error, any()}
Removes cookies from this browser context.
Reference: https://playwright.dev/docs/api/class-browsercontext#browser-context-clear-cookies
Options
:connection(term/0) - The Connection process name. Defaults toPlaywrightEx.Supervisor.Connection. The default value isPlaywrightEx.Supervisor.Connection.:timeout(timeout/0) - Required. Maximum time for the operation (milliseconds).:domain(term/0) - Only removes cookies with the given domain.:name(term/0) - Only removes cookies with the given name.:path(term/0) - Only removes cookies with the given path.
@spec close(PlaywrightEx.guid(), [close_opt() | PlaywrightEx.unknown_opt()]) :: {:ok, any()} | {:error, any()}
Closes the browser context.
Reference: https://playwright.dev/docs/api/class-browsercontext#browser-context-close
Options
:connection(term/0) - The Connection process name. Defaults toPlaywrightEx.Supervisor.Connection. The default value isPlaywrightEx.Supervisor.Connection.:timeout(timeout/0) - Required. Maximum time for the operation (milliseconds).:reason(String.t/0) - The reason to be reported to the operations interrupted by the context closure.
@spec cookies(PlaywrightEx.guid(), [cookies_opt() | PlaywrightEx.unknown_opt()]) :: {:ok, [map()]} | {:error, any()}
Returns cookies from this browser context.
Reference: https://playwright.dev/docs/api/class-browsercontext#browser-context-cookies
Options
:connection(term/0) - The Connection process name. Defaults toPlaywrightEx.Supervisor.Connection. The default value isPlaywrightEx.Supervisor.Connection.:timeout(timeout/0) - Required. Maximum time for the operation (milliseconds).:urls(list ofString.t/0) - If specified, returns cookies for the given URLs. The default value is[].
@spec new_page(PlaywrightEx.guid(), [new_page_opt() | PlaywrightEx.unknown_opt()]) :: {:ok, %{guid: PlaywrightEx.guid(), main_frame: %{guid: PlaywrightEx.guid()}}} | {:error, any()}
Creates a new page in the browser context.
Reference: https://playwright.dev/docs/api/class-browsercontext#browser-context-new-page
Options
@spec register_selector_engine(PlaywrightEx.guid(), [ register_selector_engine_opt() | PlaywrightEx.unknown_opt() ]) :: {:ok, any()} | {:error, any()}
Registers a custom selector engine.
Reference: https://playwright.dev/docs/api/class-selectors#selectors-register
Options
:connection(term/0) - The Connection process name. Defaults toPlaywrightEx.Supervisor.Connection. The default value isPlaywrightEx.Supervisor.Connection.:timeout(timeout/0) - Required. Maximum time for the operation (milliseconds).:selector_engine(non-emptykeyword/0) - Required.:name(String.t/0) - Required. Name that is used in selectors as a prefix.:source(String.t/0) - Required. Script that evaluates to a selector engine instance.