Commit Graph
31 Commits
Author SHA1 Message Date
9prodhiandClaude Opus 5.5 96c97a353b docs(rustdoc): fix private intra-doc links; compile doc examples as doctests
RUSTDOCFLAGS="-D warnings" cargo doc now builds cleanly: links to
private items became code spans and the Browser::connect example in
src/api/mod.rs uses the current signature. src/lib.rs adds
#[cfg(doctest)] items that include README.md and the docs/ guides, so
every Rust example in the documentation is compiled by cargo test; an
invented method or wrong return type now fails the build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQU84X3UzxGaxqrADxbkoE
2026-11-21 17:03:19 -06:00
9prodhiandClaude Opus 5.5 fbb7f82cc7 feat(cli): --frame iframe scoping and >>> shadow-DOM piercing
Selectors used to run only against the top document, so widgets inside
iframes (captcha checkboxes, embedded forms) and open shadow roots were
unreachable except by raw coordinates (QA finding #10).

- `--frame <iframe-selector>` (repeatable for nesting, same- and
  cross-origin) on text/html/links/click/fill/type/press/hover/select/wait/
  evaluate. Each hop resolves the iframe in its parent, maps it to its child
  frame with Page.describeNode, and evaluates in that frame's tracked
  execution context. Remote handles are released with their context id.
- ` >>> ` pierces open shadow roots in any selector. A CSS-aware tokenizer
  (quotes, brackets, parentheses, escapes, comments, CSS-only whitespace)
  leaves plain selectors byte-identical, searches all hosts depth-first, and
  invalid CSS in any segment fails fast and is named. Closed roots cannot be
  pierced from the isolated world and say so.
- Pointer commands scroll the chain into view first, then measure, so
  clicks land below the fold and in padded, bordered and scaled iframes.
- One command deadline covers every hop and protocol call; `wait`
  re-resolves the chain each poll, follows replaced iframes, fails fast on
  permanent errors (open dialog, closed page, bad selector) and always
  reports the canonical timeout message.
- type/press --frame type only into the field currently focused inside the
  frame and otherwise fail with an actionable error; no focus memory or
  page instrumentation is installed.
- ProtocolErrorKind is now #[non_exhaustive] (pre-1.0 breaking change,
  listed in CHANGELOG with the new variants and signature changes).

Implemented by agy (gemini-3.8-flash-high) and pi (openai/gpt-6.1-sol,
five fix rounds); reviewed each round by GPT-6.1-sol, Fable 5.2 and Claude
with revert-proven tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQU84X3UzxGaxqrADxbkoE
2026-11-21 13:59:53 -06:00
9prodhiandClaude Opus 5.5 fd3b728800 feat(api): adopt site-opened tabs via a per-context page registry
Tabs a site opens itself (target=_blank, window.open) were attached by the
browser but never usable: pages existed only inside new_main_frame's
temporary listeners. Each BrowserContext now has a PageRegistry that tracks
every page target, its frames and their main-world execution contexts from
the moment Browser.attachedToTarget arrives. new_main_frame claims its own
target from the registry; targets with an openerId (verified on Camoufox for
both target=_blank and window.open) are popups. The CLI adopts popups as the
next pN on each command, shows `opener` in `tabs`, reports "page <id> was
closed" for detached tabs, and lists crashed tabs as crashed.

Design points hardened over four review rounds (GPT-6.1-sol + Fable 5.2,
each fix revert-proven):
- connection handlers hold only Weak refs; MainFrame/BrowserContext own the
  registry, which owns its root subscriptions (no Arc cycle, pages keep
  working after the context handle is dropped)
- the reader drops a detached session's handlers outside the connection
  lock; guards are never dropped and the connection never called while the
  registry lock is held
- one tracker per frame id with a stable main-frame tracker; contexts can
  arrive before frameAttached without being misfiled; the main frame id is
  resolved live and once per operation
- claim is atomic and refuses double ownership; claim fails fast when the
  connection closes; abandoned targets (failed newPage/claim window) are
  closed in the background instead of turning into phantom popups
- Connection::drop on the reader thread no longer waits on itself

Library behaviour changes are listed in CHANGELOG (Unreleased).

Implemented by agy (gemini-3.8-flash-high) and pi (openai/gpt-6.1-sol);
reviewed by GPT-6.1-sol, Fable 5.2 and Claude.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQU84X3UzxGaxqrADxbkoE
2026-11-21 09:25:14 -06:00
9prodhiandClaude Opus 5.5 8826f73c14 Merge wip/t3: JavaScript dialog handling (T3)
click/click-selector responses now carry both T3's `dialog` and T4's
`downloads` fields. The launch flags (--downloads-dir, --bypass-csp,
--dialogs) share LaunchOptions/DaemonRequest::Launch, all #[serde(default)].
navigate also restores the pre-navigation context when a dialog interrupts
the navigation (DialogOpened), since the old document is still live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQU84X3UzxGaxqrADxbkoE
2026-11-21 06:13:33 -06:00
9prodhiandClaude Opus 5.5 6d24e3ca53 feat: handle JavaScript dialogs instead of freezing the page
A JS alert/confirm/prompt used to block the page silently: every command
timed out and nothing tracked the dialog. Each MainFrame now has a
DialogTracker listening for Page.dialogOpened/dialogClosed.

Default policy is manual: when a dialog opens, in-flight requests on that
page session fail at once with ProtocolErrorKind::DialogOpened (message
names the dialog), new page commands fail fast with a hint to run
`camoufox dialog <inst> <page> accept|dismiss [--text T]`, and `tabs` shows
the pending dialog. click/press that open a dialog return successfully with
the dialog info. `launch --dialogs accept|dismiss` auto-handles dialogs; the
Page.handleDialog call runs on a spawned thread, never the reader thread.

Measured: a pending `wait` fails 0.79 s after an alert opens (was: full
timeout).

Implemented by pi (openai/gpt-6.1-terra); reviewed by Claude.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQU84X3UzxGaxqrADxbkoE
2026-11-21 06:09:48 -06:00
9prodhiandClaude Opus 5.5 2bf37ab627 Merge wip/t2: page survives downloads, CSP-aware main world (T2)
Launch flags from T2 (--bypass-csp) and T4 (--downloads-dir) are both kept;
both IPC fields are #[serde(default)] (the T0 compat test caught a dropped
attribute). Test LaunchOptions literals now end in ..Default::default() so
later flags don't break them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQU84X3UzxGaxqrADxbkoE
2026-11-21 06:09:36 -06:00
9prodhiandClaude Opus 5.5 c4d373005a fix(api): page survives downloads; main-world works under CSP
#5: navigate used to drop the page's execution context on the ack (and the
CLI dropped it even earlier), so a navigation that became a download left
the page unusable until timeout. A new ExecContextTracker records live
main-world contexts; navigate remembers the current one and restores it when
the navigation produces no new document (download, same-document nav,
timeout, protocol error). Contexts created during the navigation are kept.

#6: the main-world bridge no longer declares page-scope bindings (a page
global named `val` broke it) and no longer needs eval for plain expressions:
the isolated world pre-parses the input and picks the direct or eval form.
It borrows an existing script nonce, which makes --main-world work on
nonce-CSP pages without any flag (verified on Camoufox 158). When the page
CSP still blocks it, the error says to relaunch with --bypass-csp, a new
opt-in launch flag (off by default: pages can detect it).

Implemented by agy (gemini-3.8-flash-high); reviewed by Claude.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQU84X3UzxGaxqrADxbkoE
2026-11-21 06:05:53 -06:00
9prodhiandClaude Opus 5.5 5bd5eb42dc feat(cli): download log, downloads [--wait], launch --downloads-dir
Clicking a download link used to do nothing visible, and the CLI had no way
to save a download. Each instance now keeps a bounded log (100 entries) of
Browser.downloadCreated/downloadFinished for its context, attributed to the
page by pageTargetId. `camoufox downloads <inst> [--wait SECS]` lists it;
--wait blocks on a condvar outside the instance mutex until a download
starts or finishes. `launch --downloads-dir DIR` (absolute, created 0700,
probed for writability) switches the context to saveToDisk; files land at
DIR/<uuid> and the path is never derived from the server's suggested
filename. Without the flag downloads stay cancelled but are still logged.
click/click-selector add a best-effort `downloads` field.

Implemented by agy (gemini-3.8-flash-high); reviewed by Claude.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQU84X3UzxGaxqrADxbkoE
2026-11-21 05:57:35 -06:00
9prodhiandClaude Opus 5.5 19b88c7b1a Merge wip/c1: redirect status fix + main_frame cleanup (C1b)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:43:41 -06:00
9prodhiandClaude Opus 5.5 1f406ae002 fix(api): report the final status after redirects reliably
navigate_reports_final_status_after_redirect failed ~50% of runs on main.
Root cause (from captured event traces): a local 302 -> 200 round trip
takes ~490-520ms on Camoufox 158, straddling the fixed 500ms status cap,
so navigate often returned the intermediate 302.

- While a redirect hop is in flight, wait up to 2s (bounded by the
  deadline) for the final status; ordinary navigations keep the 500ms cap.
  An unresolved chain now reports None ("final status not captured")
  instead of the stale 3xx.
- Harden ordering: buffer responses that arrive before their
  requestWillBeSent, never let a late 3xx overwrite a final status, and
  follow redirectedFrom before the navigationId gate.
- Content-Disposition check parses the disposition type instead of
  substring-matching "attachment" (no spurious 2s waits on inline files).
- Use ProtocolError constructors throughout main_frame.rs.

Implemented via Antigravity (gemini-3.8-flash-high); reviewed;
redirect integration test 10/10 on a real browser (was 3/6 on main).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:43:41 -06:00
9prodhiandClaude Opus 5.5 7fefbe09af refactor(protocol): use ProtocolError constructors; trace protocol traffic
- Replace hand-built ProtocolError literals in api/browser.rs and
  api/context.rs with the new constructors (kinds/messages unchanged).
  Three literals in client.rs that carry a serde source error are kept.
- Wire obs::ProtocolLogger into all three transport send sites and the
  reader thread: RUST_LOG=camoufox::protocol=trace shows SEND/RECV with
  bounded previews. Serialization only happens when trace is enabled, and
  never under the connection or writer lock.
- README Observability updated.

Implemented via pi (openai/gpt-6.1-sol); reviewed and gate-verified
(live trace checked: 41 lines for one navigate+evaluate).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:26:19 -06:00
9prodhiandClaude Opus 5.5 e92906b995 fix(api): detect navigations that become downloads on Camoufox 158
Camoufox 158 acks Page.navigate before Browser.downloadCreated arrives
(~15-20ms after the attachment response), so the pending-nav interception
in the reader never matched and navigate returned Ok(200) for downloads.

navigate now subscribes to Browser.downloadCreated (root session,
filtered on its frameId) before sending Page.navigate, and:
- returns NavigationBecameDownload as soon as a matching event arrives,
  including mid lifecycle wait (wait_for_lifecycle wakes on downloads);
- when the main-document response carries Content-Disposition:
  attachment, waits (max 2s, bounded by the deadline) for the download
  event instead of returning the 200 immediately.
Ordinary navigations keep the existing fast path. The reader's
pending-nav interception stays as the fallback for browsers that never
ack. All subscriptions are RAII-scoped.

Implemented via Antigravity (gemini-3.8-flash-high); reviewed,
gate-verified, real-browser attachment test passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:20:26 -06:00
9prodhiandClaude Opus 5.5 2f17137734 Merge wip/proto2: downloads, evaluate_main_world, codec cap (A2)
Resolve codec/errors.rs (A3 removed Incomplete, A2 added FrameTooLarge).
Make the main-world snippet builder private and have the CLI's js_literal
reuse api::main_frame::escape_js_json_literal (one JS-literal escaper).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:01:03 -06:00
9prodhiandClaude Opus 5.5 ce3f081592 fix(api): cancel downloads per context, add evaluate_main_world, bound evaluate
- Browser::new_context sets download behaviour "cancel" on each new
  context (the bootstrap call only covered the default context, so
  attachments were saved to ~/Downloads and opened in a new tab on
  Camoufox 158). Missing/empty browserContextId is now an error instead
  of silently targeting the default context.
- MainFrame::evaluate sends Runtime.evaluate with the caller's remaining
  deadline (was the 60s default) and reports timeouts as Timeout.
- Document that evaluate runs in an isolated world on Camoufox 158; add
  MainFrame::evaluate_main_world, which runs a sync expression in the
  page's main world via an injected <script> bridge (expression passed
  only as a JSON string literal, indirect eval, result via a one-shot
  dataset slot). Page code can observe it; CSP can block it.
- Codec rejects frames over 256 MiB (configurable) and recovers;
  decode avoids a per-frame copy.
- Gate the cli-dependent tests in main_frame.rs so plain `cargo test`
  compiles again.

Implemented via Antigravity (gemini-3.8-flash-high); reviewed and
gate-verified; evaluate_main_world proven against Camoufox 158.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:00:14 -06:00
9prodhiandClaude Opus 5.5 57260b85b2 fix(protocol): sound transport split, lock-free dispatch, no handler leaks
D2 connection core:
- Replace SplitTransport (UnsafeCell aliasing &mut PipeTransport across
  the reader and writer threads: UB) with Transport::into_split(); the
  writer sits behind a Mutex guarding both send and close, the reader is
  owned by the reader thread.
- Event handlers are Arc'd, snapshotted under the lock and invoked after
  releasing it inside catch_unwind: a panicking handler no longer poisons
  the connection, a re-entrant handler no longer deadlocks the reader.
- Undecodable frames (e.g. lone-surrogate JSON) are logged and skipped
  instead of closing the whole connection and dropping the batch.
- Reader exit always rejects pending requests and drops the event router
  outside the lock, so channel waiters observe Disconnected.
- Connection drop joins the reader with a bounded wait instead of hanging
  on a wedged browser.

D3 lifecycle:
- on_event_global returns a HandlerId; add off_event_global.
- new_main_frame's four listeners are RAII-guarded: attach/frame
  listeners are removed on return (any path), exec-context listeners are
  owned by MainFrame and removed on drop. No unbounded buffering after an
  attach timeout.
- Browser.detachedFromTarget drops the session, rejects its in-flight
  calls (Closed) and removes its handlers; Page.crashed marks the session
  crashed and rejects in-flight calls (Crashed). No more 60s hangs.

BREAKING: EventHandler is Arc<dyn Fn + Send + Sync> (was Box<dyn Fn + Send>).

Implemented via Antigravity (gemini-3.8-flash-high); reviewed,
gate-verified, real-browser suite unchanged from baseline (12/14; the two
known failures are fixed on other lanes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 06:42:43 -06:00
9prodhiandClaude Opus 4.8 aad0c54bfb feat(cli): add 20-command browsing surface; prep repo for public release
Grow the CLI from 12 primitives to a full browsing/scraping surface. Every new
command is a thin CLI/IPC wrapper over the existing `api` layer (no new protocol
plumbing), and `output.rs` is refactored into a pure, testable `render()`:

- Reading: text, html, links, data (og/jsonld/meta), url
- Navigation/waiting: wait, reload, back, forward
- Cookies/headers: cookie, header
- Interaction: click (selector or x,y trusted event), fill, type, press,
  hover, select, scroll
- Tabs: tabs, close-tab
- screenshot --selector / --clip, and a viewport-origin default clip

Public-release preparation and review hardening:

- Add MIT LICENSE and repository metadata to Cargo.toml
- Make the camoufox-browse plugin portable: discover the binary via
  $CAMOUFOX_BIN / PATH / ./target/release instead of hardcoded container paths
  (SKILL.md and hook.json)
- Sanitize internal client references from docs and code comments
- CHANGELOG: list the new commands under Added (not Changed)
- wait_for_selector fails fast on invalid selectors instead of burning the
  full timeout under the daemon lock
- Correct punctuation keyCodes in key_descriptor (`press .` no longer collides
  with Delete's keyCode)
- Add --timeout to the tabs command
- Document the daemon's serial-execution behavior in README
- Add integration tests: trusted click, reading, interaction, screenshot
  scroll-offset regression, and wait fail-fast

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-14 14:59:10 +00:00
9prodhiandClaude Sonnet 4.6 470752244a fix(api): follow redirect chain so navigate reports FINAL HTTP status (G4 review)
CRITICAL fix: on a redirect (301/302/307/308) the correlation locked
main_request_id on the first request and early-returned once a status was
captured, so it reported the redirect hop's status (e.g. 301) instead of the
final response (200/404). This broke the primary use case — Bombay HC
navigates nic.in → gov.in (301 → 200) and would have reported Some(301).

Fix:
- requestWillBeSent handler now CHAINS FORWARD: when an event's
  `redirectedFrom` equals the currently-tracked main_request_id, advance
  main_request_id to the new requestId. The document/frame/nav_id filters
  still gate the initial lock, and a redirectedFrom that does not match the
  tracked id is ignored, so a sub-resource cannot hijack the chain.
- responseReceived handler now ALLOWS OVERWRITE (removed the
  `if status.is_some() return` early-out) so the final hop's status wins.
- The post-navigate status drain now treats a 3xx as non-final and keeps
  polling (within the cap) until a non-3xx status arrives, so it cannot
  return the redirect hop's status before the chain advances.

For A(301) → B(200): rws A locks A; respReceived A sets 301; rws B
(redirectedFrom=A) advances main→B; respReceived B overwrites to 200.

Also lowered the status-wait cap to 80 ms under cfg(test) (production stays
500 ms) so the no-event unit tests don't pay the full budget.

Tests:
- Unit navigate_follows_redirect_chain_reports_final_status: 4-event
  redirect sequence asserts Some(200), not Some(301).
- Unit navigate_subresource_redirect_does_not_hijack_chain: a redirect whose
  redirectedFrom is an untracked request must not overwrite the main status.
- Unit navigate_redirect_does_not_leak_handlers: both Network handlers
  deregister to 0 after a redirect navigate.
- Integration (#[ignore]) navigate_reports_final_status_after_redirect:
  StatusServer gains a /redirect route (302 → /200); asserts final 200.
- Existing 404/200/None unit + integration tests stay green.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 09:01:48 +00:00
9prodhiandClaude Sonnet 4.6 64e5bd9f04 feat(cli): surface main-document HTTP status in navigate result (G4)
Additively add `status_code: Option<u16>` to `navigate` outcome.

Navigate returns `NavigateOutcome { nav_id, status_code }` instead of
`Option<String>`. The existing `navigation_id` semantics are unchanged;
`status_code` is a new additive field at both the API and IPC/JSON layers.

Navigate NEVER fails due to 4xx/5xx — the status is surfaced and the
call still returns Ok. If the status cannot be captured (e.g. the
Network events do not arrive within a 500 ms cap), `status_code` is
`None`.

Correlation approach: subscribe `Network.requestWillBeSent` and
`Network.responseReceived` on the page session BEFORE issuing
`Page.navigate`. The `requestWillBeSent` handler accepts the first
`document`-typed request (speculatively while nav_id is not yet known,
precisely after the navigate ack). The `responseReceived` handler
captures the HTTP status for the matching `requestId`. Both handlers
are RAII-guarded via `SubscriptionGuard` (mirrors the G3 pattern) so
they cannot leak on any exit path.

Risk gate result: `Network.responseReceived` events DO flow without
`Network.setRequestInterception`. Confirmed by event-logging probe
against the live camoufox 135 browser.

Protocol discovery: the live browser emits raw Firefox type names
(`"TYPE_DOCUMENT"`, `"TYPE_IMAGE"` etc.) in the `cause` field of
`requestWillBeSent` rather than the spec-mapped values (`"document"`,
`"image"`). The handler now accepts both forms. PROTOCOL.md updated.

TDD coverage:
- Unit: 404 status captured → Ok (not error); nav_id preserved.
- Unit: no responseReceived → status_code == None, navigate still Ok;
  both handlers deregistered (no leak).
- Unit: IPC serde includes status_code; legacy callers (no field) OK.
- Unit: print_response emits status code in human + JSON mode.
- Unit: 200 status captured.
- Integration (#[ignore]): StatusServer fixture serves /404 and /200;
  navigate to /404 → status_code==Some(404), Ok; /200 → Some(200).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 08:50:41 +00:00
9prodhiandClaude Sonnet 4.6 2450db9999 fix(api): deregister lifecycle handler + single-bound navigate timeout (G3 review)
Addresses two must-fix issues from G3 code review.

1. Handler leak. wait_for_lifecycle registered a Page.eventFired handler via
   Connection::on_event but EventRouter had no deregister API, so the closure
   stayed in the handler map forever (every --wait-until navigate leaked one).
   - EventRouter::on now returns a monotonic HandlerId; new EventRouter::off
     removes a specific (session_key, method, id) handler and prunes the empty
     key entry. Handlers are stored as (HandlerId, EventHandler) pairs.
   - Connection::on_event/on_event_any now return HandlerId; new
     Connection::off_event threads through to the router.
   - wait_for_lifecycle captures the id and uses an RAII SubscriptionGuard
     (Drop -> off_event) so the handler is removed on every exit path —
     success, timeout, error, or panic. Doc comment corrected (it previously
     and wrongly claimed "no handler leak").
   - Tests: events.rs gains on/off unit tests incl. a leak-regression guard
     (repeated on/off keeps count at 0); main_frame.rs gains
     wait_for_lifecycle_does_not_leak_handlers asserting the
     (session_key,"Page.eventFired") count returns to 0 after N successful AND
     N timed-out waits. Added a #[cfg(test)] Connection::event_handler_count_for
     accessor + EventRouter::handler_count_for.

2. Timeout double-counting. navigate passed the full timeout to BOTH
   send_navigate_with_timeout AND wait_for_lifecycle, so navigate+wait could
   take ~2x timeout. Now a single deadline is captured before the navigate RPC
   and the lifecycle wait gets deadline.saturating_duration_since(now), so the
   whole operation is bounded by one --timeout. Test:
   navigate_wait_until_combined_timeout_is_single_bounded.

These deregister APIs (on_event -> HandlerId, off_event, SubscriptionGuard)
are the foundation G4's Network.responseReceived wait will reuse.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 08:36:48 +00:00
9prodhiandClaude Sonnet 4.6 63f04c2f80 feat(cli): add navigate --wait-until=load|domcontentloaded (G3)
Adds an opt-in --wait-until <state> flag to the navigate command.
When set, after the Page.navigate RPC is acked, the caller blocks until
the matching Page.eventFired lifecycle event fires on the page session,
bounded by the existing --timeout. Absent flag: return after ack
(existing behavior unchanged).

Implementation:
- src/api/main_frame.rs: add Arc<Connection> to MainFrame (for on_event);
  add NavigateOptions::wait_until field; add reusable
  MainFrame::wait_for_lifecycle(name, timeout) helper (uses on_event +
  mpsc + recv_timeout on the page session key); add map_wait_until()
  validator that rejects unsupported values (including networkidle) with
  a clear error naming load/domcontentloaded before any network I/O;
  update navigate() to call the helper when wait_until is present.
- src/api/context.rs: pass Arc<Connection> to MainFrame::new.
- src/cli/commands.rs: add --wait-until flag to Navigate.
- src/cli/ipc.rs: add wait_until: Option<String> to DaemonRequest::Navigate
  (skip_serializing_if=None so legacy wire is unaffected).
- src/bin/camoufox.rs, src/cli/daemon.rs, src/cli/instance.rs: thread
  wait_until through the CLI→daemon→instance→API stack.
- tests/fixtures/mod.rs: add LifecycleServer (deferred /slow.js that
  inserts div#load-marker; load fires only after slow.js delivered).
- tests/integration.rs: add #[ignore] test asserting div#load-marker is
  present immediately after navigate(..., wait_until=load) returns.
- Unit tests: wait fires after event; timeout returns Timeout error with
  session still usable; unsupported values error before network I/O;
  IPC serde round-trip; absent wait_until path unchanged;
  domcontentloaded maps to DOMContentLoaded protocol name.

wait_for_lifecycle is the reusable helper Task 4 (G4 status) will also use
for Network.responseReceived event capture.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 08:25:33 +00:00
9prodhiandClaude Sonnet 4.6 d0a0b7b0af feat(cli): add cookies command exporting full jar incl. HttpOnly cookies
Implements G1 from the eCourts spike findings: adds `camoufox cookies
<instance_id>` which calls `Browser.getCookies` on the root session with
the instance's browserContextId. HttpOnly cookies are included (the Juggler
protocol returns them in the same array as ordinary cookies). `--json` emits
the full cookie objects; human mode prints `name=value` one per line plus a
count.

- src/api/context.rs: add `Serialize` to `Cookie` so it can be embedded in
  the IPC response JSON.
- src/cli/commands.rs: add `Cookies` variant to `Command`.
- src/cli/ipc.rs: add `DaemonRequest::Cookies`; add serde + response tests.
- src/bin/camoufox.rs: map `Command::Cookies` → `DaemonRequest::Cookies`.
- src/cli/daemon.rs: add dispatch arm calling `InstanceManager::cookies`.
- src/cli/instance.rs: add `InstanceManager::cookies()` which delegates to
  `BrowserContext::get_cookies()` (root-session RPC, already implemented).
- src/cli/output.rs: add cookies branch in `print_response`; add output tests.
- src/protocol/client.rs: add mock-transport unit tests for the
  `Browser.getCookies` round-trip (including HttpOnly flag preservation).
- tests/fixtures/mod.rs: add `CookieServer` that sets one plain + one HttpOnly
  cookie via `Set-Cookie` headers.
- tests/integration.rs: add `#[ignore]` integration test that navigates to
  `CookieServer`, calls `get_cookies()`, and asserts both cookies are present
  with the HttpOnly flag correct.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 08:08:00 +00:00
9prodhi 87d49138e0 Merge branch 'fix/download-detection'
Subscribe to Browser.downloadCreated at the root session, set download
behavior to cancel, and track pending Page.navigate requests by frame
so an attachment-flow navigation is resolved as
ProtocolError::NavigationBecameDownload instead of hanging.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

# Conflicts:
#	src/api/main_frame.rs
#	src/protocol/client.rs
#	src/protocol/errors.rs
#	src/protocol/pending.rs
#	tests/integration.rs
2026-05-27 14:39:42 +00:00
9prodhiandClaude Opus 4.7 fca569896a fix(api): detect navigations diverted into download flow
Previously a Page.navigate on a Content-Disposition: attachment
endpoint (e.g., sci.gov.in/sci-get-pdf) had no completion signal:
Juggler routed the response into a download flow, no DOM was created,
no execution context was created, and the pending Page.navigate
parked forever.

This commit:
- Adds ProtocolError::NavigationBecameDownload variant.
- Subscribes to Browser.downloadCreated at the root session and sets
  download behavior to "cancel" so detection happens without disk
  writes.
- Tracks pending navigations by (frame_id, request_id); on a download
  event for a known pending nav, resolves the pending slot with
  NavigationBecameDownload immediately rather than letting the caller
  hang.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 14:33:09 +00:00
9prodhiandClaude Opus 4.7 b1f5c43bc2 fix(protocol): plumb --timeout through navigate and bound Client::send
Previously the CLI --timeout flag was dropped at Instance::navigate
(parameter declared _timeout, never forwarded) and the protocol-layer
Client::send blocked on bare rx.recv() with no deadline. A
Content-Disposition: attachment navigation produced no response, the
pending slot leaked, and the daemon needed kill -9.

This commit:
- Adds ProtocolError::Timeout variant.
- Adds Client::send_with_timeout that uses rx.recv_timeout and frees
  the pending slot on timeout.
- Defaults Client::send to a 60s timeout (no call can hang forever).
- Adds a timeout parameter to MainFrame::navigate.
- Forwards Instance::navigate's CLI timeout through to the protocol
  layer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 14:31:28 +00:00
Claude aa5ed884d9 fix: close Layer-3 event-ordering race; refine test/doc scope
Addresses code-review findings:
- Move Runtime.executionContextCreated listener to before Browser.newPage
  with event-buffering until session_id and frame_id are known. Closes
  the theoretical race where Camoufox could emit the top-frame exec
  context before its frameAttached event.
- Honest doc on the regression test: it exercises Layer 3 end-to-end;
  Layers 1 and 2 are not race-triggered at new_main_frame() time.
- Document MainFrame::evaluate's destroyed-context handling: the Layer-3
  listener proactively clears the cached context on
  Runtime.executionContextDestroyed, with the retry loop here as a
  safety net for wire-level races.
- Invalidate the cached exec context inside MainFrame::navigate so
  evaluate-after-navigate cannot race against a still-alive pre-nav
  about:blank context (the destroyed event arrives shortly after, but
  not always before the next evaluate).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 10:48:18 +00:00
Claude 56be001f7c chore: clippy and doc cleanup after MainFrame refactor
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 10:13:31 +00:00
Claude 860548dedb refactor: delete Page; finalize MainFrame as the public page API 2026-05-11 10:08:08 +00:00
Claude c849f54ab3 feat(api): BrowserContext::new_main_frame with Layer 1/2/3 fixes (hybrid)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 09:53:28 +00:00
Claude 7a45867892 feat(api): add MainFrame type alongside Page
Introduces MainFrame in src/api/main_frame.rs — a page handle structurally
pinned to the top frame. evaluate() uses a cached Arc<Mutex<Option<String>>>
execution context with retry logic; navigate() always targets self.frame_id.
Both Page and MainFrame coexist; callers migrate in a subsequent task.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 09:49:55 +00:00
9prodhi 95f91af19f initial camoufox-rs release (API, protocol transport, CLI daemon, tests) 2026-03-03 00:08:40 +00:00
9prodhi 03c603c053 Initial commit 2026-02-28 23:08:10 +00:00