Guides Paywall UI

Paywall UI

Drop a ready-made, CSP-safe upgrade screen into your popup or options page with mountPaywall, or build your own from getPlans().

mountPaywall renders a complete upgrade screen from your dashboard products: plans, prices, buy buttons, a free trial button, a restore link and a license key field. Use it when you do not want to design your own upgrade screen.

<!-- popup.html -->
<body style="width: 360px; margin: 0">
  <main id="app" hidden><!-- your paid UI --></main>
  <div id="paywall"></div>
  <script type="module" src="popup.js"></script>
</body>
// popup.js
import { bill } from './bill'
import { mountPaywall } from '@extensionbill/sdk/paywall'

const app = document.querySelector('#app')
let unmountPaywall = null

function render(user) {
  const pro = bill.hasAccess(user)
  app.hidden = !pro

  if (pro && unmountPaywall) {
    unmountPaywall()
    unmountPaywall = null
  } else if (!pro && !unmountPaywall) {
    unmountPaywall = mountPaywall(document.querySelector('#paywall'), bill, {
      title: 'Upgrade to Focus Tabs Pro',
    })
  }
}

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

The shared bill client is set up in the Quick start. Using a framework? Each framework page shows how to mount the paywall as a component and clean it up. Without a bundler, load extensionbill-paywall.global.js and call ExtensionBillPaywall.mountPaywall(…): see Without a bundler.

@extensionbill/sdk/paywall is a separate entry point, so extensions that build their own UI never ship it. mountPaywall is synchronous: it shows a loading state immediately, then loads bill.getPlans() and bill.getUser() and renders the plans.

What it renders

Everything comes from your dashboard:

  • Header with your app icon (HTTPS icons only), the title, the subtitle, and a close button when onClose is set. Your app’s brand color is the accent color.
  • Plans: one card per active product in dashboard order, with its name, description and features as a bullet list. The product marked highlight gets a “Most popular” badge and an accent border.
  • Prices: each price’s formatted label (for example $4.99 / month), plus the PayPal subscription trial length and setup fee when the price has them.
  • Buy buttons: “Buy now” for one-time prices, “Subscribe” for recurring ones. A click calls bill.openCheckout(price.id) and shows a note that the page updates once payment completes.
  • Free trial button, only when your app’s trial is enabled and this install can still start it (trial.available). It calls bill.startTrial(); while the trial runs, a “Free trial: N days left” banner replaces it.
  • Restore link, “Already purchased? Restore”, which calls bill.openRestore().
  • License key field behind “Have a license key?”, which calls bill.activateLicense(key).
  • Paid state: when the user has a plan, a “You’re on Pro.” banner with a Manage subscription button that calls bill.openPortal().

The paywall subscribes to bill.onChange, so it updates itself after a purchase, restore, trial start or license activation, including purchases finished in another tab. Errors (offline, trial_unavailable, license errors such as seat_limit_reached) appear inline under the header. If plans fail to load, it shows the error with a Try again button.

Unmounting

mountPaywall returns a function. Call it to remove the paywall: it clears the shadow root and unsubscribes from bill.onChange. Call it before you remove the host element, and when the user gets access.

Customize

Options

function mountPaywall(el: HTMLElement, bill: ExtensionBillClient, opts?: PaywallOptions): () => void
OptionDefaultDescription
titleUpgrade <app name>Heading at the top. The app name comes from your dashboard.
subtitleUnlock every feature. Secure checkout with PayPal.Line under the heading.
theme'auto''light', 'dark', or 'auto' (follows the system prefers-color-scheme).
onCloseNoneRenders a close button (×) that calls this function. Without it there is no close button.
labelsEnglish defaultsOverride any text the paywall shows. See Labels.

el is the host element. Control its width, margins, height and placement with your own CSS.

Close button on a full page

On an options page, open the paywall from your own “Upgrade” button and pass onClose. onClose does not unmount by itself; it only reports the click, so unmount or hide the host in your handler:

// options.js
import { bill } from './bill'
import { mountPaywall } from '@extensionbill/sdk/paywall'

const host = document.querySelector('#upgrade-panel')
let unmount = null

function closePaywall() {
  unmount?.()
  unmount = null
  host.hidden = true
}

document.querySelector('#open-upgrade').addEventListener('click', () => {
  if (unmount) return
  host.hidden = false
  unmount = mountPaywall(host, bill, { theme: 'light', onClose: closePaywall })
})

Labels

Pass labels to translate or reword any text. Unspecified labels keep their English defaults, exported as DEFAULT_PAYWALL_LABELS from @extensionbill/sdk/paywall. The paywall fills in the placeholders in braces.

KeyDefault
closeClose
loadingLoading plans…
loadErrorCouldn't load plans.
retryTry again
noPlansNo plans are available right now.
popularMost popular
buyBuy now
subscribeSubscribe
freeTrialDays{days}-day free trial
setupFee+ {amount} setup fee
startTrialStart {days}-day free trial
trialStartedYour free trial has started.
trialActiveFree trial: {days} days left
currentPlanYou're on {plan}.
manageManage subscription
restoreAlready purchased? Restore
haveLicenseHave a license key?
licenseLabelLicense key
licensePlaceholderXXXX-XXXX-XXXX-XXXX
activateActivate
activatedLicense activated. Thank you!
checkoutOpenedCheckout opened in a new tab. This page updates automatically once payment completes.
offlineYou're offline. Check your connection and try again.
genericErrorSomething went wrong. Please try again.
mountPaywall(el, bill, {
  title: 'Passe à Pro',
  subtitle: 'Toutes les fonctionnalités. Paiement sécurisé avec PayPal.',
  labels: {
    buy: 'Acheter',
    subscribe: "S'abonner",
    restore: 'Déjà acheté ? Restaurer',
    startTrial: 'Essai gratuit de {days} jours',
  },
})

Use chrome.i18n.getMessage() to feed labels from your extension’s _locales files.

Styling and CSP

The paywall renders inside a shadow root attached to el. Your page’s CSS does not change it, and its CSS does not leak into your page. Use theme to match your UI and style only the host element.

It works with the default Manifest V3 Content Security Policy, so you do not need to relax content_security_policy:

  • DOM nodes are created with createElement and textContent; API strings are never parsed as HTML.
  • Listeners use addEventListener; there are no inline onclick attributes or string handlers.
  • Styles are bundled and injected into the shadow root. Nothing is fetched at runtime except your app icon: no external stylesheet, font or image.

For full control over the look, build your own.

Build a custom paywall

bill.getPlans() returns everything the built-in paywall uses. This example renders plans, prices, a trial button and a restore link, building the DOM with createElement and textContent only:

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

const root = document.getElementById('paywall')

function h(tag, text, className) {
  const node = document.createElement(tag)
  if (text !== undefined) node.textContent = text // never innerHTML
  if (className) node.className = className
  return node
}

function button(text, onClick) {
  const node = h('button', text)
  node.type = 'button'
  node.addEventListener('click', () => onClick().catch((err) => (errorArea.textContent = err.message)))
  return node
}

const errorArea = h('p', undefined, 'error')

function renderPrice(price) {
  const row = h('div', undefined, 'price')
  row.append(h('span', price.nickname ? `${price.nickname}: ${price.formatted}` : price.formatted))
  if (price.trialDays) row.append(h('span', `${price.trialDays}-day free trial`, 'details'))
  row.append(button(price.type === 'recurring' ? 'Subscribe' : 'Buy now', () => bill.openCheckout(price.id)))
  return row
}

function renderPlan(plan) {
  const card = h('article', undefined, plan.highlight ? 'plan plan--highlight' : 'plan')
  if (plan.highlight) card.append(h('span', 'Most popular', 'badge'))
  card.append(h('h2', plan.name))
  if (plan.description) card.append(h('p', plan.description))
  const features = h('ul')
  features.append(...plan.features.map((f) => h('li', f)))
  card.append(features, ...plan.prices.map(renderPrice))
  return card
}

function render({ app, plans, trial }, user) {
  root.style.setProperty('--accent', /^#[0-9a-f]{6}$/i.test(app.brandColor) ? app.brandColor : '#0070BA')
  const nodes = [h('h1', `Upgrade ${app.name}`), errorArea]

  if (user.trial.active) nodes.push(h('p', `Free trial: ${user.trial.daysLeft} days left`))
  else if (trial.enabled && user.trial.available && !user.paid) {
    nodes.push(button(`Start ${trial.days}-day free trial`, () => bill.startTrial()))
  }

  if (user.paid) nodes.push(h('p', `You're on ${user.plan?.name ?? 'a paid plan'}.`))
  else nodes.push(...plans.map(renderPlan))

  nodes.push(button('Already purchased? Restore', () => bill.openRestore()))
  root.replaceChildren(...nodes)
}

const plansResponse = await bill.getPlans()
render(plansResponse, await bill.getUser())
bill.onChange((user) => render(plansResponse, user)) // re-renders after trial, restore or purchase

Easy to miss:

  • Checkout by price.id. Never send amounts from the extension; the server always prices checkout from your dashboard.
  • formatted for display. It already accounts for currency, billing interval and zero-decimal currencies. Prices arrive in integer minor units, so for extras such as price.setupFee use your own formatter and divide by 100 only for currencies with decimals (not JPY, HUF or TWD).
  • Untrusted text. Product names, descriptions and features are typed in your dashboard, but treating every API string as text means a stray < can never become markup or script.
  • Validate the brand color before it reaches CSS, and use app.iconUrl only when it starts with https://.
  • One onChange listener. If you mount and unmount a custom paywall repeatedly, keep the function bill.onChange returns and call it on teardown.
  • More controls. Add a license field with bill.activateLicense(key) (License keys) and map error codes from Error codes.