Skip to content

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

Open
sambitcreate wants to merge 14 commits into
mainfrom
react_grab_feature
Open

sambitcreate wants to merge 14 commits into
mainfrom
react_grab_feature

Conversation

@sambitcreate

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.

…/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 | 𝕏

}
}
});
this.observer.observe(document.documentElement, { childList: true, subtree: true });

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.

This observer covers only light-DOM additions. If a web component inserts an iframe into an open shadow root after Grab starts, or attaches that root after activation, the frame is never shielded; its handlers receive the click and Grab receives no top-document event.

Technical details
# Dynamic shadow-root frames bypass Grab

## Affected sites
- `main/services/browser/grab-runtime/index.ts:93-101` — the sole observer is attached to `document.documentElement`; mutation observation does not cross shadow boundaries, and `attachShadow()` does not create a light-DOM child mutation.
- `tests/e2e/browser-grab.spec.ts:515-591` — verifies only frames already present in the light DOM before Grab starts.

## Required outcome
- Keep every discoverable frame shielded for the full Grab session, including frames added to open shadow roots after activation.
- Add a behavioral case that inserts the shadow-root frame after Grab starts and proves its pointer/click handlers remain untouched while the element is captured.

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