如何將 MV3 Chrome 擴充功能由 Lemon Squeezy 遷移至 Polar.sh:零後端 API 對應與取捨
Migrating an MV3 Chrome Extension from Lemon Squeezy to Polar.sh (Zero Backend, API Mapping & Tradeoffs)
作者把一款付費 Manifest V3 Chrome 擴充功能由 Lemon Squeezy 遷至 Polar.sh,整理零後端授權驗證的 API 對應、MV3 陷阱及客戶遷移方案。
Lemon Squeezy permanently closed new store sign-ups on November 16, 2026, is launching its Stripe Managed Payments migration tooling on December 2, 2026, and will stop processing payments, renewals, checkout links, webhooks, and license key validation on March 31, 2027.
Because Stripe Managed Payments does not include built-in software license key generation or validation, browser extension developers who relied on Lemon Squeezy's License API need a replacement that doesn't force them to run a backend server and database.
When Lemon Squeezy announced its sunset, I built a paid Manifest V3 browser extension directly on Polar.sh and mapped out the exact API differences, MV3 pitfalls, and client-side security tradeoffs for developers moving over.
1. Endpoint & Parameter Mapping: Lemon Squeezy → Polar.sh
Polar.sh exposes unauthenticated Customer Portal license endpoints that only require your public organization_id (UUID) — so you never embed a secret API token in your extension bundle.
Endpoint Mapping
| Action | Lemon Squeezy (api.lemonsqueezy.com) |
Polar.sh (api.polar.sh) |
|---|---|---|
| Activate | POST /v1/licenses/activate |
POST /v1/customer-portal/license-keys/activate |
| Validate | POST /v1/licenses/validate |
POST /v1/customer-portal/license-keys/validate |
| Deactivate | POST /v1/licenses/deactivate |
POST /v1/customer-portal/license-keys/deactivate |
(Note: POST /v1/customer-portal/license-keys/deactivate is the public client endpoint requiring key, organization_id, and activation_id. Customers can also self-deactivate devices inside the Polar Customer Portal if enabled.)
Payload & Header Mapping
| Concept | Lemon Squeezy | Polar.sh (Customer Portal API) |
|---|---|---|
| Content-Type | application/x-www-form-urlencoded |
application/json |
| License key |
license_key (required) |
key (required) |
| Organization scope | (not required) |
organization_id (required on all 3 endpoints) |
| Device / instance label (activate) |
instance_name (required) |
label (required on /activate) |
| Activation ID (validate / deactivate) | instance_id |
activation_id (required on /deactivate; only needed on /validate when activation limits are enabled) |
2. Activate vs. Validate (and When You Can Skip Activation)
One subtle difference in Polar.sh: you only need to call /activate if your license key benefit enforces an activation limit (e.g., max 3 devices per key). If your benefit has no activation limit, you can skip /activate entirely and call /validate without activation_id.
When activation limits are enabled, activate once on first entry (note that label is required):
// 1. Activate a device slot (required only when activation limits are enabled)
const activateRes = await fetch(
'https://api.polar.sh/v1/customer-portal/license-keys/activate',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
key: licenseKey,
organization_id: POLAR_PUBLIC_ORG_ID,
label: `Chrome Extension – ${deviceId}`, // required
}),
},
);
const activation = await activateRes.json();
// Persist activation.id in chrome.storage.local for future validate/deactivate calls
Then validate on startup / daily alarm:
// 2. Validate license key
const validateRes = await fetch(
'https://api.polar.sh/v1/customer-portal/license-keys/validate',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
key: licenseKey,
organization_id: POLAR_PUBLIC_ORG_ID,
...(activationId ? { activation_id: activationId } : {}),
// Optional: scope validation to a specific product/tier benefit
benefit_id: EXPECTED_PRO_BENEFIT_ID,
// Optional: increment metered usage if usage limits are enabled
increment_usage: 0,
}),
},
);
const data = await validateRes.json();
Two Easy Bugs to Avoid in Response Handling
-
Check
statusvs.expires_atby billing model:- For subscription license keys, check
data.status === 'granted'— Polar automatically updatesstatus(e.g.,revokedordisabled) when a subscription cancels or refunds, rather than relying onexpires_at. - For one-time license keys with fixed validity, check both
data.status === 'granted'andexpires_at(!data.expires_at || Date.parse(data.expires_at) > Date.now()).
- For subscription license keys, check
-
Verify
benefit_idif you sell multiple tiers or extensions under one Polar organization:- Always check
data.benefit_id === EXPECTED_PRO_BENEFIT_ID(or passbenefit_idin the validation payload). Otherwise, a valid license key from Product A or a cheaper tier in the same organization could unlock Product B.
- Always check
Don't forget to declare host_permissions in manifest.json:
"host_permissions": [
"https://api.polar.sh/*",
"https://sandbox-api.polar.sh/*"
]
3. Handling Existing Lemon Squeezy Customers Before March 31, 2027
Because Lemon Squeezy will completely stop validating license keys on March 31, 2027, leaving legacy validation code in place will lock out existing buyers once the API goes dark.
Export your full Lemon Squeezy customer, order, and license key CSVs well ahead of time, then pick one of two practical cutover paths:
-
Dual-validation grace period + 100% Polar discount code (stays zero-backend):
- Ship an extension update months before March 31, 2027 that validates newly entered keys against Polar.sh while continuing to accept legacy Lemon Squeezy keys during the transition window. After the cutoff, legacy keys can no longer be validated against Lemon Squeezy and only keep working from locally cached validation state — so treat March 31, 2027 as the real deadline for re-claiming.
- Because Polar issues license keys as product benefits attached to a checkout, create a 100% off discount code in Polar — either one shared code capped at your legacy buyer count (simplest, but leakable if posted publicly), or unique single-use codes per buyer generated via the Polar API (safer). I verified this on
sandbox.polar.sh: once a 100% code drops the total to$0, the payment form disappears, only email is required, and Polar immediately grants the license key benefit on checkout completion. Email the code to existing buyers so they can claim their fresh Polar key in seconds, and show a non-blocking banner inside the extension options page prompting them to paste the new key before the cutoff.
-
Temporary legacy-key validation shim (note: this is the only option here that temporarily introduces a tiny backend):
- If you have too many legacy buyers to ask them to re-claim keys, import your exported Lemon Squeezy license keys into a tiny Cloudflare Worker + KV store that keeps validating legacy keys after March 31, 2027, while routing all new buyers directly to Polar.sh's zero-backend endpoints.
(Heads-up for recurring products: **PayPal subscriptions* on Lemon Squeezy cannot be migrated automatically to Stripe or Polar—those subscribers will need to re-checkout with a supported payment method.)*
4. Four Manifest V3 Gotchas That Will Break Your Licensing Flow
Service Worker globals vanish after ~30 seconds of inactivity.
Never cacheisProoractivationIdin a module-level variable. Persist license state inchrome.storage.localand run periodic revalidation viachrome.alarms(e.g., every 24 hours).Never lock out paying users when their Wi-Fi drops (or on rate-limit bursts).
Polar's unauthenticated Customer Portal license endpoints enforce per-minute rate limiting (HTTP429withretry-after), so don't validate on every popup open. Keep Pro unlocked on transientTypeError/429/5xxresponses within a 72-hour offline grace window (Date.now() - lastValidatedAt < 72 * 60 * 60 * 1000) and letchrome.alarmssilently revalidate once the window resets. Only revoke access on definitive server responses (404,status !== 'granted', or an expired one-timeexpires_at).activeTabdoes not work reliably from Side Panel buttons.
If your UI lives in Chrome'ssidePanel, clicking a button inside the panel does not grantactiveTabto the underlying page. Usetabs+ scopedhost_permissionsinstead.Firefox MV3 requires manifest transforms.
If you also ship on Firefox, stripsidePanelfrompermissions, mapside_paneltosidebar_action, usebackground.scriptsinstead ofbackground.service_worker, and includebrowser_specific_settings.gecko.
5. The Honest Security Tradeoff (Client-Side Bypass)
Let's be transparent: any purely client-side license check in a browser extension can be bypassed. Extension JavaScript runs locally on the user's machine — someone with DevTools can inspect it, patch the unpacked bundle, or stub the fetch() response.
So when does zero-backend validation make sense, and when doesn't it?
-
Good fit (
$5–$29local utility extensions): SEO auditors, tab managers, CSS inspectors, export helpers — tools where your marginal server cost per user is$0. You avoid paying for and maintaining a backend, and most paying users won't spend time patching and side-loading an unpacked extension every browser update just to avoid a modest one-time purchase. - Bad fit (API-proxying extensions): If your extension proxies paid LLM APIs or proprietary backend databases, do not rely on client-side checks. Validate the Polar license key on your backend before forwarding any paid API call.
Want to inspect a working reference?
If you want to wire this up yourself from scratch, the endpoints, parameter mappings, and MV3 patterns above are everything you need.
If you'd rather skip building the TypeScript Polar client, 72h offline grace cache, UTC daily trial quota, Chromium + Firefox MV3 builds, and 27 Vitest tests from scratch, I packaged my full working setup (including a live in-browser simulator you can click through without installing anything) here:
https://jas845323.github.io/polarext/
Happy to answer any questions about Polar's sandbox vs. production quirks or MV3 storage/alarm patterns!
來源:DEV Community · dev.to