Skip to content

feat(ui): sync gateway browser viewport to the dock panel size - #123104

Merged
steipete merged 5 commits into
mainfrom
steipete/sidebar-browser-responsive-28dd91
Aug 13, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/sidebar-browser-responsive-28dd91

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The Control UI's dockable browser panel renders the gateway browser as screenshots taken at whatever viewport the agent last used. The panel never told the remote browser how big the dock actually is, so the snapshot rendered at a mismatched size — scaled-down desktop pages in a narrow right dock, dead space, or overflow scrolling — and resizing the dock only rescaled the stale image.

Why This Change Was Made

The gateway browser plugin already supports viewport resizing end-to-end (POST /act {kind:"resize"} → Playwright setViewportSize, capped at 8192px); the Control UI just never called it. This change closes that gap at the panel boundary:

  • browser-client.ts gains a thin resizeBrowserViewport wrapper over the existing /act resize route.
  • BrowserPanelController syncs the remote viewport to the panel's observed content box: debounced ~300 ms behind a ResizeObserver on .bp-viewport, clamped to [100, 8192], skipped when metrics already match within 1px, with a per-target last-requested guard so a page that cannot honor an exact size is never re-asked until the panel size or tab changes (no request loops).
  • A successful capture whose metrics disagree with the observed panel size (>1px) re-triggers the same debounced sync — covering panel open, tab switch, and navigation to a tab an agent resized.
  • browser-panel.ts owns the transient observer lifecycle (the .bp-viewport element only exists while the dock is open/available).

User Impact

The remote page now follows the dock: opening the panel, dragging the resizer, or switching tabs resizes the remote browser viewport to the panel's available space, so the snapshot fills the dock edge-to-edge at 1:1 CSS scale instead of rendering at an arbitrary stale size. Docs updated (docs/web/control-ui.md).

Evidence

  • Focused tests: node scripts/run-vitest.mjs ui/src/components/browser → 9 files, 80 tests passed (4 new viewport-sync scenarios: debounce+clamp+refresh, loop guard/no-op on match, mismatched-metrics sync without looping on an inexact remote, tab-switch sync).
  • Autoreview (Codex gpt-5.6-sol, high): clean, no accepted/actionable findings.
  • Live proof on an isolated dev gateway (--allow-unconfigured, own OPENCLAW_STATE_DIR, port 19231, real managed Chrome) driven by Playwright against the built dist/control-ui:
    • Before (pre-fix bundle): panel viewport 560×822 → remote shot stays 1464×2000; widening the dock to 860×822 just rescales the stale shot to 860×1175, overflowing the panel.
    • After (fixed bundle): panel 560×822 → remote resized to 560×822 (shot 1120×1644 @2x DPR), rendered exactly 560×822; dragging to 860×822 re-syncs the remote to 860×822 (shot 1720×1644), rendered exactly 860×822. The page reflows responsively (ORF.at switches to its narrow layout and shows its consent dialog fresh — real page behavior at the new width).
Before (dock widened: stale 1464×2000 shot, arbitrary scale + dead space) After (dock widened: remote follows to 860×822, fills exactly)
before after

After, initial open at 560×822 (page reflowed to the dock's width):

after-initial

Resize demo video (open panel → navigate → drag dock wider → remote viewport re-syncs and recaptures):

after-resize-demo.mp4

Production LOC: +110 (new capability at the panel boundary: client wrapper 16, controller sync 58, pending-input timer 15, observer lifecycle 21); tests +194.

@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 13, 2026 09:31
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui size: M maintainer Maintainer-authored PR labels Aug 13, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 13, 2026
@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 13, 2026, 6:16 AM ET / 10:16 UTC.

ClawSweeper review

What this changes

This PR makes the Control UI resize the Gateway-controlled browser viewport to match its dock panel.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: the feature is still absent from current main, but two P2 lifecycle bugs can either resize a hidden remote browser or skip a needed re-sync after returning to a tab.

Priority: P2
Reviewed head: 97ce2b1cbbc2d1e8a632b4091badaed49a162aed

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The stated live proof and focused coverage are strong, but two concrete lifecycle defects must be repaired before this is merge-ready.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This maintainer-authored PR is exempt from the external contributor proof gate; its body nonetheless records an isolated real Gateway and Chrome before/after run.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external contributor proof gate; its body nonetheless records an isolated real Gateway and Chrome before/after run.
Evidence reviewed 7 items Current main lacks this behavior: Current main captures screenshots and metrics but does not observe the dock or send a resize action; the panel only updates dock reservation and overlays.
Existing browser contract: The browser route accepts positive dimensions capped at 8192, and its Playwright executor applies them with setViewportSize.
Hidden-panel resize: The new debounced sync checks only for an available client before starting the resize request; liveness is checked only after the request resolves. Closing the panel does not clear this timer.
Findings 2 actionable findings [P2] Fence queued resizes after the dock closes
[P2] Reset the resize guard when the active document changes
Security None None.

How this fits together

The Control UI browser dock displays screenshots from a browser hosted by the Gateway. Dock dimensions travel through the Gateway browser action route to resize the remote page, then a fresh screenshot returns to the panel.

flowchart LR
  A[Browser dock] --> B[Panel size observer]
  B --> C[Viewport sync controller]
  C --> D[Gateway browser request]
  D --> E[Browser action validation]
  E --> F[Remote page viewport]
  F --> G[Screenshot capture]
  G --> A
Loading

Before merge

  • Fence queued resizes after the dock closes (P2) - A resize scheduled by the observer survives an ordinary dock close: syncViewport only checks client availability, and runAction sends /act before it evaluates isLive. Closing the dock neither invalidates the controller nor clears this timer, so closing within the 300 ms debounce silently resizes the remote browser. Check liveness or cancel this pending work before dispatch, and cover close-before-debounce.
  • Reset the resize guard when the active document changes (P2) - The guard retains A's last requested size after switching away. If B already matches the panel, it does not replace that guard; an agent can then resize A, and returning to A observes the mismatch but suppresses the required request because A/W/H still matches the stale guard. Clear or generation-key the guard on tab/document transitions and test the A → B → A sequence.
  • Resolve merge risk (P1) - Merging as-is can silently resize an agent-controlled browser after its dock closes and can leave a revisited tab at an obsolete viewport size.

Findings

  • [P2] Fence queued resizes after the dock closes — ui/src/components/browser/browser-panel-controller.ts:291-322
  • [P2] Reset the resize guard when the active document changes — ui/src/components/browser/browser-panel-controller.ts:313-319
Agent review details

Security

None.

PR surface

Source +237, Tests +182, Docs 0. Total +419 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 6 440 203 +237
Tests 2 182 0 +182
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 623 204 +419

Review metrics

Metric Value Why it matters
Production versus test delta production +110 functional lines (203-line input extraction discounted); tests +182, test support +14 The feature adds a new dock-to-browser synchronization path; the production growth is capability-driven, but its lifecycle states need the listed regressions before merge.

Merge-risk options

Maintainer options:

  1. Repair viewport lifecycle fencing (recommended)
    Prevent queued resize actions after close and invalidate the per-target request guard when the active tab or document changes, then add the two focused regressions.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Add regressions for close-before-debounce and returning to a previously resized tab after its remote viewport changes.

Technical review

Best possible solution:

Fence delayed resize work by panel liveness and reset the request guard at tab or document transitions, with focused regressions for both sequences.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: close the dock after a resize callback schedules but before its 300 ms delay, or return to a previously requested tab after its remote viewport changes.

Is this the best way to solve the issue?

No: observing the panel is the right owner boundary, but the delayed action lacks a liveness fence and its guard survives the transitions it must re-evaluate.

Full review comments:

  • [P2] Fence queued resizes after the dock closes — ui/src/components/browser/browser-panel-controller.ts:291-322
    A resize scheduled by the observer survives an ordinary dock close: syncViewport only checks client availability, and runAction sends /act before it evaluates isLive. Closing the dock neither invalidates the controller nor clears this timer, so closing within the 300 ms debounce silently resizes the remote browser. Check liveness or cancel this pending work before dispatch, and cover close-before-debounce.
    Confidence: 0.98
  • [P2] Reset the resize guard when the active document changes — ui/src/components/browser/browser-panel-controller.ts:313-319
    The guard retains A's last requested size after switching away. If B already matches the panel, it does not replace that guard; an agent can then resize A, and returning to A observes the mismatch but suppresses the required request because A/W/H still matches the stale guard. Clear or generation-key the guard on tab/document transitions and test the A → B → A sequence.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2278ca6952ea.

Labels

Label changes:

  • add P2: The patch has two reproducible browser-panel lifecycle defects with limited but user-visible remote-browser impact.
  • add merge-risk: 🚨 session-state: The new synchronization state can apply a stale viewport to an inactive or hidden browser tab.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external contributor proof gate; its body nonetheless records an isolated real Gateway and Chrome before/after run.

Label justifications:

  • P2: The patch has two reproducible browser-panel lifecycle defects with limited but user-visible remote-browser impact.
  • merge-risk: 🚨 session-state: The new synchronization state can apply a stale viewport to an inactive or hidden browser tab.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external contributor proof gate; its body nonetheless records an isolated real Gateway and Chrome before/after run.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs ui/src/components/browser.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • Shakker: Recent current-main history contains a series of browser navigation and lifecycle repairs in this controller area. (role: recent browser-panel lifecycle contributor; confidence: medium; commits: c402b41eb3d4, 4bb7077538aa; files: ui/src/components/browser/browser-panel-controller.ts)
  • steipete: Current-main history includes prior Control UI browser-panel documentation work as well as this proposed implementation. (role: feature-era Control UI browser contributor; confidence: medium; commits: 330d0fa4c60d, 5749c2412e1d; files: docs/web/control-ui.md, ui/src/components/browser/browser-panel-controller.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Prevent or cancel delayed resize dispatch after the dock closes.
  • Reset or generation-key the resize guard across tab and document transitions.
  • Add the two focused lifecycle regressions and rerun the browser-panel test lane.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

ClawSweeper review findings: a debounced resize could fire after the dock
closed (silently resizing the agent-controlled browser), and the per-target
resize guard survived tab/document changes, suppressing a needed re-sync when
revisiting a tab an agent had resized. Gate syncViewport on the panel being
open and clear the guard in invalidateViewOperations; both paths now have
regression tests that fail pre-fix.
@steipete

Copy link
Copy Markdown
Contributor Author

Both ClawSweeper P2 findings are fixed at head ef89f6c6dd1, each at its lifecycle owner:

  • Fence queued resizes after the dock closes — syncViewport now refuses to dispatch unless browserPanelIsOpen(); a debounced resize that outlives an ordinary dock close no-ops instead of silently resizing the agent-controlled browser. Regression test: "drops a debounced resize when the dock closes before it fires".
  • Reset the resize guard when the active document changes — lastRequestedViewport is now cleared in invalidateViewOperations() (the existing owner of document-change invalidation), so revisiting a tab an agent resized re-requests the panel size. Regression test: "re-syncs a revisited tab after its document changed size elsewhere" (A → B → A sequence).

Both tests fail on the pre-fix code (2 failed → now 6/6 passing). Full browser-panel suite: 82/82. Exact-head CI is green and a fresh Codex autoreview of the branch reports no actionable findings.

@steipete
steipete merged commit 0f0d222 into main Aug 13, 2026
172 of 174 checks passed
@steipete
steipete deleted the steipete/sidebar-browser-responsive-28dd91 branch August 13, 2026 10:52
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 14, 2026
…law#123104)

* feat(ui): sync browser viewport to panel

* docs(web): note browser panel follows dock size

* refactor(ui): split browser panel input handling out of the controller

* refactor(ui): keep browser panel input host interface module-local

* fix(ui): fence browser viewport sync on dock close and document change

ClawSweeper review findings: a debounced resize could fire after the dock
closed (silently resizing the agent-controlled browser), and the per-target
resize guard survived tab/document changes, suppressing a needed re-sync when
revisiting a tab an agent had resized. Gate syncViewport on the panel being
open and clear the guard in invalidateViewOperations; both paths now have
regression tests that fail pre-fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant