Metadata-Version: 2.4
Name: helixwright
Version: 0.8.0
Summary: Python automation SDK for Helix Browser Local API and the private Helix RPC page-control plane.
Author: Helix Browser
License-Expression: LicenseRef-Proprietary
Project-URL: Homepage, https://pypi.org/project/helixwright/
Project-URL: Documentation, http://66.154.125.146:8000/helixwright/
Keywords: automation,browser,fingerprint,chromium,local-api,helix
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Typing :: Typed
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# Helixwright

Helixwright is the Python automation SDK for Helix Browser.

Version `0.8.0` is a V5-only public facade. It does not use CDP,
WebDriver, Playwright, Selenium, direct `chrome.exe` launch, local profile
folders, or local fingerprint generation.

## Runtime Model

Helixwright talks to Helix Browser Desktop Local API. The desktop app creates or
reuses a server-owned profile, starts an automation session, and returns a
private Browser RPC endpoint. Page automation then uses Browser RPC V5.

Runtime rules:

- `/rpc` is used only for `rpc.hello` discovery.
- Normal runtime control must switch to `/rpc/v5`.
- Older RPC V1/V2/V3/V4 cores are rejected.
- `Locator` is the canonical element-action layer.
- `Input` is raw trusted input only.
- Browser profiles, fingerprints, geo-follow, proxy materialization, and cloud
  sync are owned by Helix Browser, not by the SDK.

`0.8.0` is designed for the cloud-active M149 Browser RPC V5 core that includes
the 0073 input/scroll/receipt capability set. The SDK rejects missing baseline
V5 element/input capabilities; the reliability guarantees documented for
`0.8.0` apply to that current cloud-active core contract.

## Install

```bash
pip install helixwright
```

Local source development:

```powershell
cd "G:\Helix Browser\repos\helixwright"
pip install -e .
python tests\ci.py
```

## Quick Start

```python
import helixwright as hw

with hw.launch("https://example.com", name="demo") as page:
    page.wait_for("body")
    print(page.title())
    page.locator("body").click()
```

Most scripts only need a URL and, when required, a proxy:

```python
with hw.launch(
    "https://example.com",
    proxy="http://user:pass@127.0.0.1:7890",
) as page:
    print(page.profile_id, page.session_id)
```

Reuse an existing Helix profile only when you already know that profile should
be used:

```python
with hw.launch("https://example.com", reuse_profile_id="p_existing") as page:
    print(page.url)
```

## Public Objects

| Object | Purpose |
| --- | --- |
| `Client` | Local API client and profile/browser/core managers. |
| `Page` | Primary automation session returned by `hw.launch()`. |
| `Locator` | Element lookup and element-bound actions. |
| `Input` | Raw trusted mouse, keyboard, wheel, drag, and pointer path input. |
| `MotionProfile` | Python-visible motion policy passed to Browser RPC V5. |
| `RuntimeActionEffect` | Lightweight result returned by trusted actions. |
| `OutcomeContract` / `OutcomeVerdict` | Production transition contracts for state machines. |
| `TraceController` | Lightweight native trace control through `page.trace`. |
| `TraceRecorder` | AI/debug evidence directory writer. |
| `ProbeController` | Page inspection helpers through `page.probe`. |
| `TabController` | `page.tabs` multi-tab helpers. |
| `NetworkController` | `page.network` capture, waits, response body, and routing helpers. |
| `DownloadController` | `page.downloads` download capture and wait helpers. |
| `DialogController` | `page.dialogs` JavaScript alert/confirm/prompt policy. |
| `CookieController` | `page.cookies` browser cookie and storage-state helpers. |
| `ConsoleController` | `page.console` console capture polling. |

Retired pre-V5 public element objects, `Fingerprint`, account lookup launch,
direct browser launch, and old RPC fallback surfaces are intentionally absent.

## Launch API

```python
hw.launch(
    url=None,
    *,
    reuse_profile_id=None,
    name=None,
    group=None,
    tags=None,
    start_pages=None,
    proxy=None,
    client=None,
    base_url=None,
    headless=False,
    timeout_ms=30000,
    humanize=None,
    motion=None,
) -> Page
```

Reusable config:

```python
cfg = hw.LaunchConfig(
    name="shop",
    url="https://example.com",
    proxy="http://127.0.0.1:7890",
    motion=hw.MotionProfile.balanced(),
)

with hw.launch(config=cfg) as page:
    page.locator("body").wait()
```

Unsupported old arguments raise `TypeError`, including `account_id`,
`profile_id`, `fingerprint`, `chrome`, `user_data_dir`, `persona`, `seed`, and
`extra_args`.

## Page

`Page` is the main object returned by `hw.launch()`. It owns state, navigation,
controllers, trace, probes, and short one-off element shortcuts.

| API | Returns | Notes |
| --- | --- | --- |
| `page.url` | `str` | Current URL. |
| `page.title()` | `str` | Current document title. |
| `page.content()` | `str` | Current document HTML. |
| `page.goto(url, wait="load", timeout_ms=None)` | `Page` | Navigate and return the same page. |
| `page.back(timeout_ms=30000)` | `Page` | Browser history back. |
| `page.forward(timeout_ms=30000)` | `Page` | Browser history forward. |
| `page.reload(ignore_cache=False, timeout_ms=30000)` | `Page` | Reload current page. |
| `page.wait_for_url(url_or_predicate, timeout_ms=30000)` | `str` | Returns matched URL. |
| `page.screenshot(path=None, timeout_ms=None)` | `bytes` | Writes PNG when `path` is given. |
| `page.evaluate(expression, timeout_ms=None)` | `Any` | Evaluate a JavaScript expression in Helixwright's isolated world. Use for diagnostics and DOM readbacks, not page main-world globals. |
| `page.scroll_until(selector, max_rounds=40, step=None, container=None, into_view=True, timeout_ms=30000)` | `Locator` | Trusted-wheel discovery for lazy or virtualized targets. |
| `page.frames()` | `list[dict]` | Document frame/OOPIF inventory. |
| `page.targets()` | `list[dict]` | Browser tab/WebContents inventory. |
| `page.last_action_receipt()` | `dict` | Last Browser RPC action receipt. |
| `page.info()` | `dict` | Session/profile/fingerprint/proxy snapshot. |
| `page.close()` | `None` | Close the automation session. |

One-off shortcuts delegate to `Locator`:

```python
page.click("role=button@@name:Sign in")
page.fill("label=Email", "user@example.com")
page.type("label=Password", "secret")
page.press("label=Password", "Enter")
```

Prefer `Locator` variables for anything reused or important.

`page.evaluate()` runs in Helixwright's isolated automation world. It can read
DOM state such as `document.title`, attributes, element values, and arrays built
from DOM queries. It intentionally does not run in the page main world, so
globals created by site scripts, such as `window.someFlag`, are not a reliable
production success signal. Use DOM state, `Locator` reads, `page.probe`, action
receipts, or explicit visible destination elements instead.

## Locators

Use `page.locator(selector)` for CSS and Helix structured selectors:

```python
email = page.locator("label=Email")
email.fill("user@example.com")
print(email.input_value())

page.locator("role=button@@name:Sign in").click()
```

Structured selector factories are available when you want typed code instead of
string formatting:

```python
page.get_by_role("button", name="Sign in").click()
page.get_by_text("Continue").click()
page.get_by_label("Email").fill("user@example.com")
page.get_by_placeholder("Search").type("invoice")
page.get_by_test_id("submit").click()

row = page.locator("tr[data-user='42']")
row.get_by_role("button", name="Edit").click()
```

Frame-flat selectors supported by the current core include:

- Plain CSS.
- Interactive `text=...` / `text:"..."`.
- `role=button@@name:...` and other role+name selectors.
- `label=...`.
- `placeholder=...`, `aria-label=...`, `aria=...`, `title=...`, `alt=...`.
- `testid=...`, matching `data-testid`, `data-test`, `data-qa`, and `data-cy`.
- Simple positive Drission text filters when they compile to one CSS scope plus
  one text filter.

`targets()` is not a frame list. Use `frames()` when diagnosing iframe or OOPIF
visibility.

Inside `with page.frame(target) as frame:`, locators stay scoped to that frame
for consecutive actions. `frame.locator(...).click()` uses the same V5 trusted
action and bounded scroll discovery path, but it does not reset the explicit
frame scope after the first action.

## Locator Actions

Default actions are trusted Browser RPC V5 actions. Eligible locators use the
frame-flat element path, so actions can converge on the owning root document,
iframe/OOPIF, shadow tree, or overflow container without changing public frame
context or teleporting the pointer. Existing offscreen targets use target-owned
scroll geometry; lazy targets use bounded trusted-wheel discovery. Every wheel
round is checked against actual document/container movement before another plan
is chosen. Use `page.scroll_until(...)` only when a script intentionally scopes
discovery to a known virtualized list or custom scroll container.

| API | Returns | Notes |
| --- | --- | --- |
| `locator.click(timeout_ms=None, verify=None)` | `RuntimeActionEffect` | Trusted click. |
| `locator.double_click(timeout_ms=None)` | `RuntimeActionEffect` | Trusted double click. |
| `locator.hover(timeout_ms=None)` | `RuntimeActionEffect` | Trusted hover. |
| `locator.fill(text, timeout_ms=None, verify=True)` | `RuntimeActionEffect` | Clear and set form value; verifies by default. |
| `locator.type(text, timeout_ms=None, verify=True)` | `RuntimeActionEffect` | Trusted key input; verifies by default. |
| `locator.press(key, timeout_ms=None)` | `RuntimeActionEffect` | Focus target and press key. |
| `locator.select(value=None, label=None, index=None, timeout_ms=None)` | `RuntimeActionEffect` | Select exactly one axis; selected values are in `effect.return_value`. |
| `locator.drag_to(target, timeout_ms=None)` | `RuntimeActionEffect` | Drag to another `Locator`. |
| `locator.upload(files, verify=True, timeout_ms=None)` | `RuntimeActionEffect` | Attach file path(s) to file input. |
| `locator.wait(state="visible", timeout_ms=None)` | `Locator` | Wait for state. |
| `locator.scroll_into_view(timeout_ms=None)` | `Locator` | Fully exposes a target that can fit in its viewport. |
| `locator.resolve(timeout_ms=None)` | `dict` | V5 resolve evidence. |
| `locator.explain(timeout_ms=None)` | `dict` | Actionability and hit-test evidence. |
| `locator.input_value(timeout_ms=None)` | `Any` | Form value readback. |
| `locator.text()` | `str` | Element text. |
| `locator.attr(name)` | `Any` | Attribute value. |
| `locator.rect()` | `Any` | Bounding box. |
| `locator.screenshot(path=None, timeout_ms=None)` | `bytes` | Element PNG. |

Native HTML `<select>` uses Browser RPC V5 `element.select_native` when the
core advertises it. The native option popup is browser UI, not a DOM locator.

Every trusted action effect exposes `ok`, `action_id`, `selector`,
`return_value`, `has_progress`, and `no_effect`. State machines consume the
handler-returned effect, or `page.last_action_effect` when a handler omits an
explicit return.

Inside `with page.frame(target) as frame:`, `frame.click(...)`,
`frame.fill(...)`, and `frame.type(...)` return `RuntimeActionEffect` too.
`frame.last_action_effect` exposes the owning page's latest effect, so
frame-scoped state-machine handlers use the same return contract as root-page
handlers.

## Raw Input

Use `page.input` only when you intentionally need raw coordinates or a custom
trajectory. Normal element work belongs on `Locator`.

```python
page.input.click(100, 200)
page.input.wheel(600)
page.input.key("Enter")
page.input.type("already focused target")

page.input.pointer_path([
    {"x": 10, "y": 20, "dt": 0, "kind": "move"},
    {"x": 12, "y": 22, "dt": 16, "kind": "down", "buttons": 1},
    {"x": 40, "y": 55, "dt": 80, "kind": "up", "buttons": 0},
])
```

`pointer_path(points)` is one atomic Browser RPC V5 call. It is not emulated by
many SDK round trips.

## MotionProfile

`humanize` controls action-to-action timing. `MotionProfile` controls the
compact Python-visible motion policy passed to Browser RPC V5.

```python
motion = hw.MotionProfile.fast()

with hw.launch("https://example.com", motion=motion, humanize="default") as page:
    page.get_by_role("button", name="Submit").click()
```

Motion policy applies to:

- `Locator.click()` and other Browser RPC V5 element actions when the core uses
  SDK motion policy.
- `page.input.move()`, `page.input.click()`, `page.input.drag()`, and
  `page.scroll()`.
- `Page.set_motion(...)`, which changes the active page default.

`page.input.pointer_path(points)` is the exception: it is fully caller-defined
raw trajectory input.

## State Machines And Outcome Contracts

Use `StateMachine` for multi-page or branchy flows. Handlers should return the
last action effect, and `OutcomeContract` describes what counts as success,
branch, progress, failure, or no-effect.

```python
import helixwright as hw

def submit_login(ctx):
    page = ctx.scope
    page.locator("#email").fill(ctx.data["email"])
    page.locator("#password").fill(ctx.data["password"])
    return page.locator("role=button@@name:Sign in").click()

machine = hw.StateMachine([
    hw.State(
        "login",
        match=hw.Signature(url_substr="/login", require_selectors=["#email", "#password"]),
        handler=submit_login,
        expect=hw.OutcomeContract(
            success_states=["dashboard"],
            branch_states=["otp", "captcha"],
            progress=[hw.DomChanged(), hw.Network(url_contains="/login", method="POST", status=200)],
            failure=[hw.Appeared("text=/invalid password/i")],
            no_effect="retry_once_then_report",
        ),
    ),
    hw.State("dashboard", match=hw.Signature(url_substr="/dashboard"), terminal=True),
])

machine.run(page, until="dashboard", failure_dir="G:/HelixArtifacts/results/login-flow")
```

`expect="dashboard"` still works as a short form for simple flows, but new
production code should use `OutcomeContract` whenever a site can show OTP,
challenge, validation errors, loading states, or same-page progress.

When an outcome contract fails, exhausts `no_effect`, or times out,
`machine.run(..., failure_dir=...)` writes a failure bundle containing
`manifest.json`, `state_context.json`, `classification.json`,
`outcome_verdict.json`, `action_effect.json`, `transitions.json`, and
best-effort `network_recent.json`, `console_recent.json`,
`locator_explain.json`, `frames.json`, and `screenshot.png`.

## Page Controllers

Domain controllers keep non-element capabilities grouped instead of adding many
unrelated top-level `Page` methods.

### Tabs

```python
print(page.tabs.list())          # -> list[dict]
index = page.tabs.new("https://example.com")
page.tabs.switch(index)
page.tabs.close(index)

popup = page.tabs.expect(
    lambda: page.get_by_role("link", name="Open").click(),
    timeout_ms=30000,
)                                  # -> dict
```

### Network

```python
page.network.listen()
page.get_by_role("button", name="Load").click()

response = page.network.wait_for_response("/api/items", timeout_ms=30000)
print(response.status, response.url)

with page.network.expect_response("/api/save", timeout_ms=30000) as response_info:
    page.get_by_role("button", name="Save").click()
print(response_info.value.json())

page.network.block("*.png", "*.gif")
page.network.clear_routes()
```

Body helpers read captured response assets:

```python
text = page.network.body("https://example.com/api/items")
raw = page.network.bytes("https://example.com/file.bin")
headers = page.network.headers("https://example.com/api/items")
data = page.network.json("https://example.com/api/items")
```

### Downloads

```python
download = page.downloads.expect(
    lambda: page.get_by_role("link", name="Export").click(),
    timeout_ms=30000,
)                                  # -> dict
print(download["path"])
```

### Dialogs

```python
page.dialogs.accept()
page.dialogs.dismiss()
page.dialogs.accept(prompt_text="hello")
page.dialogs.off()
```

### Cookies And Storage

```python
cookies = page.cookies.list()
page.cookies.set("sid", "value", url="https://example.com")
state = page.cookies.storage_state("state.json")
deleted = page.cookies.clear()
```

### Console

```python
page.console.listen()
page.evaluate("console.log('ready')")
messages = page.console.messages()
```

## Trace And AI Authoring

Trace is a debug and AI-authoring surface. It is separate from normal runtime
actions.

```python
with hw.launch("https://example.com") as page:
    with page.trace.start_session("trace-example", mode="authoring") as trace:
        page.get_by_role("button", name="Submit").click()
        page.probe.forms(include_values=True)
        page.probe.state({"done": lambda p: "/done" in p.url})
    trace.report()
```

For deeper failure analysis:

```python
with page.trace.start_session(
    "trace-debug",
    mode="failure_debug",
    network_bodies=True,
) as trace:
    page.probe.cookies()
    page.probe.storage()
    page.probe.listener_hints("button[type=submit]")
```

CLI capture for an already-running automation session:

```powershell
python -m helixwright trace --session auto_123 --duration 15 --output trace-example
python -m helixwright trace --session auto_123 --mode failure_debug --network-bodies --output trace-debug
```

## Client Managers

```python
client = hw.Client()
print(client.health())
print(client.session())

profile = client.profiles.create(name="demo", proxy="http://127.0.0.1:7890")
profile.update(name="renamed")
profile.clone(count=2)
profile.sync_up()
profile.sync_down()

client.proxy.check("http://127.0.0.1:7890")
client.cores.list()
client.cores.ensure("chromium", "149.0.7827.156")
client.browser.active()
client.browser.start(profile.id)
client.browser.stop(profile.id)
client.browser.stop_all()
client.automation.list()
client.automation.stop("auto_123")
```

The SDK no longer exposes `client.fingerprint` or `client.automation.start()`.
Use `hw.launch()` / `client.automation.launch()` so profile creation and session
start remain one server-owned operation.

## Error Types

| Error | Meaning |
| --- | --- |
| `LocalApiUnavailable` | Desktop Local API is unreachable. |
| `DesktopNotLoggedIn` | Desktop is reachable but not logged in. |
| `LocalApiError` | Local API returned a business error. |
| `ProfileNotFound` | The requested profile id does not exist. |
| `AutomationEndpointUnavailable` | Local API/core did not return a usable V5 RPC endpoint. |
| `AutomationSessionNotFound` | The requested automation session does not exist. |
| `RpcError` | Browser RPC returned a structured error. |
| `TransportError` | Browser RPC transport failed, usually because the browser exited. |
| `WaitTimeoutError` | A page wait condition timed out. |

## Examples

```powershell
cd "G:\Helix Browser\repos\helixwright"
python examples\99_offline_mock_demo.py
python examples\00_helixwright_quickstart.py
python examples\01_client_managers.py
python examples\02_launch_config_and_actions.py
python examples\03_native_trace_state_machine.py
python examples\04_public_facade_controllers.py
```
