Skip to content

API Reference parrot_tools.scraping.session_actions

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.scraping.session_actions

View source

Session-identity browser actions — authenticate, cookies, file transfer, human-in-the-loop waits, and browser events.

Stateless async helpers extracted from the legacy WebScrapingTool so the modern executor.py dispatch path and the legacy tool can share a single implementation (FEAT-453, Module 1). This mirrors the extraction shape FEAT-222 established in advanced_actions.py for Loop/Conditional: module-level async def exec_<action>(driver, action, ...) functions that accept an :class:AbstractDriver plus (where recursion is needed) a dispatch_step_fn callback — never methods on a tool class.

Before this module existed, executor.py::_dispatch_step matched these action types, logged a warning, and returned True — reporting success without doing anything. That defect is the reason this module exists: every function here returns False (never True) on a failure path.

Alias AbstractDriver

Re-exported from parrot_tools.scraping.drivers.abstract.AbstractDriver.

Alias Authenticate

Re-exported from parrot_tools.scraping.models.Authenticate.

Alias AwaitBrowserEvent

Re-exported from parrot_tools.scraping.models.AwaitBrowserEvent.

Alias AwaitHuman

Re-exported from parrot_tools.scraping.models.AwaitHuman.

Alias AwaitKeyPress

Re-exported from parrot_tools.scraping.models.AwaitKeyPress.

Attribute CredentialResolverFn

Attribute DispatchStepFn

Alias GetCookies

Re-exported from parrot_tools.scraping.models.GetCookies.

Alias PathConfinementError

Re-exported from parrot_tools.scraping.confine.PathConfinementError.

Alias ScrapingStep

Re-exported from parrot_tools.scraping.models.ScrapingStep.

Alias SetCookies

Re-exported from parrot_tools.scraping.models.SetCookies.

Alias UploadFile

Re-exported from parrot_tools.scraping.models.UploadFile.

Alias WaitForDownload

Re-exported from parrot_tools.scraping.models.WaitForDownload.

Function exec_authenticate

Execute an :class:Authenticate action.

Supports all four method values: - "form" (default) — fills username_selector/password_selector and clicks submit_selector. enter_on_username=True presses Enter after the username field for multi-step logins. - "basic" — HTTP Basic Auth via credentials embedded in the URL (scheme://user:pass@host/...), navigated via the driver. - "oauth" / "custom" — dispatches action.custom_steps sequentially through dispatch_step_fn, since neither has a generic form-based flow.

exec_authenticate(driver: AbstractDriver, action: Authenticate, dispatch_step_fn: Optional[DispatchStepFn], *, credential_resolver: Optional[CredentialResolverFn] = None, timeout: int = 30) -> bool

Parameter Type Default Description
driver AbstractDriver Browser driver implementing :class:AbstractDriver.
action Authenticate The :class:Authenticate model to execute.
dispatch_step_fn Optional[DispatchStepFn] Callback used to dispatch custom_steps (required for method in ("oauth", "custom")).
credential_resolver Optional[CredentialResolverFn] None Optional async callable resolving credentials (e.g. via a CredentialBroker) instead of reading action.username/action.password literally. When action.credential_provider is set (TASK-2389, Decision G3 — "no credentials in plan JSON"), only the resolver is consulted: a missing resolver, a resolver exception, a None result (broker miss), or an incomplete credential all fail the step closed — the literal fields are never read in this case, even as a fallback. When action.credential_provider is unset, credential_resolver is an optional soft override (pre-TASK-2389 behaviour, kept for back-compat): a non-None result overrides the literal fields field-by-field; a None result or no resolver at all falls back to the literal fields.
timeout int 30 Timeout (seconds) applied to navigation/wait steps.

Returns: bool — True on success, False on any failure. Never raises for expected failure modes — an unhandled exception is caught, logged (without leaking credentials), and turned into False.

Function exec_await_browser_event

Execute an :class:AwaitBrowserEvent action.

Pauses automation until a user triggers a browser-side event: pressing a configured key combo, clicking an optional floating "Resume" button, dispatching a custom DOM event, or setting a localStorage flag — whichever is configured via action.wait_condition/action.target.

exec_await_browser_event(driver: AbstractDriver, action: AwaitBrowserEvent) -> bool

Parameter Type Default Description
driver AbstractDriver Browser driver implementing :class:AbstractDriver.
action AwaitBrowserEvent The :class:AwaitBrowserEvent model.

Returns: bool — True once the event is received; False on timeout.

Function exec_await_human

Execute an :class:AwaitHuman action.

exec_await_human(driver: AbstractDriver, action: AwaitHuman, *, channel: Optional[HumanChannel] = None) -> bool

Parameter Type Default Description
driver AbstractDriver Browser driver implementing :class:AbstractDriver.
action AwaitHuman The :class:AwaitHuman model — one of four condition_type values (selector, url_contains, title_contains, manual).
channel Optional[HumanChannel] None Optional injected :class:HumanChannel (parrot.human — not a bespoke notifier, Decision D2). DOM-based condition types notify it when supplied; condition_type="manual" requires it.

Returns: bool — True once the condition is satisfied (or a manual confirmation is received); False on timeout, missing condition, or a manual wait with no channel (fails closed immediately).

Function exec_await_keypress

Execute an :class:AwaitKeyPress action.

Pauses until the operator presses a key in the console (stdin). Useful when there is no reliable selector to wait on. driver is accepted (unused) for signature parity with the other exec_* functions.

exec_await_keypress(driver: AbstractDriver, action: AwaitKeyPress) -> bool

Parameter Type Default Description
driver AbstractDriver Browser driver implementing :class:AbstractDriver (unused).
action AwaitKeyPress The :class:AwaitKeyPress model — expected_key (None means any key), message, and timeout (default 300s).

Returns: bool — True once the expected key (or any key, if unset) is pressed; False on timeout.

Function exec_get_cookies

Execute a :class:GetCookies action.

exec_get_cookies(driver: AbstractDriver, action: GetCookies) -> Dict[str, Any]

Parameter Type Default Description
driver AbstractDriver Browser driver implementing :class:AbstractDriver.
action GetCookies The :class:GetCookies model (optional names/domain filters).

Returns: Dict[str, Any] — {"cookies": [...]} — a list of {"name": ..., "value": ...} dicts. Returns an empty list (never raises) if cookie extraction fails.

Function exec_set_cookies

Execute a :class:SetCookies action.

exec_set_cookies(driver: AbstractDriver, action: SetCookies) -> bool

Parameter Type Default Description
driver AbstractDriver Browser driver implementing :class:AbstractDriver.
action SetCookies The :class:SetCookies model — a list of cookie dicts with at least name/value, and optional path, domain, secure, same_site/sameSite.

Returns: bool — True if every cookie was set; False on any failure.

Function exec_upload_file

Execute an :class:UploadFile action.

Uploads via driver.fill(selector, path) — the only file-input interaction available through :class:AbstractDriver (neither the ABC nor its concrete drivers expose an upload_file/set_input_files method). This is the same mechanism Selenium's send_keys on a file input uses under the hood; Playwright's fill() does not support file inputs, so this action is effectively Selenium-oriented until a native per-driver upload hook exists.

exec_upload_file(driver: AbstractDriver, action: UploadFile) -> bool

Parameter Type Default Description
driver AbstractDriver Browser driver implementing :class:AbstractDriver.
action UploadFile The :class:UploadFile model — single file_path or, with multiple_files=True, the file_paths list.

Returns: bool — True on success; False if a path is missing, escapes the configured root, or the driver interaction fails.

Function exec_wait_for_download

Execute a :class:WaitForDownload action.

Polls the filesystem for a file matching filename_pattern that has stabilised (size unchanged across a short interval and non-zero) — downloads are a driver-external filesystem event, so there is no :class:AbstractDriver method for this; driver is accepted (unused) for signature parity with the other exec_* functions.

exec_wait_for_download(driver: AbstractDriver, action: WaitForDownload) -> bool

Parameter Type Default Description
driver AbstractDriver Browser driver implementing :class:AbstractDriver (unused).
action WaitForDownload The :class:WaitForDownload model — filename_pattern, download_path, timeout, move_to, delete_after.

Returns: bool — True once a matching, stable download is found (and moved, if move_to is set); False on timeout or a rejected path.

Attribute logger

Alias within_root

Re-exported from parrot_tools.scraping.confine.within_root.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally