Telepath API

class synmods.playwright.service.PlaywrightApi

Bases: StormSvc, CellApi

async browser(conf: Dict | None = None) Browser | None

Create a new Chromium browser and return a Telepath Share.

Note

Users should use the Storm package API instead of calling this directly.

Parameters:

conf (dict or None) – Optional configuration to apply to the browser launch and contexts.

Returns:

The Browser share or None on error.

Return type:

(s_telepath.Share or None)

async getPlaywrightMeta() Dict[str, str | bool]

Get meta information about the Playwright browser configuration.

Returns:

Dictionary with a meta keyvals under a “browser” key.

Return type:

dict

class synmods.playwright.service.Browser

Bases: Share

async close() None

Close the Playwright Browser and all associated Pages.

The Browser and Pages will no longer be available for use after calling this method

async page(loadurl: str | None = None, conf: Dict | None = None) Page | None

Create a new browser page and return the Telepath Share.

Note

Users should use the Storm package API instead of calling this directly.

Parameters:
  • loadurl (str or None) – Optional URL to load in the page.

  • conf (dict or None) – Optional context configuration to apply to the page.

Returns:

The Page Telepath Share or None on error.

Return type:

(s_telepath.Share or None)

class synmods.playwright.service.Page

Bases: Share

async click(selector: str) Tuple[bool, None | str, Dict]

Click on a page element by selector.

Note

If the selector does not exist this execution will wait for it appear (or timeout). By default this waits for navigation (if any).

Parameters:

selector (str) – The CSS selector to click.

Returns:

A retn tuple with the bool indicating if the click was successful.

Return type:

(bool, None or str, dict)

async close() None

Close the Playwright page and fini the Telepath Share.

The Page will no longer be available for use after calling this method.

async closeBrowser() None

Close the Playwright Browser and all associated Pages.

The Browser and Pages will no longer be available for use after calling this method

async emulateMedia(media: Literal['print', 'screen'] = None) Tuple[bool, None | str, Dict]

Change the CSS media type of the current page.

Parameters:

media (str) – The CSS media type. If None, CSS media emulation is disabled.

Returns:

A retn tuple with the bool indicating if the action was successful.

Return type:

(bool, None or str, dict)

async fill(selector: str, text: str) Tuple[bool, None | str, Dict]

Fill an element by selector with text.

Note

If the selector does not exist this execution will wait for it appear (or timeout).

Parameters:
  • selector (str) – The element CSS selector.

  • text (str) – The text to fill.

Returns:

A retn tuple with the bool indicating if the action was successful.

Return type:

(bool, None or str, dict)

async getHtml() Tuple[bool, str, Dict]

Get the rendered HTML of the page as a string.

Returns:

A retn tuple containing the HTML string or an error string.

Return type:

(bool, str, dict)

async getStorageState() Tuple[bool, Dict | str, Dict]

Get the storage state for the current context.

Returns:

A retn tuple containing the state dictionary or an error string.

Return type:

(bool, dict or str, dict)

async goto(url: str) Tuple[bool, Dict | str, Dict]

Goto a URL and loading into this Page.

Note

By default this waits until the load event is fired. All response codes are treated as valid non-error results.

Parameters:

url (str) – The URL to goto.

Returns:

A retn tuple containing the response object or an error string.

Return type:

(bool, dict or str, dict)

async info() Tuple[bool, Dict | str, Dict]

Retrieve information about the current session.

Returns:

Retn with info dictionary as result.

The info dictionary has the following structure:

{
    'browser': {
        'iden': The iden of the Browser share,
        'type': Browser name, e.g. chromium,
        'version': The browser version string,
        'connected': Boolean indicating if the browser is connected,
        'contexts': The number of contexts initialized in the browser,
    },
    'url': The URL currently loaded in the page,
    'closed': Boolean indicating if the page is closed,
    'context_pages': The number of pages open in the current context,
}

Return type:

(bool, dict or str, dict)

async jseval(text: str, arg: Any | None = None) Tuple[bool, Any, Dict]

Execute JavaScript in the page and return the result.

Note

If the result is not serializable the result is set as None. No timeout is applied to this execution.

Parameters:

text (str) – The JavaScript to execute.

Returns:

A retn tuple containing the result or an error string.

Return type:

(bool, Any, dict)

async key(action: Literal['up', 'down', 'press'], key: str) Tuple[bool, None | str, Dict]

Simulate a key action.

Parameters:
  • action (str) – One of up, down, or press.

  • key (str) – The key name.

Returns:

A retn tuple with the bool indicating if the action was successful.

Return type:

(bool, None or str, dict)

async saveHtml() Tuple[bool, Tuple[int, str] | str, Dict]

Save the rendered HTML of the page to the Axon.

Returns:

A retn tuple containing the file (size, sha256) or an error string.

Return type:

(bool, (int, str) or str, dict)

async savePdf(opts: Dict[str, float | bool | str] | None = None) Tuple[bool, Tuple[int, str] | str, Dict]

Generate a PDF of the renered page and save to the Axon.

See https://playwright.dev/python/docs/api/class-page#page-pdf for supported PDF opts (“path” argument is not supported).

Parameters:

opts (dict or None) – Optional kwargs to pass to Playwright pdf().

Returns:

A retn tuple containing the file (size, sha256) or an error string.

Return type:

(bool, (int, str) or str, dict)

async spawn() Page | None

Spawn a new Page that shares a context with this Page.

Note

Users should use the Storm package API instead of calling this directly.

Returns:

A new Page Telepath Share or None on error.

Return type:

(s_telepath.Share or None)

async type(text: str) Tuple[bool, None | str, Dict]

Simulate typing text using key presses.

Parameters:

text (str) – The text to type.

Returns:

A retn tuple with the bool indicating if the action was successful.

Return type:

(bool, None or str, dict)

async waitEvent(event: str) Tuple[bool, None | str, Dict]

Wait for an Event and return an error on timeout.

Note

The event is typically the same as passed to a JavaScript event listener.

Example

Wait for a console log event:

await page.waitEvent('console')
Parameters:

event (str) – The event name.

Returns:

A retn tuple with the bool indicating if the wait was successful.

Return type:

(bool, None or str, dict)

async waitLoad(state: Literal['load', 'domcontentloaded', 'networkidle'] = 'load') Tuple[bool, None | str, Dict]

Wait for a load state and return immediately if it is already reached.

Parameters:

state (str) – One of load (default), domcontentloaded, networkidle.

Returns:

A retn tuple with the bool indicating if the wait was successful.

Return type:

(bool, None or str, dict)

async waitSelector(selector: str, timeout: float | None = None) Tuple[bool, None | str, Dict]

Wait for a selector to be in the DOM and be visible.

Parameters:
  • selector (str) – The CSS selector to wait for.

  • timeout (float or None) – Optional timeout in seconds that overrides configuration value.

Returns:

A retn tuple with the bool indicating if the wait was successful.

Return type:

(bool, None or str, dict)