All posts

How to set up license keys in a browser extension

Nicholas Affonso

January 03, 2026

How to set up license keys in a browser extension

Monetizing a browser extension is straightforward with Keyforge. In this guide, you'll add license key activation and validation to a Chrome, Firefox, or Edge extension using simple fetch calls from your background script or popup.

You'll also see how to connect a payment provider so licenses are delivered automatically after purchase.

Before you start

Make sure you've created the basics inside your Keyforge account:

Setting up a device identifier

Each license activation is tied to a device identifier. For browser extensions, a UUID stored in chrome.storage (or browser.storage for Firefox) works well as a stable identifier.

async function getDeviceId() {
  const result = await chrome.storage.local.get('deviceId');
  if (result.deviceId) return result.deviceId;

  const id = crypto.randomUUID();
  await chrome.storage.local.set({ deviceId: id });
  return id;
}

This ID is generated once on first run and reused on every subsequent launch.

Activating a license

When a user enters their license key, activate it against their device. Call the activation endpoint from your background script or popup.

const deviceId = await getDeviceId();

const res = await fetch(
  'https://keyforge.dev/api/v1/public/licenses/activate',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      licenseKey: 'ABCDE-ABCDE-ABCDE-ABCDE-ABCDE',
      deviceIdentifier: deviceId,
      deviceName: 'My browser',
      productId: 'p_123456',
    }),
  }
);

const data = await res.json();
await chrome.storage.local.set({ licenseKey: data.license.key });
console.log('License activated');

After activation, the license key is stored in chrome.storage so it can be retrieved on future launches without asking the user again.

Validating a license

On each launch (or when the extension is initialized), validate the stored license key to confirm it's still active.

const { licenseKey, deviceId } = await chrome.storage.local.get([
  'licenseKey',
  'deviceId',
]);

const res = await fetch(
  'https://keyforge.dev/api/v1/public/licenses/validate',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      licenseKey,
      deviceIdentifier: deviceId,
      productId: 'p_123456',
    }),
  }
);

const data = await res.json();
if (data.isValid) {
  console.log('License is valid');
} else {
  console.log('License invalid');
}

If the license is invalid, prompt the user to enter a new key or direct them to the customer portal.


Payments and customer portal

Connect a payment provider to automatically generate and deliver a license key by email when someone purchases your extension, with no backend or webhooks required. Keyforge supports Stripe, Lemon Squeezy, and Polar for both one-time purchases and subscriptions.

For subscriptions, license expiration dates update automatically on each renewal, and the license is deactivated if a subscription is cancelled. Follow the payments setup guide to connect your product. Customers can manage their licenses, devices, and billing through the customer portal.

License upgrades and renewals

You can offer customers the option to upgrade their license to a higher tier or extend the expiration date of a timed license, directly from the customer portal with no code required. Configure up to 3 upgrade or renewal options per product in the dashboard.

Perpetual fallback

Perpetual fallback lets customers keep using your extension with limited functionality after their license expires, rather than being locked out entirely. When enabled on a product, the validate endpoint returns status: "fallbacked" for expired licenses. Note that isValid remains true in this case, so check the status field to differentiate.

const data = await res.json();

if (data.status === 'active') {
  // Full access
} else if (data.status === 'fallbacked') {
  // License expired - grant limited access based on your extension's logic
  console.log('Running in limited mode');
} else {
  // Invalid - prompt the user to re-enter their license key
}

Conclusion

You now have a complete licensing setup for your browser extension. The same code works across Chrome, Firefox, and any Chromium-based browser. Keyforge handles license management and payment automation so you can focus on building your extension.

For more details, visit the Keyforge documentation.

Simplify your licensing process

Focus on building your product and let us handle licensing. Manage license keys via payments and offer your customers a smooth self-serve experience.