mokr.browser.browser
Classes
This class is created upon connect to a browser. It is essentially a |
Module Contents
- class mokr.browser.browser.Browser(browser_type: Literal['chrome', 'firefox'], connection: mokr.connection.Connection, context_ids: list[str], ignore_https_errors: bool, default_viewport: dict | None, process: subprocess.Popen | None = None, close_callback: Callable | None = None, proxy_credentials: dict | None = None, default_user_agent: str | None = None, **kwargs: Any)
Bases:
pyee.EventEmitterThis class is created upon connect to a browser. It is essentially a container for the individual pages and browser contexts.
- Parameters:
browser_type (Literal["chrome", "firefox"]) – The type of browser.
connection (
mokr.network.Connection) – Websocket connection.context_ids (list[str]) – Browser context identifiers.
ignore_https_errors (bool) – Ignore site security errors.
default_viewport (dict | None) – Default viewport configuration.
process (Popen | None, optional) – Local browser process, if any. Defaults to None.
close_callback (Callable | None, optional) – Callback to run on close. Defaults to None.
proxy_credentials – (dict | None, optional): Dictionary with proxy credentials keyed as “username” and “password”. Credentials should be for the proxy the browser process is bound to.
default_user_agent (str, optional) – Default user agent to use on all new pages.
- property kind: str
One of “chrome” or “firefox”.
- property process: subprocess.Popen | None
The local browser process. If created via
mokr.connect, will return None.
- property version: str
Get browser version (product from browser full version info.)
- property user_agent: str
Get the user agent the browser was spawned with or that is set as the default to override with. This can be overidden later again with
mokr.browser.Page.set_user_agent.
- property browser_contexts: list[mokr.browser.context.BrowserContext]
A list of all
mokr.browser.BrowserContextinstances attached to this browser. By default, this will be a single context.
- property ws_endpoint: str
The websocket URL that this
Browser’smokr.connection.Connectionobject is using.
- async first_page() mokr.browser.page.Page | None
Return the first page in the default context’s
BrowserContext.pages. If no pages active, returns None.- Returns:
First active page in the default context, if any.
- Return type:
Page | None
- async ready() Browser
Enable target discovery in the remote connection.
- Returns:
This
Browserclass.- Return type:
- async create_incognito_browser_context() mokr.browser.context.BrowserContext
Create a new browser context. This is akin to spawning an incognito browser window, it will not share cookies or storage with pages in other contexts. To do so, use
Browser.new_pageinstead.Example:
browser = await launch().launch() # Navigate and login or perform another storage-accessed action. context = await browser.create_incognito_browser_context() page = await context.first_page() # Navigate to the same site. Session isn't shared! ...
- Returns:
A new
mokr.browser.BrowserContext.- Return type:
- async new_page() mokr.browser.page.Page
Spawn a new page within the default context.
- Returns:
A new
mokr.browser.Pageat “about:blank”.- Return type:
- targets() list[mokr.browser.target.Target]
A list of all
mokr.browser.Target`s in all contexts attached to this `Browserobject.- Returns:
- All initialised targets within all contexts in
this browser.
- Return type:
list[Target]
- async pages() list[mokr.browser.page.Page]
A list of all
mokr.browser.Page`s in all contexts attached to this `Browserobject.- Returns:
All pages within all contexts in this browser.
- Return type:
list[Page]
- async close() None
Run the
close_callbackgiven during initialisation.
- async disconnect() None
Disconnect the
Browser’sConnectionobject’s websocket connection and fail anyBrowser.targetsthat haven’t finished initialising.