Frameworks Pick your stack

Pick your stack

Use ExtensionBill from React, Preact, Vue, Svelte, Angular, Solid, Lit or plain JavaScript. One background setup, a tiny binding per framework.

Every binding ships inside @extensionbill/sdk. Pick your stack and follow its page; the setup they all share is on this page.

StackImportAPIGuide
React@extensionbill/sdk/reactuseUser(bill)React
Preact@extensionbill/sdk/preactuseUser(bill)Preact
Vue@extensionbill/sdk/vueuseUser(bill)Vue
Svelte@extensionbill/sdk/svelteuserStore(bill)Svelte
Angular@extensionbill/sdk/angularinjectUser(bill)Angular
Solid@extensionbill/sdk/solidcreateUser(bill)Solid
Lit@extensionbill/sdk/litUserControllerLit
Vanilla JS@extensionbill/sdkcreateUserStore(bill)Vanilla JS
No bundlerextensionbill.global.jsglobal ExtensionBillWithout a bundler

Stack not listed? createUserStore(bill) works with any framework that can subscribe to a value: see Vanilla JS.

Shared setup

You need an app with a sandbox PayPal connection, a product with the entitlement key pro, and your sandbox publishable key (pk_test_…) from Developers → Integrate. The Quickstart sets this up in five minutes.

Manifest permissions

Add "permissions": ["storage", "alarms"] and a background.service_worker. alarms is optional: with it, the SDK refreshes the user state on a schedule. You need no host_permissions. Full example: manifest.json.

Client and background

Create the client once and import it everywhere. Never create a client inside a component: components only share one load when they share one bill.

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

export const bill = ExtensionBill({
  publishableKey: import.meta.env.VITE_EXTENSIONBILL_PUBLISHABLE_KEY,
})
// src/background.ts
import { bill } from './bill'

bill.startBackground()

Call startBackground() once, synchronously, at the top level of the service worker. Manifest V3 stops idle service workers and restarts them when an event arrives, and Chrome only delivers that event to listeners registered during the first run of the script. Inside an await, a then() or an event handler, the worker can restart without the SDK’s listeners: installs are not registered and popups wait for an answer that never comes. More: Start the background.

Use your framework’s binding in UI pages (popup, options page, side panel, new tab page). Content scripts keep the plain API (bill.getUser(), bill.onChange()): see Checking access.

What every binding returns

Each binding exposes the same five members, as plain values, refs, signals or accessors depending on the framework:

MemberMeaning
userThe UserState, null until the first load finishes.
loadingtrue until the first load settles. Later updates replace user, so the UI never falls back to a spinner.
errorThe ExtensionBillError from the last failed load or refresh(), null again after the next successful update.
hasAccess(feature?)With a key, checks that entitlement; without one, checks for any paid access. A running free trial unlocks everything (rules).
refresh()Reloads from the server and returns the new UserState. It rethrows on failure, so call refresh().catch(() => {}) from a button and show error.

Every component that uses the same bill shares one load and one onChange subscription. After a purchase, refund or trial end, every open popup, options page and side panel updates by itself.

Test a purchase

  1. Start your build: npm run dev for Vite, WXT and Plasmo, npm run build for Angular.

  2. Open chrome://extensions, turn on Developer mode, click Load unpacked and pick the output folder from Build tools. WXT loads it for you.

  3. Open the popup, click Upgrade to Pro and pay with a PayPal sandbox buyer account (steps). Find its email and password in PayPal sandbox accounts (PayPal guide: sandbox accounts).

  4. The popup switches to the Pro view as soon as the payment completes, without a reload.

Troubleshooting

  • Stuck on “Loading…”, background_unavailable, or still locked after paying: the service worker is not running the SDK. Check that it calls bill.startBackground() at the top level and that the manifest points at it. Look for errors under Inspect views: service worker on the extension card, and try ExtensionBill({ publishableKey, debug: true }).
  • invalid_publishable_key: the env variable is empty. Check its name and prefix (VITE_, or PLASMO_PUBLIC_ in Plasmo), then restart the dev server.
  • unsupported_context: the page runs outside the extension (for example http://localhost:5173 in a normal tab), or startBackground() runs outside the service worker. Open the popup from the toolbar.
  • 403 extension_not_allowed: your unpacked build has a different extension ID. Add it under Settings → General, or leave the list empty while developing.
  • Cannot find module '@extensionbill/sdk/react' (or another binding): set "moduleResolution": "bundler" in tsconfig.json.

More: FAQ, Error codes.

Build tools

Build toolFrameworksLoad unpacked from
Vite + CRXJSVanilla, React, Preact, Vue, Svelte, Solid, Litdist
WXTVanilla, React, Preact, Vue, Svelte, Solid, Litloaded by npm run dev; npm run build writes .output/chrome-mv3
PlasmoReact, Vue, Sveltebuild/chrome-mv3-dev
Angular CLI + esbuildAngulardist/extension
webpackAnyyour output folder

Every framework page starts with Vite + CRXJS (Angular CLI for Angular). The WXT and Plasmo setup below is the same for every framework; each page lists only its own template and module.

WXT

// wxt.config.ts
import { defineConfig } from 'wxt'

export default defineConfig({
  modules: ['@wxt-dev/module-react'], // your framework's module, see its page
  manifest: { permissions: ['storage', 'alarms'] },
})

Put src/bill.ts from above in utils/bill.ts. WXT reads the same VITE_ variables from .env.development and .env.production. The defineBackground main function runs synchronously at startup, so it counts as top level:

// entrypoints/background.ts
import { bill } from '@/utils/bill'

export default defineBackground(() => {
  bill.startBackground()
})

Your popup goes in entrypoints/popup/ and imports bill from @/utils/bill.

Plasmo

Add the permissions to package.json:

{
  "manifest": {
    "permissions": ["storage", "alarms"]
  }
}

Plasmo only exposes PLASMO_PUBLIC_ variables, through process.env:

# .env.development
PLASMO_PUBLIC_EXTENSIONBILL_PUBLISHABLE_KEY=pk_test_…
// bill.ts
import { ExtensionBill } from '@extensionbill/sdk'

export const bill = ExtensionBill({
  publishableKey: process.env.PLASMO_PUBLIC_EXTENSIONBILL_PUBLISHABLE_KEY!,
})
// background.ts
import { bill } from './bill'

bill.startBackground()

Your popup is the default export of popup.tsx (or popup.vue, popup.svelte). Run npm run dev and load build/chrome-mv3-dev.