Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

Zero-Backend Pro License Keys in Manifest V3 Extensions (With Offline Grace Caching)

Running a custom auth server, Stripe webhook listener, and PostgreSQL database just to unlock a $5–$7 Pro upgrade in a browser extension is overkill — and forces privacy-focused users to trust another third-party backend

Running a custom auth server, Stripe webhook listener, and PostgreSQL database just to unlock a $5–$7 Pro upgrade in a browser extension is overkill — and forces privacy-focused users to trust another third-party backend.

Across our MIT-licensed Manifest V3 extensions (Lark Markdown Clipper and Lark Cookie Sweep), we keep the core extension 100% free and verify optional Pro keys using one 80-line ES module (src/lib/license.js) with zero backend infrastructure.

Here is the exact pattern and the three edge cases that matter in production.

1. Validate Key Shape Before Touching the Network

Every key entered into an options page should pass a strict format check before triggering any fetch() call. Standard Gumroad license keys follow four 8-character uppercase alphanumeric groups:

export const GUMROAD_VERIFY_URL = "https://api.gumroad.com/v2/licenses/verify";
export const CACHE_KEY = "ll_license";
export const CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000; // re-verify weekly

export function normalizeKey(key) {
  if (typeof key !== "string") return null;
  const k = key.trim().toUpperCase();
  // Gumroad keys look like XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX
  return /^[A-Z0-9]{8}(-[A-Z0-9]{8}){3}$/.test(k) ? k : null;
}

Rejecting typos locally avoids wasted requests and lets the UI return an instant "malformed key" message.

2. Distinguish Definitive Invalid Keys From Transient Network Errors

When calling POST https://api.gumroad.com/v2/licenses/verify, pass increment_uses_count: "false" so checking the same user's key on a weekly timer doesn't burn activation limits, and inspect both res.ok and body.success:

export function isValidPurchase(body) {
  if (!body || body.success !== true || !body.purchase) return false;
  const p = body.purchase;
  return !p.refunded && !p.chargebacked && !p.disputed &&
    !p.subscription_ended_at && !p.subscription_cancelled_at && !p.subscription_failed_at;
}

export async function verifyOnline(productId, key, fetchImpl = globalThis.fetch) {
  const k = normalizeKey(key);
  if (!k) return { status: "invalid", error: "malformed key" };
  if (!productId) return { status: "error", error: "missing product id" };
  let res;
  try {
    res = await fetchImpl(GUMROAD_VERIFY_URL, {
      method: "POST",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: new URLSearchParams({
        product_id: productId,
        license_key: k,
        increment_uses_count: "false",
      }).toString(),
    });
  } catch (e) {
    return { status: "error", error: String(e?.message ?? e) };
  }
  let body = null;
  try { body = await res.json(); } catch { /* non-JSON body */ }
  // Gumroad answers 404 + success:false for unknown keys: definitive "invalid".
  if (body && body.success === false) return { status: "invalid", error: body.message ?? "not found" };
  if (!res.ok || !body) return { status: "error", error: `HTTP ${res.status}` };
  return isValidPurchase(body)
    ? { status: "valid", email: body.purchase.email }
    : { status: "invalid", error: "refunded, disputed or subscription inactive" };
}

Notice the critical distinction:

  • body.success === false (even with HTTP 404) is a definitive "invalid" — unknown, refunded, or disputed key.
  • fetch throwing offline or receiving a 5xx response returns "error" — never revoke a paying customer's Pro unlock just because their laptop is on airplane Wi-Fi.

3. Weekly chrome.storage Cache With Offline Grace

Inside checkPro, cache { key, valid, checkedAt } in chrome.storage.local for 7 days. When the TTL expires, re-verify in the background, and if r.status === "error", preserve Boolean(cached.valid):

export async function checkPro(productId, storage, { fetchImpl = globalThis.fetch, now = Date.now() } = {}) {
  const cached = (await storage.get(CACHE_KEY))?.[CACHE_KEY];
  if (!cached?.key) return false;
  if (cached.valid && now - (cached.checkedAt ?? 0) < CACHE_TTL_MS) return true;
  const r = await verifyOnline(productId, cached.key, fetchImpl);
  if (r.status === "error") return Boolean(cached.valid);
  await storage.set({ [CACHE_KEY]: { key: cached.key, valid: r.status === "valid", checkedAt: now } });
  return r.status === "valid";
}

And because fetchImpl and storage are injected parameters, the entire licensing flow is unit-tested in Node.js with zero Chrome mocks (node --test).

4. Minimal host_permissions Disclosure

Store reviewers (Chrome Web Store, Firefox AMO, Edge Add-ons) scrutinize network permissions. Scoping "host_permissions" exclusively to "https://api.gumroad.com/*" instead of <all_urls> makes privacy reviews straightforward — and makes it obvious to users that the extension never calls your own server unless they explicitly enter a license key.

You can inspect the full MIT source and reuse src/lib/license.js directly from:

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.