mokr.browser.context

Attributes

LOGGER

Classes

BrowserContext

Browser context within the browser process. Contexts are independent

Module Contents

mokr.browser.context.LOGGER
class mokr.browser.context.BrowserContext(browser: mokr.browser.Browser, context_id: str | None)

Bases: pyee.EventEmitter

Browser context within the browser process. Contexts are independent of one another, not sharing storage. Contexts beyond the default context that mokr.browser.Browser starts with will be incognito.

Parameters:
  • browser (Browser) – Parent mokr.browser.Browser object from which the context was spawned.

  • context_id (str | None) – The context identifier (may be None).

property incognito: bool

True if the browser context is incognito, otherwise False. Only default context spawned when the mokr.browser.Browser object is spawned is not incognito.

property browser: mokr.browser.Browser

The mokr.browser.Browser object this context is attached to.

targets() list[mokr.browser.target.Target]

A list of all `mokr.browser.Target`s in this context.

Returns:

All initialised targets within this context.

Return type:

list[Target]

async pages() list[mokr.browser.page.Page]

A list of all `mokr.browser.Page`s in this context.

Returns:

All pages within this context.

Return type:

list[Page]

async first_page() mokr.browser.page.Page

Return the first page in BrowserContext.pages. If no pages active, returns None.

Returns:

First active page in this context, if any.

Return type:

Page | None

async new_page() mokr.browser.page.Page

Spawn a new page.

Returns:

A new mokr.browser.Page at “about:blank”.

Return type:

Page

async close() None

Close the context. Can only be done on incognito contexts.

Raises:

BrowserError – Raised if called from the default context.