mokr.browser.target

Attributes

KINDS

Classes

Target

Representative of a remote target.

Module Contents

mokr.browser.target.KINDS
class mokr.browser.target.Target(browser: mokr.browser.Browser, target_info: dict, browser_context: mokr.browser.context.BrowserContext, session_factory: Callable, ignore_https_errors: bool, default_viewport: dict | None, screenshot_task_queue: list, loop: asyncio.AbstractEventLoop, proxy_credentials: dict | None = None, user_agent_data: dict[str, str] | None = None)

Representative of a remote target. Targets are a somewhat obscure concept, they can be a browser, frame, page, worker, or more. For the purposes of this package, only browser, pages, and workers are tracked explicitly. Full list of target types can be found at devtools_agent_host_impl.cc at https://source.chromium.org/chromium/chromium/src/.

Parameters:
  • browser (Browser) – Parent mokr.browser.Browser.

  • target_info (dict) – The “targetInfo” in the event emitted that triggered this object’s initialisation.

  • browser_context (BrowserContext) – The mokr.browser.BrowserContext that this spawned from.

  • session_factory (Callable) – Callable that creates a new mokr.connection.DevtoolsConnection for this target.

  • ignore_https_errors (bool) – Whether network security errors should be ignored or not. Inherited from parent mokr.browser.Browser.

  • default_viewport (dict | None) – Default viewport configuration. Inherited from parent mokr.browser.Browser.

  • screenshot_task_queue (list) – The screenshot task queue, empty by default. Inherited from parent mokr.browser.Browser.

  • loop (asyncio.AbstractEventLoop) – The asyncio loop that is tracked under the mokr.browser.Browser’s mokr.connection.Connection.

  • 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. Inherited from parent mokr.browser.Browser.

  • user_agent_data (dict[str, str] | None, optional) – A dictionary containing the user agent and an indicator to whether it was the original or an override.

property url: str

Get url of this target.

property kind: KINDS

Get type of this target. Type may be on of “page”, “background_page”, “service_worker”, “browser”, or “other”.

property browser: mokr.browser.Browser

The mokr.browser.Browser that owns the mokr.browser.BrowserContext that this target was initialised from.

property browser_context: mokr.browser.context.BrowserContext

mokr.browser.BrowserContext this target was initialised from.

property opener: Target | None

The parent Target that spawned this, if any.

async create_devtools_connection() mokr.connection.DevtoolsConnection

Initialise the mokr.connection.DevtoolsConnection that will be bound to this Target.

Returns:

The new mokr.connection.DevtoolsConnection.

Return type:

DevtoolsConnection

async page() mokr.browser.page.Page | None

Get the mokr.browser.Page object attached to this Target. Only applicable if Target.kind is “page” or “background_page”.

Returns:

Associated mokr.browser.Page, if any.

Return type:

Page | None