Skip to content

fix+feat(camoufox): ref_id regression fix and scroll parity#4

Merged
behr-davide merged 1 commit into
mainfrom
db/camoufox-scroll-and-ref-fix
Apr 21, 2026
Merged

fix+feat(camoufox): ref_id regression fix and scroll parity#4
behr-davide merged 1 commit into
mainfrom
db/camoufox-scroll-and-ref-fix

Conversation

@behr-davide

Copy link
Copy Markdown

Two changes bundled into 0.26.0-celeria-camoufox.2 because they both live in the sidecar and both matter for the end-to-end agent loop:

  1. FIX: NameError on every page.snapshot call My 0b8c105 "scoped snapshot + ref renumbering" fix renamed the loop- local ref_id -> dom_ref but missed the ref_cache.put(ref_id, ...) call at the end of the same loop. Every snapshot raised internal-error: name 'ref_id' is not defined in the .1 release, which took out the core snapshot->click->fill flow. Fix keeps the two-ref distinction explicit: query the DOM by the pre-filter data-__ab-ref value (dom_ref), cache under the renumbered agent-facing ref (entry["ref"]). A regression test (test_interactive_only_snapshot_then_click_by_ref) exercises the full interactive_only snapshot -> click-by-ref flow and would have caught the original NameError.

  2. FEAT: page.scroll + page.scrollIntoView parity with the Chrome path Previously returned not-yet-implemented: action 'Runtime.evaluate' is not yet supported on engine=camoufox because the sidecar had no scroll dispatch. The Rust side already normalises direction/amount -> dx/dy and passes {x, y, selector?} through; the sidecar now:

    • scrolls window when no selector is given
    • scrolls the element's own scroll container when selector is an @en ref or CSS selector
    • centres the element via scrollIntoView({block:'center', inline:'center'}) for page.scrollIntoView, mirroring the Chrome JS exactly
    • classifies Playwright errors into selector-not-found, ambiguous-selector, element-detached, ref-stale, timeout, action-failed (same taxonomy the click/fill paths use)

    Rust-side Camoufox arms added to handle_scroll and
    handle_scrollintoview in actions.rs. The two handlers now dispatch
    on mgr.backend.is_camoufox() and forward to
    mgr.camoufox_client().call("page.scroll"|"page.scrollIntoView"), so
    the sidecar protocol stays high-level rather than carrying CDP
    method strings.

Still deferred to v2: screenshot --annotate. Ref-annotated screenshots need CDP DOM-box extraction; porting it cleanly means either computing bounding boxes via Playwright and compositing server-side or injecting an overlay via page.evaluate. Out of scope for this patch; the existing "not-yet-supported" error message already flags it as a v2 item.

Files:

  • packages/camoufox-sidecar/camoufox_sidecar/snapshot.py - ref_id fix
  • packages/camoufox-sidecar/camoufox_sidecar/session.py - scroll + scroll_into_view methods
  • packages/camoufox-sidecar/camoufox_sidecar/main.py - register page.scroll and page.scrollIntoView handlers
  • packages/camoufox-sidecar/tests/test_commands.py - regression test for the ref_id bug + 6 tests covering the scroll surface
  • cli/src/native/actions.rs - Camoufox early-returns in handle_scroll and handle_scrollintoview
  • package.json + sync-version - bump to 0.26.0-celeria-camoufox.2
  • CHANGELOG.md - new release block with Bug Fixes + New Features; previous .1 block demoted to markers

Two changes bundled into 0.26.0-celeria-camoufox.2 because they both
live in the sidecar and both matter for the end-to-end agent loop:

1. FIX: NameError on every page.snapshot call
   My 0b8c105 "scoped snapshot + ref renumbering" fix renamed the loop-
   local ref_id -> dom_ref but missed the ref_cache.put(ref_id, ...)
   call at the end of the same loop. Every snapshot raised
   `internal-error: name 'ref_id' is not defined` in the .1 release,
   which took out the core snapshot->click->fill flow.
   Fix keeps the two-ref distinction explicit: query the DOM by the
   pre-filter data-__ab-ref value (dom_ref), cache under the renumbered
   agent-facing ref (entry["ref"]). A regression test
   (test_interactive_only_snapshot_then_click_by_ref) exercises the
   full interactive_only snapshot -> click-by-ref flow and would have
   caught the original NameError.

2. FEAT: page.scroll + page.scrollIntoView parity with the Chrome path
   Previously returned `not-yet-implemented: action 'Runtime.evaluate'
   is not yet supported on engine=camoufox` because the sidecar had no
   scroll dispatch. The Rust side already normalises
   direction/amount -> dx/dy and passes {x, y, selector?} through; the
   sidecar now:
   - scrolls window when no selector is given
   - scrolls the element's own scroll container when selector is an
     @en ref or CSS selector
   - centres the element via scrollIntoView({block:'center',
     inline:'center'}) for page.scrollIntoView, mirroring the Chrome
     JS exactly
   - classifies Playwright errors into selector-not-found,
     ambiguous-selector, element-detached, ref-stale, timeout,
     action-failed (same taxonomy the click/fill paths use)

   Rust-side Camoufox arms added to handle_scroll and
   handle_scrollintoview in actions.rs. The two handlers now dispatch
   on mgr.backend.is_camoufox() and forward to
   mgr.camoufox_client().call("page.scroll"|"page.scrollIntoView"), so
   the sidecar protocol stays high-level rather than carrying CDP
   method strings.

Still deferred to v2: screenshot --annotate. Ref-annotated screenshots
need CDP DOM-box extraction; porting it cleanly means either computing
bounding boxes via Playwright and compositing server-side or injecting
an overlay via page.evaluate. Out of scope for this patch; the
existing "not-yet-supported" error message already flags it as a v2
item.

Files:
- packages/camoufox-sidecar/camoufox_sidecar/snapshot.py - ref_id fix
- packages/camoufox-sidecar/camoufox_sidecar/session.py  - scroll +
  scroll_into_view methods
- packages/camoufox-sidecar/camoufox_sidecar/__main__.py - register
  page.scroll and page.scrollIntoView handlers
- packages/camoufox-sidecar/tests/test_commands.py - regression test
  for the ref_id bug + 6 tests covering the scroll surface
- cli/src/native/actions.rs - Camoufox early-returns in handle_scroll
  and handle_scrollintoview
- package.json + sync-version - bump to 0.26.0-celeria-camoufox.2
- CHANGELOG.md - new release block with Bug Fixes + New Features;
  previous .1 block demoted to <!-- old-release:* --> markers
@behr-davide behr-davide merged commit 9d1295b into main Apr 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant