#7030

feat(browser): add passive CSS variables and design token extraction

OpenHumaam-04-06wants to merge intofrom

Summary

Adds passive extraction of :root CSS custom properties (variables and design tokens) to web page inspection across domain schemas, the Chrome DevTools Protocol (CDP) provider, and the CLI/MCP tool boundaries under --include-css-variables.

Problem and expected behavior

When reverse-engineering and reconstructing web applications and user interfaces from captured browser sessions, agents and analysts need access to design system tokens (color schemes, spacing, typography scales, z-indexes, and design system variables). Previously, inspectWebPage only captured DOM snapshots, scripts, network requests, and storage, leaving CSS custom properties unobserved unless manually queried via console evaluations.

With this change:

  • inspectWebPage accepts an optional include_css_variables flag (defaults to false).
  • When enabled, it queries :root computed styles via CDP (CSS.enable, CSS.getComputedStyleForNode, and CSS.disable cleanup).
  • It extracts and strictly validates --[a-zA-Z0-9_-]+ variables, stripping non-printable/control characters, enforcing size limits (maximum 250 variables, 512 bytes per value, max 5 nested var() references, bounded 2,000 raw intake buffer).
  • Returns structured facts with deterministic sorting, origin_scope attribution, and diagnostic limitation reporting.

Change and scope

  • Added browserCssVariablesSummarySchema and input schema options in src/domain/browserObservationSchemas.ts and src/domain/browserObservation.ts.
  • Implemented captureCssVariables in src/browser/CdpCaptureCssVariables.ts and integrated into src/browser/CdpPageCapture.ts.
  • Exposed --include-css-variables flag in src/cliObservationOptions.ts, src/cli/browserCommands.ts, and tool schemas in src/contracts/browserToolContracts.ts.
  • Implemented unit tests for schema parsing/validation, CDP mock connection extraction & error handling, and CLI boundary execution.

Follow the contribution scope. Ordinary enhancement within existing read-only browser inspection boundaries; maintainer scope decision is not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/domain/browserObservationSchemas.ts (domain contract), then src/browser/ (CDP provider extraction), then src/cli/ (CLI adapter).
  • Contribution scope fit and linked maintainer decision: Read-only passive observation of browser styling, not applicable.
  • CLI and MCP/tool-catalog contract: Added --include-css-variables boolean option to CLI rea browser inspect and MCP inspectWebPage.
  • Provider, bridge, target-format, or platform compatibility: Chrome DevTools Protocol (CDP) CSS and DOM domains. Handled protocol-level rejection gracefully with limitation reporting.
  • Evidence, artifact, provenance, or reconstruction contract: Returns css_variables object with status, origin_scope, total, retained_count, and sorted items.
  • Target selection, authority, upstream behavior, and cleanup details: Read-only query; guarantees CSS.disable cleanup in finally block.
  • Generated metadata, package, or installation impact: Verified via npm run mcp-catalog:check and npm run docs:check.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • src/domain/browserObservation.test.ts (domain validation, max items, BiDi/control character filtering, nesting depth bounds)
    • src/browser/CdpCaptureCssVariables.test.ts (CDP protocol command sequence, error handling, truncation, detached DOM nodes)
    • tests/boundary/cli/browserCssVariablesCli.test.ts (CLI argument parsing and tool dispatch)
  • User-visible CLI/MCP output:
    "css_variables": {
      "status": "extracted",
      "origin_scope": "same_origin",
      "total": 2,
      "retained_count": 2,
      "items": [
        { "name": "--primary-color", "value": "#007acc" },
        { "name": "--spacing-unit", "value": "8px" }
      ]
    }

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • node scripts/run-typescript.mjs --noEmit — 0 errors across all 5,275 files.
  • npx.cmd vitest run src/domain/browserObservation.test.ts src/browser/CdpCaptureCssVariables.test.ts tests/boundary/cli/browserCssVariablesCli.test.ts — 23/23 tests passed.
  • npm.cmd run check:fast — turbo typecheck + lint 2/2 tasks successful.
  • npm.cmd run format:check — 0 formatting issues across 5,766 files.
  • npm.cmd run docs:check — 6/6 tasks successful, 9/9 readme conformance tests passed.
  • npm.cmd run mcp-catalog:check — 4/4 tasks successful.
  • npm.cmd run build:cached — 3/3 tasks successful.

Compatibility, safety, and release

  • Breaking changes or migration steps: None. include_css_variables is optional and defaults to false.
  • Real Hopper/Ghidra, browser, or OS coverage: Validated against CDP protocol contract specifications on Windows.
  • Security, privacy, process, or containment review: Fully bounded: 250 items max, 512 bytes per value max, 5-level nested var() limit, non-printable & control characters stripped, 2000-variable intake cap to prevent memory exhaustion, detached DOM node resilience (-32000), guaranteed CSS.disable cleanup.

Author readiness

Human owner: @Humaam-04-06

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Activity

17
greptile-apps[bot]1mo ago

Confidence Score: 5/5

[Medium impact] The PR appears safe to merge based on the reviewed changes.

Summary

Adds optional root CSS variable capture to browser inspection, with bounded results, credential redaction, and coverage reporting.

  • Page inspection can return root CSS design tokens on request.
  • Capture comparisons now include selected root CSS variables.
  • Existing imports are grouped together without changing behavior.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["CLI / MCP: include_css_variables"] --> B["Inspection input"]
  B --> C["CDP: root computed styles"]
  C --> D["Redact URL credentials"]
  D --> E["Validate and bound tokens"]
  E --> F["Evidence: items and coverage"]

Reviews (13) · Last reviewed commit: "fix(browser): recognize escaped url func..." · Reviewed by Greptile

chatgpt-codex-connector[bot]1mo ago

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

ReviewStatusCommitReview trigger
📝 Code Review✅ Completed 2026-10-25T14:42:37.824361Z834becbNew commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

greptile-apps[bot]1mo ago

Want your agent to iterate on Greptile's feedback? Try greploops.