[PR #12988] fix(app): handle crypto.randomUUID failure in non-secure browser contexts #14464

Closed
opened 2026-02-16 18:19:15 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12988

State: closed
Merged: No


Fixes #12989

crypto.randomUUID() throws a DOMException when called in a non-secure browser context (plain HTTP, not HTTPS). This crashes the web UI when attaching images and in a couple other spots.

The existing code used optional chaining (crypto.randomUUID?.()) but that doesn't help — the method exists on the crypto object, it just throws when the context isn't secure.

Fix:

Replace optional chaining with try/catch in the 3 browser-context usages:

  • packages/app/src/components/prompt-input/attachments.ts
  • packages/app/src/context/comments.tsx
  • packages/app/src/utils/perf.ts

Falls back to Math.random().toString(16).slice(2) on failure (same fallback as before, just actually reachable now).

Server-side usages (packages/opencode, packages/enterprise) are unaffected since Node/Bun always has a secure context.

Testing:

Ran the web UI locally over HTTP, confirmed image attachment works without the randomUUID crash.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12988 **State:** closed **Merged:** No --- Fixes #12989 `crypto.randomUUID()` throws a `DOMException` when called in a non-secure browser context (plain HTTP, not HTTPS). This crashes the web UI when attaching images and in a couple other spots. The existing code used optional chaining (`crypto.randomUUID?.()`) but that doesn't help — the method exists on the `crypto` object, it just throws when the context isn't secure. **Fix:** Replace optional chaining with try/catch in the 3 browser-context usages: - `packages/app/src/components/prompt-input/attachments.ts` - `packages/app/src/context/comments.tsx` - `packages/app/src/utils/perf.ts` Falls back to `Math.random().toString(16).slice(2)` on failure (same fallback as before, just actually reachable now). Server-side usages (packages/opencode, packages/enterprise) are unaffected since Node/Bun always has a secure context. **Testing:** Ran the web UI locally over HTTP, confirmed image attachment works without the randomUUID crash.
yindo added the pull-request label 2026-02-16 18:19:15 -05:00
yindo closed this issue 2026-02-16 18:19:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14464