mirror of
https://github.com/9prodhi/camoufox-rs.git
synced 2026-11-29 08:00:44 +00:00
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>