Skip to content

fix: support crypto.randomUUID in non-secure contexts (HTTP)#1

Open
macsatcom wants to merge 1 commit intoOpenRouterTeam:mainfrom
macsatcom:fix/crypto-random-uuid-non-secure-context
Open

fix: support crypto.randomUUID in non-secure contexts (HTTP)#1
macsatcom wants to merge 1 commit intoOpenRouterTeam:mainfrom
macsatcom:fix/crypto-random-uuid-non-secure-context

Conversation

@macsatcom
Copy link
Copy Markdown

Problem

crypto.randomUUID() is only available in secure contexts (HTTPS or localhost). When the app is served over plain HTTP — e.g. on a local network IP like 192.168.x.x — the browser throws:

Uncaught TypeError: crypto.randomUUID is not a function

This breaks both file upload and URL input in the Input Images card, since the id field can't be generated.

Note that page.tsx already handles this correctly with crypto.randomUUID?.() ?? ..., but references-card.tsx uses the bare crypto.randomUUID() call without a fallback.

Fix

Extract a randomId() helper that uses crypto.randomUUID?.() with optional chaining and falls back to a Math.random()-based ID when the secure context API is unavailable.

Test plan

  • Upload an image over HTTPS — works as before
  • Upload an image over HTTP on a local IP — no longer throws, image is added correctly
  • Add an image via URL over HTTP — works correctly

crypto.randomUUID() is only available in secure contexts (HTTPS or
localhost). Accessing the app over HTTP on a local network IP throws
'crypto.randomUUID is not a function', breaking image uploads and
URL input in the references card.

Replace the bare calls with a randomId() helper that falls back to a
Math.random()-based ID when the secure context API is unavailable.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

@macsatcom is attempting to deploy a commit to the OpenRouter Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant