Skip to content

fix(desktop): browser error copy + renderer CSP - #324

Merged
bubbleptr merged 2 commits into
mainfrom
fix/browser-error-copy-and-renderer-csp
Sep 17, 2026
Merged

bubbleptr merged 2 commits into
mainfrom
fix/browser-error-copy-and-renderer-csp

Conversation

@bubbleptr

Copy link
Copy Markdown
Owner

Summary

  • Browser surface:常见 errno 映射成人话 #156: did-fail-load forwarded Chromium's raw errorDescription (e.g. ERR_CONNECTION_REFUSED) straight to the Browser surface's error empty state. Added a pure describeLoadError() mapping the common codes (connection refused, DNS failure, cert problems, no internet, timeout, aborted) to plain English, falling back to the raw text for anything unmapped. Wired into browser-surface.tsx's error state, showing human text plus the raw code.
  • Renderer 自身 CSP(外壳卫生) #157: Added a baseline renderer CSP (default-src 'self') via a <meta> tag in apps/desktop/index.html. img-src also allows data:/blob:/https: (browser-tab still-frame snapshots, composer image attachments via URL.createObjectURL, and arbitrary tool-result image URLs in the Trajectory inspector) and script-src allows wasm-unsafe-eval (the Session Dock diff viewer's bundled oniguruma WASM for syntax highlighting). electron.vite.config.ts relaxes script-src further only for the Vite dev server (HMR client + React Fast Refresh's inline preamble); the production index.html ships unmodified.

Verification

  • bun run typecheck — green.
  • bun run test — green except 3 tests (agent-workspace.test.tsx x2, design-components.test.tsx x1) that time out only under full-suite parallel load; all pass in isolation and are unrelated to this change (pre-existing timing flakes, confirmed by rerunning against the pre-change baseline).
  • bun run build — green.
  • Verified the production CSP is actually enforced (not silently ignored) by launching the built app with Playwright/Electron and checking real securitypolicyviolation events: an injected inline <script> is blocked, a cross-origin fetch() is blocked, and same-origin WebAssembly.instantiate of the bundled module succeeds.
  • bun run test:e2e — flaky under full parallel load both before and after this change (confirmed against the pre-change baseline: different ad hoc-Vite-dev-server fixture tests fail each run due to port/resource contention, e.g. trajectory-ledger.spec.ts, trajectory-strip.spec.ts, changes-files-surfaces.spec.ts). The one test that did regress from this change (browser-surface.spec.ts "Design mode marks a strict-CSP page...", failing because composer image attachments use blob: URLs) is now fixed by adding blob: to img-src, and passes reliably both alone and with --repeat-each=3.

Test plan

  • bun run typecheck
  • bun run test (describe-load-error + browser-surface + session-browser-panel suites)
  • bun run build
  • bun run test:e2e (all Browser-surface specs green; residual failures are pre-existing full-suite flakes unrelated to this change)

Closes #156
Closes #157

- Add describeLoadError(), a pure function mapping did-fail-load's raw
  Chromium error codes (ERR_CONNECTION_REFUSED, ERR_NAME_NOT_RESOLVED,
  ERR_CERT_*, ERR_INTERNET_DISCONNECTED, ERR_CONNECTION_TIMED_OUT,
  ERR_ABORTED) to plain-English text; unknown codes fall back to the raw
  text unchanged. Wire it into the Browser surface's error empty state,
  showing the human text plus the raw code.
- Add a baseline Content-Security-Policy meta tag to index.html
  (default-src 'self', with img-src covering data:/blob:/https: for
  browser-tab snapshots, composer attachments, and Trajectory
  tool-result images, and script-src covering wasm-unsafe-eval for the
  diff viewer's bundled oniguruma WASM). electron.vite.config.ts relaxes
  script-src further only for the Vite dev server's HMR client and
  React Fast Refresh preamble; the production value ships unmodified.

Closes #156
Closes #157
Address PR #324 review findings:

- Extract relaxCspForDevServer() into apps/desktop/vite-dev-csp.ts and
  use it from both electron.vite.config.ts (bun run dev) and
  vite.mock.config.ts (bun run dev:mock) — the latter also serves the
  real index.html through a Vite dev server with @vitejs/plugin-react
  active, so it needs the same script-src relaxation for React Fast
  Refresh's inline preamble. Verified bun run dev:mock renders with
  zero CSP violations via Playwright/chromium against 127.0.0.1:1421.
  (The e2e specs that spin up ad hoc vite.createServer() fixtures
  render their own hand-rolled HTML with no CSP meta and no react()
  plugin, and the http-based fixtures don't serve index.html at all —
  neither needs this plugin; re-ran all five named specs individually
  to confirm.)
- Move describe-load-error.ts (+ test) from entities/browser into
  shared/ui/browser, next to its only caller, so shared/ui keeps its
  existing type-only-import boundary with entities.
- Trim describe-load-error.test.ts to the behaviors worth protecting:
  a known code maps to non-raw human text with rawCode preserved,
  every ERR_CERT_* variant groups under the same text, unknown/non-code
  input falls back verbatim, and whitespace is trimmed before matching.
  Dropped the per-code literal assertions.
@bubbleptr
bubbleptr merged commit c758399 into main Sep 17, 2026
@bubbleptr
bubbleptr deleted the fix/browser-error-copy-and-renderer-csp branch September 17, 2026 09:06
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.

Renderer 自身 CSP(外壳卫生) Browser surface:常见 errno 映射成人话

1 participant