fix(app): handle crypto.randomUUID failure in non-secure browser contexts #12988
+21
−3
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.
Fixes #12989
crypto.randomUUID()throws aDOMExceptionwhen 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 thecryptoobject, 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.tspackages/app/src/context/comments.tsxpackages/app/src/utils/perf.tsFalls 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.