crypto.randomUUID() shipped in Chrome 92 in July 2021. By 2022 it had landed in Firefox, Safari, and Edge, making it a Baseline feature — meaning you can use it without a polyfill in any browser released in the last few years. This article documents the full support matrix across browsers and server runtimes, explains the remaining gaps, and clarifies when you still need a library.

Browser support matrix

BrowserSupported fromNotes
Chrome / Chromium92 (Jul 2021)Available in secure contexts (HTTPS + localhost)
Firefox95 (Nov 2021)Available in secure contexts
Safari / WebKit15.4 (Mar 2022)Available in secure contexts
Edge92 (Jul 2021)Chromium-based, same as Chrome
Samsung Internet17.0Chromium-based
iOS Safari15.4Same as Safari

Baseline status: Widely available. No polyfill needed for any browser released after mid-2022.

Secure context requirement: crypto.randomUUID() is only available on HTTPS origins and localhost. It throws a TypeError on HTTP pages. This is by design — the Web Crypto API is restricted to secure contexts to prevent exposing cryptographic operations over unencrypted connections.

Node.js support

Node.js versionHow to access
14.17.0–18.xrequire('crypto').randomUUID() or globalThis.crypto.randomUUID()
19.0.0+crypto.randomUUID() as a top-level global (no import needed)

From Node.js 19, globalThis.crypto is a global Crypto object matching the Web Crypto API, so code written for browsers works in Node without modification.

// Works in browsers and Node.js 19+
const id = crypto.randomUUID();

// Works in Node.js 14.17+ and browsers
const { randomUUID } = require('node:crypto'); // or import
const id = randomUUID();

Deno and Bun

RuntimeSupport
Deno1.9+ (Apr 2021) — ships Web Crypto API including randomUUID
Bun0.1+ — ships globalThis.crypto with randomUUID

Both runtimes match the browser API exactly. Code using crypto.randomUUID() runs unchanged across browsers, Node.js 19+, Deno, and Bun.

What crypto.randomUUID() does not do

crypto.randomUUID() generates UUID v4 only. It does not:

For UUID v7, use the uuid npm package (v7()) or implement the RFC 9562 §5.7 layout directly — it is about 15 lines of code.

Comparing crypto.randomUUID() to the uuid package

Featurecrypto.randomUUID()uuid npm package
UUID v4YesYes
UUID v7NoYes (v9+)
UUID v5 (name-based)NoYes
Zero dependenciesYes — built-inNo
Bundle size0 bytes~5 KB minified
TypeScript typesVia lib.dom.d.tsIncluded

For applications that only need UUID v4, crypto.randomUUID() is the correct choice — no dependency, no bundle cost, cryptographically secure. For applications that need v7 (database primary keys) or v5 (deterministic name-based UUIDs), the uuid package is required.

A minimal UUID v7 implementation

If you want UUID v7 without a dependency, here is a compliant implementation in under 20 lines:

function uuidv7() {
  const bytes = crypto.getRandomValues(new Uint8Array(16));
  const ms = Date.now();

  // Timestamp (48 bits)
  bytes[0] = (ms / 2 ** 40) & 0xff;
  bytes[1] = (ms / 2 ** 32) & 0xff;
  bytes[2] = (ms / 2 ** 24) & 0xff;
  bytes[3] = (ms / 2 ** 16) & 0xff;
  bytes[4] = (ms / 2 **  8) & 0xff;
  bytes[5] =  ms            & 0xff;

  // Version 7
  bytes[6] = (bytes[6] & 0x0f) | 0x70;
  // Variant bits (RFC 9562)
  bytes[8] = (bytes[8] & 0x3f) | 0x80;

  return [...bytes].map((b, i) =>
    ([3,5,7,9].includes(i) ? '-' : '') + b.toString(16).padStart(2, '0')
  ).join('');
}

This implementation does not include the RFC 9562 §6.2 monotonic counter (which prevents out-of-order values within the same millisecond). For production use where sub-millisecond ordering matters, use the uuid package which implements Method 1 correctly.

Further reading

Frequently asked questions

Is crypto.randomUUID() safe to use without a library?

Yes, for UUID v4. crypto.randomUUID() is available in all modern browsers (Chrome 92+, Firefox 95+, Safari 15.4+) and Node.js 14.17+. It uses the platform CSPRNG and produces RFC 9562-compliant v4 values. It only generates v4 — for v7 you still need the uuid package or a custom implementation.

Does JavaScript have a built-in UUID generator?

Yes for v4: crypto.randomUUID() is available in all modern browsers and Node.js 19+. For v7 there is no built-in — use a library like the uuid npm package or a short RFC 9562-compliant implementation.

Are these UUIDs cryptographically secure?

The randomness is, yes — it comes from the Web Crypto API. That said, a UUID is an identifier, not a secret; don't use one as a password or an unguessable capability token on its own.

Is crypto.randomUUID() available in all browsers?

Yes. crypto.randomUUID() reached Baseline availability in 2022 and is supported in Chrome 92+, Firefox 95+, Safari 15.4+, and Edge 92+. For Node.js it is available from v14.17.0 via globalThis.crypto.randomUUID() and from v19.0.0 as a top-level global without the crypto. prefix. You do not need a polyfill for any browser released after mid-2022.

Does crypto.randomUUID() generate UUID v4 or v7?

It generates UUID v4 only — 122 bits of cryptographically secure randomness in the standard 8-4-4-4-12 format. There is no built-in function for UUID v7 in browsers or Node.js. For v7 you need a library (the uuid npm package) or a short RFC 9562-compliant implementation.