Skip to content

crypto.randomUUID is not a function. Appcheck bug in iOS safari local dev #9268

@EthanSK

Description

@EthanSK

Operating System

iOS

Environment (if applicable)

Angular

Firebase SDK Version

11.9.0

Firebase SDK Product(s)

AppCheck

Project Tooling

Angular, node (nestjs), nx monorepo

Detailed Problem Description

If i try and test my app over LAN on my iphone (for debug development), appcheck throws random UUID error

[Error] crypto.randomUUID is not a function. (In 'crypto.randomUUID()', 'crypto.randomUUID' is undefined)

It's because this function doesnt exist on ios safari. I dont wanna do polyfils so for now I just do this script so it sets the token in indexdb so it doesnt try and generate again


(async (token = 'YOUR DEBUG TOKEN THATS REGISTERED ON FIREBASE CONSOLE FOR APPCHECK  ') => {
  // Optional: also set the runtime flag so dev builds don't auto-generate
  window.FIREBASE_APPCHECK_DEBUG_TOKEN = token;

  const db = await new Promise((res, rej) => {
    const r = indexedDB.open('firebase-app-check-database', 1);
    r.onupgradeneeded = e => {
      const db = e.target.result;
      if (!db.objectStoreNames.contains('firebase-app-check-store')) {
        db.createObjectStore('firebase-app-check-store', { keyPath: 'compositeKey' });
      }
    };
    r.onsuccess = () => res(r.result);
    r.onerror = () => rej(r.error);
  });

  await new Promise((res, rej) => {
    const tx = db.transaction('firebase-app-check-store', 'readwrite');
    const store = tx.objectStore('firebase-app-check-store');
    const req = store.put({ compositeKey: 'debug-token', value: token });
    req.onsuccess = () => res();
    req.onerror = () => rej(req.error);
  });

  console.log('✅ App Check debug token set in IndexedDB:', token, '→ reload now.');
})();

Steps and code to reproduce issue

Just load the page with configured appcheck and you will see it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions