Skip to content

feat(browser): add React Grab element picker and composer context chips - #890

Open
sambitcreate wants to merge 17 commits into
mainfrom
react_grab_feature
Open

sambitcreate wants to merge 17 commits into
mainfrom
react_grab_feature

Conversation

@sambitcreate

@sambitcreate sambitcreate commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds React Grab to Aiden's embedded Workspace Browser so you can click any live UI element (⇧⌘G on macOS, Ctrl+Shift+G on Linux, or the toolbar cursor toggle beside Annotate) and attach structured component/DOM context plus a clean cropped thumbnail directly to your chat composer.

Feature overview

  • Browser toolbar & shortcut: Adds the MousePointer2 Grab element toggle (aria-pressed) right of the URL bar alongside Annotate, plus a non-intrusive status strip (Click an element to grab for chat · ↑↓ parent/child · ⇧Click to add multiple · Esc to cancel) and ⇧⌘G / Ctrl+Shift+G shortcut intercepted inside both the host renderer and guest WebContentsView.
  • Closed Shadow DOM live inspector: Bundled runtime (main/services/browser/grab-runtime/, built via scripts/build-browser-grab.mjs) injects a zero-interference closed Shadow DOM highlight box & pill tag over the hovered element, supports ↑/↓ component-tree stepping, Shift+Click multi-grab, F animation freeze, and stops page click side effects during capture.
  • Framework detection & local VLQ source-map symbolication: Inspects React 16–19 fibers (including _debugStack / _debugOwner / Server Component frames), Vue, Svelte, Astro, Preact, Solid, Angular, and plain DOM fallback. Symbolicates local bundles in the main process (main/services/browser/grab-source-map.ts) strictly for loopback URLs and workspace-contained file:// .js/.mjs/.cjs/.map files.
  • DevTools-safe thumbnails & credential masking: Captures the element viewport cleanly even while DevTools is open (capturePage against page bounds rather than full-window rect), hides the highlight before capture, pixel-masks sensitive/password fields via credential-mask.ts, and bounds output to ≤640 px / ≤512 KiB PNG/JPEG.
  • Chat persistence & zero-breakage Remote/mobile contract: Adds optional ChatMessage.grabbedElements?: GrabbedElementContextV1[] sidecar validated strictly on append and stored reads, linking cropped thumbnails as standard grab-thumb_<id> image attachments stored via chat-image-store (aiden-attachment://). Requires zero Remote protocol revision — paired iOS/Android clients and aiden serve preserve and display the linked image cleanly without breaking existing wire contracts.
  • Composer chips, inspection popover & transcript: Renders borderless Aiden squircle chips (renderer/components/grabbed-element-chip.tsx) with hover preview (250 ms open / 140 ms close), click-to-pin "Included with your message" popover (cropped thumbnail, Element/Component rows, collapsible details with source path, framework badge, selector, size, page, redacted props, styles, HTML, copy button, Escape focus return), read-only transcript chips (align="end" so popovers stay clear of docked side-by-side Browser views), Edit-in-Fork & queue/draft persistence, and refreshed onboarding art/docs (PRODUCT.md, README.md, docs/environment-browser.md, docs/analytics.md, docs/plans/README.md, .memory/browser-react-grab.md).
  • Stored image protocol startup fix (main/index.ts): Moves registerChatAttachmentProtocol() before createMainWindow({ startupAdmissionHeld: true }) (matching installStudioAssetProtocol and startDesignProtocol) so aiden-attachment:// stored chat images load cleanly in the initial main window without net::ERR_UNKNOWN_URL_SCHEME.

Security & architecture invariants

  • Zero new IPC channels: Reuses existing browser:command (grab / stopGrab), browser:event (grabbed), and chat append/create channels.
  • Zero external network calls: Source-map resolution rejects non-loopback/remote origins and confines file:// reads to .js/.mjs/.cjs/.map within the workspace root.
  • Getter-safe inspection & secret redaction: Reads React props/fibers via Object.getOwnPropertyDescriptor without invoking page getters; redacts password/token/secret/auth/cookie/key props and attributes before returning from main, and pixel-masks sensitive inputs in thumbnails.
  • Bot browser exclusion: Bot browsers never expose Grab controls or accept Grab commands.
  • Non-blocking text-only model support & prompt-cache determinism: Text-only models keep full structured <attached-browser-elements> context with a quiet non-blocking note; prompt formatting sorts keys deterministically and omits volatile timestamps so prompt caches stay byte-stable.
  • Content-free analytics: Adds browser_element_grabbed (kind, source) and browser_grab_sent (count_bucket, with_screenshot) to the closed registry with zero URLs, selectors, paths, or HTML.

Verification

All checks passed on merged head dec388365 (with origin/main merged cleanly):

  • npm run check:aiden-rules: PASS (0 violations)
  • npm run type-check && npm run type-check:e2e && npm run lint: PASS (0 errors, 0 warnings)
  • npm run test:ci:registry: 15/15 PASS
  • npm run test:ci-policy: 123/123 PASS
  • npm run test:browser: 299/299 PASS
  • npm run test:slash-commands: 819/819 PASS
  • npm run test:onboarding: 81/81 PASS
  • npm run test:analytics: 174/174 PASS
  • npm run test:bot-browser: 37/37 PASS
  • Cua Space Electron E2E (npm run test:e2e:space -- tests/e2e/browser-grab.spec.ts tests/e2e/accessibility.spec.ts tests/e2e/browser.spec.ts): 16/16 PASS (0 failures, 0 retries) — covers live React grab, ↑/↓ stepping, 0 click side effects, secret redaction, LM Studio prompt + image_url, transcript chip & aiden-attachment:// thumbnail (naturalWidth > 0), ⇧⌘G/Ctrl+Shift+G shortcut, unstoppable Escape, host Escape, Shift+Click multi-grab, DevTools-open capture, navigation/tab cleanup, 0 axe WCAG A/AA violations with 0 new exclusions on "browser grab chip & inspection popover", and 13/13 existing Browser/Annotate regression tests.

CI fixes (2026-11-24)

  • Linux E2E browser-trust.spec.ts "fill dimensions and region crops ignore hostile page viewport globals": region screenshots had switched to reading innerWidth/innerHeight in the page's main world (executeJavaScript), so page-defined globals could affect crop math. The read is back on the isolated CDP world (cf57b0bb4). The unused viewport parameter on capture/capturePage is removed.
  • macOS Electron E2E browser-grab.spec.ts DevTools step: on the hosted macOS runner's smaller display, the test clicked #secret-form below the fold. That off-viewport click hit nothing, so the grab stayed active and no chip appeared. I reproduced it on a Mac by shrinking the window to about 560 px tall, and the E2E now scrolls each target into view before clicking (f09ca7685). Each overlay frame wait is capped at 100 ms. The cap bounds a wait that could otherwise never end on a page that does not paint; it is not the fix for this failure. The background-throttling lease that cf57b0bb4 added to the grab session came from a disproven hypothesis and is removed in 0a4ae90da. Thumbnail capture still takes its own lease.
  • Pullfrog findings, all fixed in 98b99ab70:
    • Source maps are bound to the authoritative page's exact loopback origin. file:// is read only for a file:// page with a workspace root and realpath containment.
    • Props never carry value or defaultValue, and credential fields keep only descriptive props.
    • Frames are pointer-shielded during a grab, so same-origin frame elements can be grabbed and frame handlers never fire. A new E2E test covers same-origin and cross-origin frames.
  • Local: npm run test:browser 301/301, type-check, lint, test:ci-policy 123/123. Cua Space E2E: browser-grab.spec.ts + browser-trust.spec.ts 8/8. Host macOS: browser-grab.spec.ts 3/3.
  • Pullfrog finding, fixed in 41d79f16f: the frame shield's observer watched only the light DOM. It now also observes every open shadow root that its scans find. A pointerover/pointermove backstop adopts shadow roots attached after the grab starts, and any frame inside them, before the pointer reaches the frame. The frames E2E adds one frame inside an existing shadow root and one inside a late-attached root mid-grab. It asserts that the inner buttons are captured and that no frame sees a pointer event.
  • Stale source hints (0a4ae90da): a grab records the page URL when it starts. A payload taken before the page moved to another origin carries no source hint and triggers no source-map fetch. A same-origin route change keeps the hints. Covered in grab-sanitize.test.ts.
  • Local on 0a4ae90da: npm run test:browser 302/302, type-check, type-check:e2e, lint. Cua Space E2E: browser-grab.spec.ts + browser-trust.spec.ts 8/8, no retries.

Flake note

  • iOS build and simulator tests failed on 98b99ab70 in AidenNativeIntegrationTests.testReconcileEndsAnActivityFromAnOlderPairing() (ActivityKit Live Activity, run 45334015770). This PR touches no ios/ code, and main's own iOS job on b2b5c3517 also failed, on a different test. The fresh run on f09ca7685 counts as the one allowed rerun. The iOS job will stay red until main (with the iOS fix, Stop iOS simulator tests stalling in CI #917) is merged in.
  • tests/e2e/design-mode.spec.ts:752 (E2E shard 2/5) failed once with Protocol error (Page.handleJavaScriptDialog): No dialog is showing and passed on retry. Because of --fail-on-flaky-tests, the job still went red (run 45368050792). The spec is unrelated to this PR and is not fixed here.

…/transcript integration, onboarding art, and docs
…e/thumbnail pipeline, BrowserService and BrowserPanel integration
…end, guard key repeat, and plumb grab source
# Conflicts:
#	README.md
#	docs/analytics.md
#	docs/plans/README.md
#	main/services/analytics/analytics-core.test.ts
#	main/services/analytics/analytics-events.ts
#	main/services/chat-store-core.test.ts
#	renderer/components/composer.tsx
#	renderer/components/onboarding-feature-gallery.test.tsx
#	renderer/main/chat-pane.tsx

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

This PR can disclose credential values and lets untrusted local pages drive privileged cross-origin or filesystem source-map reads; iframe capture also fails as implemented.

Reviewed changes Reviewed the complete React Grab implementation and its browser runtime, main-process sanitization and capture pipeline, chat/CLI persistence, composer and transcript UI, Remote/mobile compatibility, analytics, documentation, and tests.

  • Browser picker runtime Adds framework-aware element inspection, stepping, multi-grab, click suppression, thumbnail masking, and local source-map symbolication.
  • Chat delivery and persistence Carries structured element context and linked thumbnails through drafts, queues, forks, stored chats, generation messages, and the serve-only CLI.
  • Composer and transcript UI Adds context chips, inspection popovers, Browser controls and shortcuts, onboarding art, analytics, and focused unit/E2E coverage.
  • Attachment startup Registers the stored-image protocol before the first window is created.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

…e isolated crop viewport read

Region screenshots read the viewport in the page's main world, so hostile innerWidth/innerHeight globals could skew crops; go back to the isolated-world CDP read. The grab picker waits on animation frames that stop when the window is covered (detached DevTools on macOS), so hold a background-throttling lease for the session and bound each frame wait with a timer.
…tial field props, and shield frames while grabbing

Source-map reads now require the authoritative page's exact loopback origin, or a file:// page with a workspace root and realpath containment. Props never carry value/defaultValue, and credential fields keep only descriptive props. Frames get pointer-events: none during a grab so their input reaches the top document and is suppressed; hit tests lift the shield to grab same-origin frame elements.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The iframe fix still lets dynamically rendered shadow-DOM frames receive live input during Grab, so this interaction-safety regression should be closed before merge.

Reviewed changes Reviewed the two hardening commits since the prior Pullfrog review and rechecked their browser-runtime, main-process security, capture, documentation, and E2E implications.

  • Source authority hardening Bound symbolication to the authoritative page's exact loopback origin or canonical workspace-contained files.
  • Credential redaction Redacted live value props and credential-field primitive props in the runtime and main sanitizer.
  • Frame and capture reliability Added frame shielding, static iframe coverage, a background-throttling lease, a bounded animation-frame wait, and isolated viewport measurement.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

On the smaller macOS CI display the DevTools step clicked #secret-form below the fold, so the click hit nothing and the grab stayed active. Reproduced by shrinking the window; scrolling each target into view first fixes it.
Observe every open shadow root the frame shield finds, and adopt shadow roots and frames from pointer events as a backstop for roots attached after the grab starts. The frames E2E now adds frames inside an existing and a late shadow root mid-grab.
The background-throttling lease a grab held came from a disproven hypothesis; capture already takes its own lease. The 100 ms frame-wait cap stays as a bound on a wait that could otherwise never end.

A grab now records the page URL when it starts, and a payload taken before the page moved to another origin carries no source hint.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The late-shadow-root frame fix still permits child-frame input before the shield is active, so interaction suppression is not complete.

Reviewed changes Reviewed the three commits since the prior Pullfrog review, including the frame-shield follow-up, stale source-hint authority fence, grab-session throttling cleanup, and E2E stabilization.

  • Extended frame discovery Observed discovered open shadow roots and added pointer-driven adoption for roots attached after Grab starts, with expanded iframe E2E coverage.

  • Fenced stale source hints Recorded the Grab-start page URL and discarded source hints after a source-authority change while preserving same-origin route changes.

  • Adjusted capture reliability Removed the disproven session-wide throttling lease, retained bounded overlay frame waits, and scrolled E2E targets into view before clicking.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

// their host, and on entering a frame the frame element, in this document
// first, so they are shielded before input can reach the frame.
const onPointerOver = (event: PointerEvent) => {
frames.adopt(eventTarget(event));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late-root safety still depends on this handler running before child input. If an iframe is attached under a stationary pointer, the next click stays entirely in the child browsing context; on direct pointer entry, Chromium still delivers that movement's child pointerover/pointermove after this parent handler, while the E2E first crosses host padding and does not count those events.

Technical details
# Late shadow-root frames still receive input

## Affected sites
- `main/services/browser/grab-runtime/index.ts:379-394` — discovers a late-attached shadow root only from top-document pointer events.
- `tests/e2e/browser-grab.spec.ts:580-658` — moves across `late-host` padding before entering the iframe and counts only pointer down/up/click events.

## Required outcome
- Shield a frame in a newly attached open shadow root without requiring an earlier top-document pointer event.
- Cover a frame inserted under the stationary pointer followed by a click, plus direct entry that asserts `pointerover`/`pointermove` do not reach the child.

This branch has not been deployed

No deployments
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