Skip to content

Conversation

@selimerunkut
Copy link
Contributor

@selimerunkut selimerunkut commented Feb 10, 2026

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.

@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@adamdotdevin
Copy link
Contributor

@selimerunkut let's create a shared utility for new IDs to clean this up a bit

@adamdotdevin
Copy link
Contributor

I went ahead and took care of this, gave you credit in the commit

@selimerunkut
Copy link
Contributor Author

selimerunkut commented Feb 12, 2026 via email

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.

Web UI - attaching images over HTTP (non-secure context) does not work

2 participants