kushalkambar5/barbiller/clerk-chrome-extension-patterns
Claude Code and agent skill by kushalkambar5/barbiller
- community
Checking that the SKILL.md file is still in the repository.
'Chrome Extension auth with @clerk/chrome-extension -- popup/sidepanel
Install
npx vskill@latest install kushalkambar5/barbiller/clerk-chrome-extension-patternsSKILL.md
The same SKILL.md was published earlier as midudev/autoskills/clerk-chrome-extension-patterns.
Chrome Extension Patterns
CRITICAL RULES
- OAuth (Google, GitHub, etc.) and SAML are NOT supported in popups or side panels -- use
syncHostto delegate auth to your web app - Email links (magic links) don't work in popups -- the popup closes when the user clicks outside, resetting sign-in state
- Side panels don't auto-refresh auth state -- users must close and reopen the side panel after signing in via the web app
- Service workers and content scripts have NO access to Clerk React hooks -- use
createClerkClient()or message passing - Extension URLs use
chrome-extension://nothttp://-- all redirect URLs must usechrome.runtime.getURL('.') - Without a stable CRX ID, every rebuild breaks auth -- configure
keyin manifest BEFORE deploying - Content scripts cannot use Clerk directly due to origin restrictions -- Clerk enforces strict allowed origins
- Bot protection must be DISABLED in Clerk Dashboard -- Cloudflare bot detection is not supported in extension environments
Authentication Options
| Method | Popup | Side Panel | syncHost (with web app) | |
|---|---|---|---|---|
| Email + OTP | Yes | Yes | Yes | |
| Email + Link | No | No | Yes | |
| Email + Password | Yes | Yes | Yes | |
| Username + Password | Yes | Yes | Yes | |
| SMS + OTP | Yes | Yes | Yes | |
| OAuth (Google, GitHub, etc.) | NO | NO | YES | |
| SAML | NO | NO | YES | |
| Passkeys | Yes | Yes | Yes | |
| Google One Tap | No | No | Yes | |
| Web3 | No | No | Yes |
Quick Start (Plasmo)
Enable Native API in Clerk Dashboard under Native applications. Required for all extension integrations.
.env.development:
src/popup.tsx:
Use mode="modal" for SignInButton -- navigating to a separate page breaks the popup flow.
syncHost -- Sync Auth with Web App
Use this when you need OAuth, SAML, or want the extension to reflect sign-in from your web app.
How it works: The extension reads the Clerk session cookie from your web app's domain via host_permissions.
Step 1 -- Environment variables:
.env.development:
.env.production:
Step 2 -- Add `syncHost` prop:
Step 3 -- Configure `host_permissions` in `package.json`:
Step 4 -- Add extension ID to web app's allowed origins via Clerk API:
Hide unsupported auth methods in popup when using syncHost:
Full guide: references/sync-host.md
createClerkClient() for Vanilla JS / Service Workers
Import from @clerk/chrome-extension/client (not @clerk/chrome-extension).
Background service worker (src/background/index.ts):
The background: true flag keeps sessions fresh even when popup/sidepanel is closed. Without it, tokens expire after 60 seconds.
Popup with vanilla JS (src/popup.ts):
Full guide: references/create-clerk-client.md
Headless Extension (no popup, no side panel)
For extensions that run entirely in the background and sync with a web app.
Uses syncHost + createClerkClient with background: true to read auth state from the web app's cookies.
Requires host_permissions for the sync host domain in package.json.
Full guide: references/headless-extension.md
Content Scripts
Content scripts run in an isolated JavaScript world injected into web pages. Clerk cannot be used directly -- origin restrictions prevent it.
Use message passing to request auth state from the background service worker:
Full guide: references/content-scripts.md
Stable CRX ID
Without a pinned key, Chrome derives the CRX ID from a random key at build time. This rotates every rebuild, breaking allowed origins.
Option A -- Plasmo Itero (recommended):
- Visit Plasmo Itero Generate Keypairs
- Click "Generate KeyPairs" -- save Private Key securely, copy Public Key and CRX ID
Option B -- OpenSSL:
`.env.chrome`:
`package.json`:
Add chrome-extension://YOUR_STABLE_CRX_ID to Clerk Dashboard > Allowed Origins.
Token Cache (persist across popup closes)
| Storage type | Scope | Clears on | |
|---|---|---|---|
chrome.storage.local | Device | Uninstall or manual clear | |
chrome.storage.session | Session | Browser close | |
chrome.storage.sync | All devices | Uninstall (size-limited, 8KB) | |
localStorage | Popup only | Popup close -- do not use for auth |
Common Pitfalls
| Symptom | Cause | Fix | |
|---|---|---|---|
| Redirect loop on sign-in | Missing CRX URL in ClerkProvider props | Set afterSignOutUrl, signInFallbackRedirectUrl | |
| OAuth button not working | OAuth not supported in popup | Use syncHost to delegate to web app | |
| Auth state stale after web app sign-in | syncHost not configured | Add syncHost prop + host_permissions | |
| Side panel shows signed-out after web sign-in | Known limitation | User must close and reopen the side panel | |
| Background can't get token after 60s | Session expired, no background refresh | Use createClerkClient({ background: true }) | |
| Content script can't access Clerk | Isolated world + origin restrictions | Use message passing to background service worker | |
| Auth breaks after rebuild | CRX ID rotated | Configure stable key via .env.chrome | |
PLASMO_PUBLIC_ var undefined | Wrong env file | Use .env.development, not .env | |
| Bot protection errors | Cloudflare not supported in extensions | Disable bot protection in Clerk Dashboard | |
| Token cache not persisting | Using localStorage in popup | Use chrome.storage.local or pass tokenCache prop |
Plan Requirements
| Feature | Plan | |
|---|---|---|
| Basic popup auth (email/password, OTP) | Free | |
| Passkeys | Free | |
| syncHost | Requires Pro (custom domain) | |
| OAuth through syncHost | Pro + OAuth configured on web app | |
| SAML through syncHost | Enterprise | |
| Bot protection | N/A -- must be disabled for extensions |
See Also
clerk-setup- Initial Clerk installclerk-custom-ui- Custom flows & appearance
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingweb/.agents/skills/clerk-chrome-extension-patterns/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/kushalkambar5/barbiller/clerk-chrome-extension-patterns)