Repository navigation
fix(desktop): browser error copy + renderer CSP - #324
Merged
Merged
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
did-fail-loadforwarded Chromium's rawerrorDescription(e.g.ERR_CONNECTION_REFUSED) straight to the Browser surface's error empty state. Added a puredescribeLoadError()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 intobrowser-surface.tsx's error state, showing human text plus the raw code.default-src 'self') via a<meta>tag inapps/desktop/index.html.img-srcalso allowsdata:/blob:/https:(browser-tab still-frame snapshots, composer image attachments viaURL.createObjectURL, and arbitrary tool-result image URLs in the Trajectory inspector) andscript-srcallowswasm-unsafe-eval(the Session Dock diff viewer's bundled oniguruma WASM for syntax highlighting).electron.vite.config.tsrelaxesscript-srcfurther only for the Vite dev server (HMR client + React Fast Refresh's inline preamble); the productionindex.htmlships unmodified.Verification
bun run typecheck— green.bun run test— green except 3 tests (agent-workspace.test.tsxx2,design-components.test.tsxx1) 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.securitypolicyviolationevents: an injected inline<script>is blocked, a cross-originfetch()is blocked, and same-originWebAssembly.instantiateof 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 useblob:URLs) is now fixed by addingblob:toimg-src, and passes reliably both alone and with--repeat-each=3.Test plan
bun run typecheckbun run test(describe-load-error + browser-surface + session-browser-panel suites)bun run buildbun run test:e2e(all Browser-surface specs green; residual failures are pre-existing full-suite flakes unrelated to this change)Closes #156
Closes #157