Back to blog

How to add license keys to a Chrome extension

Add license keys to a Chrome extension: issue a key with every PayPal purchase, activate it in-app, cap devices with seats. No backend required.

ExtensionBill Team 8 min read

Selling a paid extension raises a practical question fast: how does a buyer unlock what they paid for on their second computer, or on a colleague’s machine? This guide shows how to add license keys to a Chrome extension: issue a key with every purchase, let buyers activate it inside your extension, cap how many devices one purchase can use, and revoke the key automatically when an order is refunded. No license server to build or host.

If your extension doesn’t take payments yet, start with How to Add Payments to a Chrome Extension and come back here once checkout works.

When a Chrome extension license key beats email restore

A buyer who pays from your extension is unlocked on that install right away. The question is everything after that: a new laptop, a second browser profile, a reinstall, or a teammate who should use the copy their manager bought.

There are two common answers:

  • Restore with email. The buyer types the email they paid with, confirms a one-time code, and the install is linked to their purchases. Nothing to keep track of, and it covers most individual buyers. See Restore purchases.
  • License key. The buyer pastes a key like 7KQ2-M9XD-4RTB-H8VE into your extension. No inbox involved.

Email restore is the friendlier default, but paid licenses for a Chrome extension with a key fit better when:

  • One person buys and someone else uses it. Team leads, agencies and IT departments buy copies for other people. Handing over a key is easier than sharing an inbox.
  • The device can’t receive email. Shared, kiosk or locked-down machines where the user can’t open a mailbox to read a code.
  • You want a hard device limit. Email-linked purchases have no cap: any number of installs can link to the same customer. A key has a seat limit, so “use on up to 3 devices” is actually enforced.
  • You sell outside the extension. Comped copies, giveaways and bulk deals are simpler to deliver as keys.

You don’t have to choose. Offering both (“Already purchased? Restore with your email” and “Have a license key?”) covers every buyer.

Why client-only license key checks are crackable

The tempting shortcut is to validate keys inside the extension: a checksum, a hard-coded list, or a key derived from the buyer’s email with a secret salt. All of these fail for the same reason. Your extension ships to the user as readable JavaScript. Anyone can unpack it, read the validation function, and either generate valid keys or edit the check to always return true. Whatever secret the check relies on is inside the package.

License key validation for a browser extension has to happen somewhere the user doesn’t control. That means a server holds the keys, counts activations, and issues a result the extension can’t forge. ExtensionBill does this for you: activation is a request to its API, the resulting access is carried in an ES256-signed entitlement token, and editing chrome.storage doesn’t produce a valid signature. Nobody can create a license without a real completed PayPal payment (or a key you issued yourself).

To be honest about the limits: a determined user can still patch your extension’s own code so bill.hasAccess() returns true and load the modified copy unpacked. No client-side check prevents that, with any tool. For local features that’s an acceptable risk, since most people pay rather than patch code. For valuable work (AI calls, sync, data you pay for per request), check access on your server too. The Security model covers where to draw that line.

How seats and devices work

A seat is one activation of a key on one install of your extension:

  • Each install that activates a key uses one seat. Activating the same key again on the same install doesn’t use another seat.
  • The seat limit is set per product: 3 by default, any number you choose, or unlimited.
  • When every seat is in use, a new activation fails with seat_limit_reached until a seat is freed.
  • Uninstalling the extension does not free a seat, because the activation belongs to the key. A reinstall is a new install, so activating the key again takes a new seat until the old device is removed.
  • Computers signed into the same browser profile with sync on share one install through chrome.storage.sync, so they share one seat.

Seats are freed in three ways: the extension calls bill.deactivateLicense(), the buyer clicks Remove device in the customer portal, or you remove the activation in the dashboard.

Add license keys to a Chrome extension with ExtensionBill

This assumes the SDK is installed and a shared bill.js module exists, as set up in the payments guide:

// bill.js
import { ExtensionBill } from '@extensionbill/sdk'

export const bill = ExtensionBill({ publishableKey: 'pk_test_…' })

Step 1: Turn on license keys for a product

In the dashboard, open Sell → Products, edit the product and turn on License keys. Pick a Seat limit (default 3, or Unlimited) and an optional Duration in days; leave it empty for keys that never expire.

From then on, every paid purchase of that product gets a key. The buyer sees it once on the hosted checkout success page with a copy button, receives it by email (on by default under Settings → Emails → License keys), and can reveal it again in the customer portal. The install that completed checkout is unlocked straight away; the key is for the buyer’s other devices and anyone they share the purchase with.

Existing orders don’t get keys retroactively. For those, and for comped copies, use Customers → Licenses → Issue license.

Step 2: Add an activation form

Put a small form on your options page:

<!-- options.html -->
<form id="license-form">
  <label for="license-key">License key</label>
  <input id="license-key" placeholder="XXXX-XXXX-XXXX-XXXX" autocomplete="off" spellcheck="false" />
  <button type="submit">Activate</button>
</form>
<p id="license-message" role="status"></p>
<script type="module" src="options.js"></script>

Then call bill.activateLicense(key, label?). The optional label names the device, so the buyer recognizes it later in the portal:

// options.js
import { bill } from './bill.js'

const form = document.getElementById('license-form')
const input = document.getElementById('license-key')
const message = document.getElementById('license-message')

const errors = {
  license_not_found: 'That key was not found. Check it for typos.',
  license_revoked: 'This key is no longer valid.',
  license_expired: 'This key has expired.',
}

form.addEventListener('submit', async (event) => {
  event.preventDefault()
  try {
    await bill.activateLicense(input.value.trim().toUpperCase(), 'Chrome on ' + navigator.platform)
    message.textContent = 'License activated.'
  } catch (err) {
    message.textContent = err.code === 'seat_limit_reached'
      ? `This key is already used on ${err.details.seatsUsed} of ${err.details.seatLimit} devices. Remove a device in the customer portal, then try again.`
      : errors[err.code] ?? err.message
  }
})

On success the promise resolves with the updated user: user.paid is true, user.plan.type is 'license', user.entitlements contains the product’s entitlement key, and user.license describes the key. An empty key is rejected with invalid_argument before any request is made.

If you’d rather not build this UI, the Paywall UI already includes a “Have a license key?” field that calls bill.activateLicense(key).

Step 3: Gate features with hasAccess

A license grants the same entitlement as a direct purchase, so your feature gates don’t change:

// popup.js
import { bill } from './bill.js'

const user = await bill.getUser()

if (bill.hasAccess(user, 'pro')) {
  unlockProFeatures()
} else {
  showUpgradePrompt()
}

'pro' is the product’s entitlement key from the dashboard. getUser() serves a cached state for up to 5 minutes and keeps working offline for up to 72 hours after the last successful check, thanks to the signed entitlement token.

Step 4: Show the active key and a remove button

Let buyers move their key to a new computer without emailing you. Add a block with a #license-summary paragraph and a #license-deactivate button, then render from user.license, which is null unless a key is active on this install:

// options.js (additions)
const active = document.getElementById('license-active')
const summary = document.getElementById('license-summary')

function render(user) {
  const { license } = user
  form.hidden = Boolean(license)
  active.hidden = !license
  if (!license) return
  const seats = license.seatLimit === null
    ? `${license.seatsUsed} devices`
    : `${license.seatsUsed} of ${license.seatLimit} devices`
  summary.textContent = `Key ending in ${license.last4} (${license.status}), used on ${seats}.`
}

document.getElementById('license-deactivate').addEventListener('click', async () => {
  try {
    await bill.deactivateLicense()
    message.textContent = 'License removed from this device.'
  } catch {
    message.textContent = 'Could not remove the license. Try again.'
  }
})

bill.onChange(render)
render(await bill.getUser())

bill.deactivateLicense() frees this install’s seat and resolves with license: null and without the license entitlement. bill.onChange fires in every open context, so the popup and options page update together.

Step 5: Let buyers manage devices in the portal

The device a buyer wants to free is often one they no longer have: a laptop that died, a browser they reinstalled. That’s what the customer portal is for. Add a button that calls bill.openPortal():

document.getElementById('manage').addEventListener('click', () => bill.openPortal())

In the portal, buyers see each key with its last four characters, status, expiry and the devices using it (with the labels you passed to activateLicense). They can reveal the full key to copy it to a new device and click Remove device to free a seat. Changes reach your extension on its next refresh. Details are in Customer portal.

Refunds, revocation and expiry

Keys follow the order they came from:

  • A full refund revokes the key along with the purchase’s access. On a partial refund you choose whether the buyer keeps access.
  • A reversed payment (a chargeback you lost) also revokes it.
  • From Customers → Licenses you can revoke or reinstate a key, change its seat limit or expiry, and remove individual activations. Every change is recorded in the audit log.
  • For a subscription, the key stays valid while the subscription grants access. For a one-time price with a duration, the key expires that many days after payment.

Installs that activated a revoked key lose access on their next refresh, and trying to activate it again fails with license_revoked. See Refunds & disputes.

Validate a key from your own server

If your extension talks to your own backend, validate keys there with a secret API key. Never ship an sk_ key in the extension.

curl https://api.extensionbill.com/v1/licenses/7KQ2-M9XD-4RTB-H8VE/validate \
  -H "Authorization: Bearer sk_test_…"

The response includes valid, status, the product with its entitlement key, seatLimit, seatsUsed and expiresAt. valid is true only when the key exists in that environment and is active; sandbox keys validate only with sk_test_ keys. If you’d rather react to changes than poll, subscribe to the license.created, license.activated, license.deactivated and license.revoked webhooks.

Summary

To add license keys to a Chrome extension without building a license server:

  1. Turn on License keys for the product and pick a seat limit.
  2. Call bill.activateLicense(key, label) from a form, and handle seat_limit_reached with a pointer to the portal.
  3. Keep gating features with bill.hasAccess(user, 'pro').
  4. Offer bill.deactivateLicense() and bill.openPortal() so buyers manage their own devices.

The full reference is in License keys. Keep email restore next to the key field for buyers who would rather not keep a key at all.