[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7AW8HDZ4N8SWMADV50N0P2K":3,"skill-same:01M7AW8HDZ4N8SWMADV50N0P2K":87},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":34,"commitSha":35,"skillDirectory":36,"forksCount":14,"repositoryHtmlUrl":37,"repositoryHomepageUrl":6,"ownerHtmlUrl":38,"ownerBlogUrl":6,"ownerDescription":39,"updatedAt":40,"install":41,"resources":54},"01M7AW8HDZ4N8SWMADV50N0P2K","clerk-chrome-extension-patterns",null,"Chrome Extension auth with @clerk\u002Fchrome-extension -- popup\u002Fsidepanel setup, syncHost for OAuth\u002FSAML via web app, createClerkClient for service workers and headless extensions, stable CRX ID. Triggers on: Chrome extension auth, Plasmo clerk, popup sign-in, syncHost, background service worker token, createClerkClient, headless extension.","dbillion\u002Fhermes-skills-public","dbillion","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F49393855?v=4","01M7AVH8QPGCM8WKWS22TRT0T6","Oludayo Adeoye","01M7AVH8RD1JJWA0YS9CFEWAV9",0,"MIT","https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills-external\u002Fclerk-chrome-extension-patterns\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: clerk-chrome-extension-patterns\ndescription: 'Chrome Extension auth with @clerk\u002Fchrome-extension -- popup\u002Fsidepanel\n  setup, syncHost for OAuth\u002FSAML via web app, createClerkClient for service workers\n  and headless extensions, stable CRX ID. Triggers on: Chrome extension auth, Plasmo\n  clerk, popup sign-in, syncHost, background service worker token, createClerkClient,\n  headless extension.'\nlicense: MIT\nallowed-tools: WebFetch\ncompatibility: Requires PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY (Plasmo prefix for public env vars) and CLERK_FRONTEND_API.\nmetadata:\n  author: clerk\n  version: 2.0.0\n  references:\n  - references\u002Fsync-host.md\n  - references\u002Fcreate-clerk-client.md\n  - references\u002Fcontent-scripts.md\n  - references\u002Fheadless-extension.md\n---\n\n# Chrome Extension Patterns\n\n## CRITICAL RULES\n\n1. OAuth (Google, GitHub, etc.) and SAML are NOT supported in popups or side panels -- use `syncHost` to delegate auth to your web app\n2. Email links (magic links) don't work in popups -- the popup closes when the user clicks outside, resetting sign-in state\n3. Side panels don't auto-refresh auth state -- users must close and reopen the side panel after signing in via the web app\n4. Service workers and content scripts have NO access to Clerk React hooks -- use `createClerkClient()` or message passing\n5. Extension URLs use `chrome-extension:\u002F\u002F` not `http:\u002F\u002F` -- all redirect URLs must use `chrome.runtime.getURL('.')`\n6. Without a stable CRX ID, every rebuild breaks auth -- configure `key` in manifest BEFORE deploying\n7. Content scripts cannot use Clerk directly due to origin restrictions -- Clerk enforces strict allowed origins\n8. Bot protection must be DISABLED in Clerk Dashboard -- Cloudflare bot detection is not supported in extension environments\n\n## Authentication Options\n\n| Method | Popup | Side Panel | syncHost (with web app) |\n|--------|-------|------------|------------------------|\n| Email + OTP | Yes | Yes | Yes |\n| Email + Link | No | No | Yes |\n| Email + Password | Yes | Yes | Yes |\n| Username + Password | Yes | Yes | Yes |\n| SMS + OTP | Yes | Yes | Yes |\n| OAuth (Google, GitHub, etc.) | **NO** | **NO** | **YES** |\n| SAML | **NO** | **NO** | **YES** |\n| Passkeys | Yes | Yes | Yes |\n| Google One Tap | No | No | Yes |\n| Web3 | No | No | Yes |\n\n## Quick Start (Plasmo)\n\n```bash\nnpx create-plasmo --with-tailwindcss --with-src my-extension\ncd my-extension\nnpm install @clerk\u002Fchrome-extension\n```\n\nEnable **Native API** in Clerk Dashboard under Native applications. Required for all extension integrations.\n\n`.env.development`:\n```\nPLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...\nCLERK_FRONTEND_API=https:\u002F\u002Fyour-app.clerk.accounts.dev\n```\n\n`src\u002Fpopup.tsx`:\n```tsx\nimport { ClerkProvider, Show, SignInButton, SignUpButton, UserButton } from '@clerk\u002Fchrome-extension'\n\nconst PUBLISHABLE_KEY = process.env.PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY\nconst EXTENSION_URL = chrome.runtime.getURL('.')\n\nif (!PUBLISHABLE_KEY) {\n  throw new Error('Missing PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY')\n}\n\nfunction IndexPopup() {\n  return (\n    \u003CClerkProvider\n      publishableKey={PUBLISHABLE_KEY}\n      afterSignOutUrl={`${EXTENSION_URL}\u002Fpopup.html`}\n      signInFallbackRedirectUrl={`${EXTENSION_URL}\u002Fpopup.html`}\n      signUpFallbackRedirectUrl={`${EXTENSION_URL}\u002Fpopup.html`}\n    >\n      \u003CShow when=\"signed-out\">\n        \u003CSignInButton mode=\"modal\" \u002F>\n        \u003CSignUpButton mode=\"modal\" \u002F>\n      \u003C\u002FShow>\n      \u003CShow when=\"signed-in\">\n        \u003CUserButton \u002F>\n      \u003C\u002FShow>\n    \u003C\u002FClerkProvider>\n  )\n}\n\nexport default IndexPopup\n```\n\nUse `mode=\"modal\"` for `SignInButton` -- navigating to a separate page breaks the popup flow.\n\n## syncHost -- Sync Auth with Web App\n\nUse this when you need OAuth, SAML, or want the extension to reflect sign-in from your web app.\n\n**How it works**: The extension reads the Clerk session cookie from your web app's domain via `host_permissions`.\n\n**Step 1 -- Environment variables:**\n\n`.env.development`:\n```\nPLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...\nCLERK_FRONTEND_API=https:\u002F\u002Fyour-app.clerk.accounts.dev\nPLASMO_PUBLIC_CLERK_SYNC_HOST=http:\u002F\u002Flocalhost\n```\n\n`.env.production`:\n```\nPLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_...\nCLERK_FRONTEND_API=https:\u002F\u002Fclerk.your-domain.com\nPLASMO_PUBLIC_CLERK_SYNC_HOST=https:\u002F\u002Fclerk.your-domain.com\n```\n\n**Step 2 -- Add `syncHost` prop:**\n\n```tsx\nconst SYNC_HOST = process.env.PLASMO_PUBLIC_CLERK_SYNC_HOST\n\n\u003CClerkProvider\n  publishableKey={PUBLISHABLE_KEY}\n  syncHost={SYNC_HOST}\n  afterSignOutUrl=\"\u002F\"\n  routerPush={(to) => navigate(to)}\n  routerReplace={(to) => navigate(to, { replace: true })}\n>\n```\n\n**Step 3 -- Configure `host_permissions` in `package.json`:**\n\n```json\n{\n  \"manifest\": {\n    \"key\": \"$CRX_PUBLIC_KEY\",\n    \"permissions\": [\"cookies\", \"storage\"],\n    \"host_permissions\": [\n      \"$PLASMO_PUBLIC_CLERK_SYNC_HOST\u002F*\",\n      \"$CLERK_FRONTEND_API\u002F*\"\n    ]\n  }\n}\n```\n\n**Step 4 -- Add extension ID to web app's allowed origins via Clerk API:**\n\n```bash\ncurl -X PATCH https:\u002F\u002Fapi.clerk.com\u002Fv1\u002Finstance \\\n  -H \"Authorization: Bearer YOUR_SECRET_KEY\" \\\n  -H \"Content-type: application\u002Fjson\" \\\n  -d '{\"allowed_origins\": [\"chrome-extension:\u002F\u002FYOUR_EXTENSION_ID\"]}'\n```\n\n**Hide unsupported auth methods in popup when using syncHost:**\n\n```tsx\n\u003CSignIn\n  appearance={{\n    elements: {\n      socialButtonsRoot: 'plasmo-hidden',\n      dividerRow: 'plasmo-hidden',\n    },\n  }}\n\u002F>\n```\n\nFull guide: `references\u002Fsync-host.md`\n\n## createClerkClient() for Vanilla JS \u002F Service Workers\n\nImport from `@clerk\u002Fchrome-extension\u002Fclient` (not `@clerk\u002Fchrome-extension`).\n\n**Background service worker** (`src\u002Fbackground\u002Findex.ts`):\n\n```typescript\nimport { createClerkClient } from '@clerk\u002Fchrome-extension\u002Fclient'\n\nconst publishableKey = process.env.PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY\n\nasync function getToken(): Promise\u003Cstring | null> {\n  const clerk = await createClerkClient({\n    publishableKey,\n    background: true,\n  })\n  if (!clerk.session) return null\n  return await clerk.session.getToken()\n}\n\nchrome.runtime.onMessage.addListener((request, sender, sendResponse) => {\n  getToken()\n    .then((token) => sendResponse({ token }))\n    .catch((error) => {\n      console.error('[Background] Error:', JSON.stringify(error))\n      sendResponse({ token: null })\n    })\n  return true\n})\n```\n\nThe `background: true` flag keeps sessions fresh even when popup\u002Fsidepanel is closed. Without it, tokens expire after 60 seconds.\n\n**Popup with vanilla JS** (`src\u002Fpopup.ts`):\n\n```typescript\nimport { createClerkClient } from '@clerk\u002Fchrome-extension\u002Fclient'\n\nconst EXTENSION_URL = chrome.runtime.getURL('.')\nconst POPUP_URL = `${EXTENSION_URL}popup.html`\n\nconst clerk = createClerkClient({ publishableKey })\n\nclerk.load({\n  afterSignOutUrl: POPUP_URL,\n  signInForceRedirectUrl: POPUP_URL,\n  signUpForceRedirectUrl: POPUP_URL,\n  allowedRedirectProtocols: ['chrome-extension:'],\n}).then(() => {\n  clerk.addListener(render)\n  render()\n})\n```\n\nFull guide: `references\u002Fcreate-clerk-client.md`\n\n## Headless Extension (no popup, no side panel)\n\nFor extensions that run entirely in the background and sync with a web app.\n\nUses `syncHost` + `createClerkClient` with `background: true` to read auth state from the web app's cookies.\n\n```typescript\nimport { createClerkClient } from '@clerk\u002Fchrome-extension\u002Fclient'\n\nconst publishableKey = process.env.PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY\nconst syncHost = process.env.PLASMO_PUBLIC_CLERK_SYNC_HOST\n\nasync function getAuthenticatedUser() {\n  const clerk = await createClerkClient({\n    publishableKey,\n    syncHost,\n    background: true,\n  })\n  return clerk.user\n}\n```\n\nRequires `host_permissions` for the sync host domain in `package.json`.\n\nFull guide: `references\u002Fheadless-extension.md`\n\n## Content Scripts\n\nContent scripts run in an isolated JavaScript world injected into web pages. **Clerk cannot be used directly** -- origin restrictions prevent it.\n\nUse message passing to request auth state from the background service worker:\n\n```typescript\n\u002F\u002F content.ts\nasync function getToken(): Promise\u003Cstring | null> {\n  return new Promise((resolve) => {\n    chrome.runtime.sendMessage({ type: 'GET_TOKEN' }, (response) => {\n      resolve(response?.token ?? null)\n    })\n  })\n}\n\nasync function main() {\n  const token = await getToken()\n  if (!token) return\n  \u002F\u002F use token for authenticated API calls\n}\n\nmain()\n```\n\nFull guide: `references\u002Fcontent-scripts.md`\n\n## Stable CRX ID\n\nWithout a pinned key, Chrome derives the CRX ID from a random key at build time. This rotates every rebuild, breaking allowed origins.\n\n**Option A -- Plasmo Itero (recommended):**\n1. Visit [Plasmo Itero Generate Keypairs](https:\u002F\u002Fitero.plasmo.com\u002Fext\u002Fgenerate-keypairs)\n2. Click \"Generate KeyPairs\" -- save Private Key securely, copy Public Key and CRX ID\n\n**Option B -- OpenSSL:**\n```bash\nopenssl genrsa -out key.pem 2048\n# Use Plasmo Itero to convert or extract the public key in correct format\n```\n\n**`.env.chrome`:**\n```\nCRX_PUBLIC_KEY=\"\u003CPUBLIC KEY from Itero>\"\n```\n\n**`package.json`:**\n```json\n{\n  \"manifest\": {\n    \"key\": \"$CRX_PUBLIC_KEY\",\n    \"permissions\": [\"cookies\", \"storage\"],\n    \"host_permissions\": [\n      \"http:\u002F\u002Flocalhost\u002F*\",\n      \"$CLERK_FRONTEND_API\u002F*\"\n    ]\n  }\n}\n```\n\nAdd `chrome-extension:\u002F\u002FYOUR_STABLE_CRX_ID` to Clerk Dashboard > Allowed Origins.\n\n## Token Cache (persist across popup closes)\n\n```tsx\nconst tokenCache = {\n  async getToken(key: string) {\n    const result = await chrome.storage.local.get(key)\n    return result[key] ?? null\n  },\n  async saveToken(key: string, token: string) {\n    await chrome.storage.local.set({ [key]: token })\n  },\n  async clearToken(key: string) {\n    await chrome.storage.local.remove(key)\n  },\n}\n\n\u003CClerkProvider publishableKey={PUBLISHABLE_KEY} tokenCache={tokenCache}>\n```\n\n| Storage type | Scope | Clears on |\n|---|---|---|\n| `chrome.storage.local` | Device | Uninstall or manual clear |\n| `chrome.storage.session` | Session | Browser close |\n| `chrome.storage.sync` | All devices | Uninstall (size-limited, 8KB) |\n| `localStorage` | Popup only | Popup close -- do not use for auth |\n\n## Common Pitfalls\n\n| Symptom | Cause | Fix |\n|---------|-------|-----|\n| Redirect loop on sign-in | Missing CRX URL in ClerkProvider props | Set `afterSignOutUrl`, `signInFallbackRedirectUrl` |\n| OAuth button not working | OAuth not supported in popup | Use `syncHost` to delegate to web app |\n| Auth state stale after web app sign-in | `syncHost` not configured | Add `syncHost` prop + `host_permissions` |\n| Side panel shows signed-out after web sign-in | Known limitation | User must close and reopen the side panel |\n| Background can't get token after 60s | Session expired, no background refresh | Use `createClerkClient({ background: true })` |\n| Content script can't access Clerk | Isolated world + origin restrictions | Use message passing to background service worker |\n| Auth breaks after rebuild | CRX ID rotated | Configure stable key via `.env.chrome` |\n| `PLASMO_PUBLIC_` var undefined | Wrong env file | Use `.env.development`, not `.env` |\n| Bot protection errors | Cloudflare not supported in extensions | Disable bot protection in Clerk Dashboard |\n| Token cache not persisting | Using `localStorage` in popup | Use `chrome.storage.local` or pass `tokenCache` prop |\n\n## Plan Requirements\n\n| Feature | Plan |\n|---------|------|\n| Basic popup auth (email\u002Fpassword, OTP) | Free |\n| Passkeys | Free |\n| syncHost | Requires Pro (custom domain) |\n| OAuth through syncHost | Pro + OAuth configured on web app |\n| SAML through syncHost | Enterprise |\n| Bot protection | N\u002FA -- must be disabled for extensions |\n\n## See Also\n\n- `clerk-setup` - Initial Clerk install\n- `clerk-custom-ui` - Custom flows & appearance\n","# Chrome Extension Patterns\n\n## CRITICAL RULES\n\n1. OAuth (Google, GitHub, etc.) and SAML are NOT supported in popups or side panels -- use `syncHost` to delegate auth to your web app\n2. Email links (magic links) don't work in popups -- the popup closes when the user clicks outside, resetting sign-in state\n3. Side panels don't auto-refresh auth state -- users must close and reopen the side panel after signing in via the web app\n4. Service workers and content scripts have NO access to Clerk React hooks -- use `createClerkClient()` or message passing\n5. Extension URLs use `chrome-extension:\u002F\u002F` not `http:\u002F\u002F` -- all redirect URLs must use `chrome.runtime.getURL('.')`\n6. Without a stable CRX ID, every rebuild breaks auth -- configure `key` in manifest BEFORE deploying\n7. Content scripts cannot use Clerk directly due to origin restrictions -- Clerk enforces strict allowed origins\n8. Bot protection must be DISABLED in Clerk Dashboard -- Cloudflare bot detection is not supported in extension environments\n\n## Authentication Options\n\n| Method | Popup | Side Panel | syncHost (with web app) |\n|--------|-------|------------|------------------------|\n| Email + OTP | Yes | Yes | Yes |\n| Email + Link | No | No | Yes |\n| Email + Password | Yes | Yes | Yes |\n| Username + Password | Yes | Yes | Yes |\n| SMS + OTP | Yes | Yes | Yes |\n| OAuth (Google, GitHub, etc.) | **NO** | **NO** | **YES** |\n| SAML | **NO** | **NO** | **YES** |\n| Passkeys | Yes | Yes | Yes |\n| Google One Tap | No | No | Yes |\n| Web3 | No | No | Yes |\n\n## Quick Start (Plasmo)\n\n```bash\nnpx create-plasmo --with-tailwindcss --with-src my-extension\ncd my-extension\nnpm install @clerk\u002Fchrome-extension\n```\n\nEnable **Native API** in Clerk Dashboard under Native applications. Required for all extension integrations.\n\n`.env.development`:\n```\nPLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...\nCLERK_FRONTEND_API=https:\u002F\u002Fyour-app.clerk.accounts.dev\n```\n\n`src\u002Fpopup.tsx`:\n```tsx\nimport { ClerkProvider, Show, SignInButton, SignUpButton, UserButton } from '@clerk\u002Fchrome-extension'\n\nconst PUBLISHABLE_KEY = process.env.PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY\nconst EXTENSION_URL = chrome.runtime.getURL('.')\n\nif (!PUBLISHABLE_KEY) {\n  throw new Error('Missing PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY')\n}\n\nfunction IndexPopup() {\n  return (\n    \u003CClerkProvider\n      publishableKey={PUBLISHABLE_KEY}\n      afterSignOutUrl={`${EXTENSION_URL}\u002Fpopup.html`}\n      signInFallbackRedirectUrl={`${EXTENSION_URL}\u002Fpopup.html`}\n      signUpFallbackRedirectUrl={`${EXTENSION_URL}\u002Fpopup.html`}\n    >\n      \u003CShow when=\"signed-out\">\n        \u003CSignInButton mode=\"modal\" \u002F>\n        \u003CSignUpButton mode=\"modal\" \u002F>\n      \u003C\u002FShow>\n      \u003CShow when=\"signed-in\">\n        \u003CUserButton \u002F>\n      \u003C\u002FShow>\n    \u003C\u002FClerkProvider>\n  )\n}\n\nexport default IndexPopup\n```\n\nUse `mode=\"modal\"` for `SignInButton` -- navigating to a separate page breaks the popup flow.\n\n## syncHost -- Sync Auth with Web App\n\nUse this when you need OAuth, SAML, or want the extension to reflect sign-in from your web app.\n\n**How it works**: The extension reads the Clerk session cookie from your web app's domain via `host_permissions`.\n\n**Step 1 -- Environment variables:**\n\n`.env.development`:\n```\nPLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...\nCLERK_FRONTEND_API=https:\u002F\u002Fyour-app.clerk.accounts.dev\nPLASMO_PUBLIC_CLERK_SYNC_HOST=http:\u002F\u002Flocalhost\n```\n\n`.env.production`:\n```\nPLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_...\nCLERK_FRONTEND_API=https:\u002F\u002Fclerk.your-domain.com\nPLASMO_PUBLIC_CLERK_SYNC_HOST=https:\u002F\u002Fclerk.your-domain.com\n```\n\n**Step 2 -- Add `syncHost` prop:**\n\n```tsx\nconst SYNC_HOST = process.env.PLASMO_PUBLIC_CLERK_SYNC_HOST\n\n\u003CClerkProvider\n  publishableKey={PUBLISHABLE_KEY}\n  syncHost={SYNC_HOST}\n  afterSignOutUrl=\"\u002F\"\n  routerPush={(to) => navigate(to)}\n  routerReplace={(to) => navigate(to, { replace: true })}\n>\n```\n\n**Step 3 -- Configure `host_permissions` in `package.json`:**\n\n```json\n{\n  \"manifest\": {\n    \"key\": \"$CRX_PUBLIC_KEY\",\n    \"permissions\": [\"cookies\", \"storage\"],\n    \"host_permissions\": [\n      \"$PLASMO_PUBLIC_CLERK_SYNC_HOST\u002F*\",\n      \"$CLERK_FRONTEND_API\u002F*\"\n    ]\n  }\n}\n```\n\n**Step 4 -- Add extension ID to web app's allowed origins via Clerk API:**\n\n```bash\ncurl -X PATCH https:\u002F\u002Fapi.clerk.com\u002Fv1\u002Finstance \\\n  -H \"Authorization: Bearer YOUR_SECRET_KEY\" \\\n  -H \"Content-type: application\u002Fjson\" \\\n  -d '{\"allowed_origins\": [\"chrome-extension:\u002F\u002FYOUR_EXTENSION_ID\"]}'\n```\n\n**Hide unsupported auth methods in popup when using syncHost:**\n\n```tsx\n\u003CSignIn\n  appearance={{\n    elements: {\n      socialButtonsRoot: 'plasmo-hidden',\n      dividerRow: 'plasmo-hidden',\n    },\n  }}\n\u002F>\n```\n\nFull guide: `references\u002Fsync-host.md`\n\n## createClerkClient() for Vanilla JS \u002F Service Workers\n\nImport from `@clerk\u002Fchrome-extension\u002Fclient` (not `@clerk\u002Fchrome-extension`).\n\n**Background service worker** (`src\u002Fbackground\u002Findex.ts`):\n\n```typescript\nimport { createClerkClient } from '@clerk\u002Fchrome-extension\u002Fclient'\n\nconst publishableKey = process.env.PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY\n\nasync function getToken(): Promise\u003Cstring | null> {\n  const clerk = await createClerkClient({\n    publishableKey,\n    background: true,\n  })\n  if (!clerk.session) return null\n  return await clerk.session.getToken()\n}\n\nchrome.runtime.onMessage.addListener((request, sender, sendResponse) => {\n  getToken()\n    .then((token) => sendResponse({ token }))\n    .catch((error) => {\n      console.error('[Background] Error:', JSON.stringify(error))\n      sendResponse({ token: null })\n    })\n  return true\n})\n```\n\nThe `background: true` flag keeps sessions fresh even when popup\u002Fsidepanel is closed. Without it, tokens expire after 60 seconds.\n\n**Popup with vanilla JS** (`src\u002Fpopup.ts`):\n\n```typescript\nimport { createClerkClient } from '@clerk\u002Fchrome-extension\u002Fclient'\n\nconst EXTENSION_URL = chrome.runtime.getURL('.')\nconst POPUP_URL = `${EXTENSION_URL}popup.html`\n\nconst clerk = createClerkClient({ publishableKey })\n\nclerk.load({\n  afterSignOutUrl: POPUP_URL,\n  signInForceRedirectUrl: POPUP_URL,\n  signUpForceRedirectUrl: POPUP_URL,\n  allowedRedirectProtocols: ['chrome-extension:'],\n}).then(() => {\n  clerk.addListener(render)\n  render()\n})\n```\n\nFull guide: `references\u002Fcreate-clerk-client.md`\n\n## Headless Extension (no popup, no side panel)\n\nFor extensions that run entirely in the background and sync with a web app.\n\nUses `syncHost` + `createClerkClient` with `background: true` to read auth state from the web app's cookies.\n\n```typescript\nimport { createClerkClient } from '@clerk\u002Fchrome-extension\u002Fclient'\n\nconst publishableKey = process.env.PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY\nconst syncHost = process.env.PLASMO_PUBLIC_CLERK_SYNC_HOST\n\nasync function getAuthenticatedUser() {\n  const clerk = await createClerkClient({\n    publishableKey,\n    syncHost,\n    background: true,\n  })\n  return clerk.user\n}\n```\n\nRequires `host_permissions` for the sync host domain in `package.json`.\n\nFull guide: `references\u002Fheadless-extension.md`\n\n## Content Scripts\n\nContent scripts run in an isolated JavaScript world injected into web pages. **Clerk cannot be used directly** -- origin restrictions prevent it.\n\nUse message passing to request auth state from the background service worker:\n\n```typescript\n\u002F\u002F content.ts\nasync function getToken(): Promise\u003Cstring | null> {\n  return new Promise((resolve) => {\n    chrome.runtime.sendMessage({ type: 'GET_TOKEN' }, (response) => {\n      resolve(response?.token ?? null)\n    })\n  })\n}\n\nasync function main() {\n  const token = await getToken()\n  if (!token) return\n  \u002F\u002F use token for authenticated API calls\n}\n\nmain()\n```\n\nFull guide: `references\u002Fcontent-scripts.md`\n\n## Stable CRX ID\n\nWithout a pinned key, Chrome derives the CRX ID from a random key at build time. This rotates every rebuild, breaking allowed origins.\n\n**Option A -- Plasmo Itero (recommended):**\n1. Visit [Plasmo Itero Generate Keypairs](https:\u002F\u002Fitero.plasmo.com\u002Fext\u002Fgenerate-keypairs)\n2. Click \"Generate KeyPairs\" -- save Private Key securely, copy Public Key and CRX ID\n\n**Option B -- OpenSSL:**\n```bash\nopenssl genrsa -out key.pem 2048\n# Use Plasmo Itero to convert or extract the public key in correct format\n```\n\n**`.env.chrome`:**\n```\nCRX_PUBLIC_KEY=\"\u003CPUBLIC KEY from Itero>\"\n```\n\n**`package.json`:**\n```json\n{\n  \"manifest\": {\n    \"key\": \"$CRX_PUBLIC_KEY\",\n    \"permissions\": [\"cookies\", \"storage\"],\n    \"host_permissions\": [\n      \"http:\u002F\u002Flocalhost\u002F*\",\n      \"$CLERK_FRONTEND_API\u002F*\"\n    ]\n  }\n}\n```\n\nAdd `chrome-extension:\u002F\u002FYOUR_STABLE_CRX_ID` to Clerk Dashboard > Allowed Origins.\n\n## Token Cache (persist across popup closes)\n\n```tsx\nconst tokenCache = {\n  async getToken(key: string) {\n    const result = await chrome.storage.local.get(key)\n    return result[key] ?? null\n  },\n  async saveToken(key: string, token: string) {\n    await chrome.storage.local.set({ [key]: token })\n  },\n  async clearToken(key: string) {\n    await chrome.storage.local.remove(key)\n  },\n}\n\n\u003CClerkProvider publishableKey={PUBLISHABLE_KEY} tokenCache={tokenCache}>\n```\n\n| Storage type | Scope | Clears on |\n|---|---|---|\n| `chrome.storage.local` | Device | Uninstall or manual clear |\n| `chrome.storage.session` | Session | Browser close |\n| `chrome.storage.sync` | All devices | Uninstall (size-limited, 8KB) |\n| `localStorage` | Popup only | Popup close -- do not use for auth |\n\n## Common Pitfalls\n\n| Symptom | Cause | Fix |\n|---------|-------|-----|\n| Redirect loop on sign-in | Missing CRX URL in ClerkProvider props | Set `afterSignOutUrl`, `signInFallbackRedirectUrl` |\n| OAuth button not working | OAuth not supported in popup | Use `syncHost` to delegate to web app |\n| Auth state stale after web app sign-in | `syncHost` not configured | Add `syncHost` prop + `host_permissions` |\n| Side panel shows signed-out after web sign-in | Known limitation | User must close and reopen the side panel |\n| Background can't get token after 60s | Session expired, no background refresh | Use `createClerkClient({ background: true })` |\n| Content script can't access Clerk | Isolated world + origin restrictions | Use message passing to background service worker |\n| Auth breaks after rebuild | CRX ID rotated | Configure stable key via `.env.chrome` |\n| `PLASMO_PUBLIC_` var undefined | Wrong env file | Use `.env.development`, not `.env` |\n| Bot protection errors | Cloudflare not supported in extensions | Disable bot protection in Clerk Dashboard |\n| Token cache not persisting | Using `localStorage` in popup | Use `chrome.storage.local` or pass `tokenCache` prop |\n\n## Plan Requirements\n\n| Feature | Plan |\n|---------|------|\n| Basic popup auth (email\u002Fpassword, OTP) | Free |\n| Passkeys | Free |\n| syncHost | Requires Pro (custom domain) |\n| OAuth through syncHost | Pro + OAuth configured on web app |\n| SAML through syncHost | Enterprise |\n| Bot protection | N\u002FA -- must be disabled for extensions |\n\n## See Also\n\n- `clerk-setup` - Initial Clerk install\n- `clerk-custom-ui` - Custom flows & appearance\n",{"name":5,"license":15,"metadata":24,"description":7,"allowed-tools":32,"compatibility":33},{"author":25,"version":26,"references":27},"clerk","2.0.0",[28,29,30,31],"references\u002Fsync-host.md","references\u002Fcreate-clerk-client.md","references\u002Fcontent-scripts.md","references\u002Fheadless-extension.md","WebFetch","Requires PLASMO_PUBLIC_CLERK_PUBLISHABLE_KEY (Plasmo prefix for public env vars) and CLERK_FRONTEND_API.","master","f341c46fed021656175d5c9ccc67a72126e50bfb","skills-external\u002Fclerk-chrome-extension-patterns","https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public","https:\u002F\u002Fgithub.com\u002Fdbillion","I enjoy writing codes,teaching programming, solving problems, tasted automation in Python and never looked back😋😋😋💞","2026-10-14 03:31:55",{"source":8,"skillName":5,"commands":42,"prompt":52,"zipAvailable":53},[43,46,49],{"tool":44,"command":45},"npx","npx skills add dbillion\u002Fhermes-skills-public --skill clerk-chrome-extension-patterns",{"tool":47,"command":48},"bunx","bunx skills add dbillion\u002Fhermes-skills-public --skill clerk-chrome-extension-patterns",{"tool":50,"command":51},"pnpm","pnpm dlx skills add dbillion\u002Fhermes-skills-public --skill clerk-chrome-extension-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills-external\u002Fclerk-chrome-extension-patterns\u002FSKILL.md",true,[55,61,64,67,70,73,77,83],{"path":56,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":59,"sourceHtmlUrl":60},"evals\u002Fevals.json","REFERENCE","参考文档",4935,"https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills-external\u002Fclerk-chrome-extension-patterns\u002Fevals\u002Fevals.json",{"path":30,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":62,"sourceHtmlUrl":63},3204,"https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills-external\u002Fclerk-chrome-extension-patterns\u002Freferences\u002Fcontent-scripts.md",{"path":29,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":65,"sourceHtmlUrl":66},3992,"https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills-external\u002Fclerk-chrome-extension-patterns\u002Freferences\u002Fcreate-clerk-client.md",{"path":31,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":68,"sourceHtmlUrl":69},3811,"https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills-external\u002Fclerk-chrome-extension-patterns\u002Freferences\u002Fheadless-extension.md",{"path":28,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":71,"sourceHtmlUrl":72},4223,"https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills-external\u002Fclerk-chrome-extension-patterns\u002Freferences\u002Fsync-host.md",{"path":74,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":75,"sourceHtmlUrl":76},"templates\u002Fchrome-ext-basic-auth\u002Fpackage.json",450,"https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills-external\u002Fclerk-chrome-extension-patterns\u002Ftemplates\u002Fchrome-ext-basic-auth\u002Fpackage.json",{"path":78,"resourceType":79,"resourceTypeDesc":80,"sizeBytes":81,"sourceHtmlUrl":82},"templates\u002Fchrome-ext-basic-auth\u002Fsrc\u002Fpopup.tsx","OTHER","其他",1138,"https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills-external\u002Fclerk-chrome-extension-patterns\u002Ftemplates\u002Fchrome-ext-basic-auth\u002Fsrc\u002Fpopup.tsx",{"path":84,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":85,"sourceHtmlUrl":86},"templates\u002Fchrome-ext-basic-auth\u002Ftsconfig.json",163,"https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills-external\u002Fclerk-chrome-extension-patterns\u002Ftemplates\u002Fchrome-ext-basic-auth\u002Ftsconfig.json",[88,95,102,111,118,125],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":19},"01M7B25T0V7RBKES86Y3RTXQRN","blocked-page-recovery","Use when a fetch fails: 403\u002F429, paywall, WAF, bot wall.","https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills\u002Fweb\u002Fblocked-page-recovery\u002FSKILL.md",[],[],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":19},"01M7B25DSBBMZRHVD28MAX7N5X","gemini-vision-fallback","Vision fallback: Gemini REST API if vision_analyze blocked.","https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills\u002Fvision\u002Fgemini-vision-fallback\u002FSKILL.md",[],[],{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":106,"licenseFileUrl":107,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":19},"01M7B22XW9QXT2ZWWXVZDFWYZP","twitter-cli","Use twitter-cli for ALL Twitter\u002FX operations — reading tweets, posting, replying, quoting, liking, retweeting, following, searching, user lookups. Invoke whenever user requests any Twitter interaction.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills\u002Ftwitter-cli\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills\u002Ftwitter-cli\u002FSKILL.md",[],[],{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":19},"01M7B22QMWY1B4F7BC114RG4S6","prism-scan","Structural analysis through dynamically generated cognitive lenses. Generates the optimal analytical lens for the specific code\u002Fartifact, then executes it. Finds conservation laws, structural invariants, and concrete bugs that vanilla analysis misses. Use on any code file, system design, or text artifact.","https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills\u002Fts-superhermes-prism-scan\u002FSKILL.md",[],[],{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":19},"01M7B22JA5XCAP1ACT6V50WYR1","prism-reflect","Constraint transparency: analyzes an artifact structurally, then analyzes what its own analysis concealed. Produces a conservation law AND a constraint report showing what was maximized, what was sacrificed, and what to investigate next. The only AI skill that knows what it can't see.","https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills\u002Fts-superhermes-prism-reflect\u002FSKILL.md",[],[],{"skillNo":126,"name":127,"nameZh":6,"description":128,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":129,"categories":130,"keywords":131,"publishedAt":19},"01M7B22EB15M75M4X3C52YGDCC","prism-full","Full Prism: multi-pass structural analysis with mandatory adversarial self-correction. Designs custom analytical passes, executes them with chaining, then attacks its own findings before synthesizing. Use for maximum depth on important code or artifacts.","https:\u002F\u002Fgithub.com\u002Fdbillion\u002Fhermes-skills-public\u002Fblob\u002Fmaster\u002Fskills\u002Fts-superhermes-prism-full\u002FSKILL.md",[],[]]