[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7AXQ8AKDSRNREMR6MS4HP43":3,"skill-same:01M7AXQ8AKDSRNREMR6MS4HP43":85},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":33,"commitSha":34,"skillDirectory":35,"forksCount":13,"repositoryHtmlUrl":36,"repositoryHomepageUrl":6,"ownerHtmlUrl":37,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":38,"install":39,"resources":52},"01M7AXQ8AKDSRNREMR6MS4HP43","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.","Krishp091205\u002Fgemini-config","Krishp091205","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F307182548?v=4","01M7AXCYY4NQ9WQ7DCT3R5Q5S4","01M7AXCYYR7QFCQQ6BFRKD93YH",0,"MIT","https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002F.agents\u002Fskills\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":14,"metadata":23,"description":7,"allowed-tools":31,"compatibility":32},{"author":24,"version":25,"references":26},"clerk","2.0.0",[27,28,29,30],"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.","main","1f317365436456f9c1039c414a2f6426caabc74c",".agents\u002Fskills\u002Fclerk-chrome-extension-patterns","https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config","https:\u002F\u002Fgithub.com\u002FKrishp091205","2026-08-23 02:02:24",{"source":8,"skillName":5,"commands":40,"prompt":50,"zipAvailable":51},[41,44,47],{"tool":42,"command":43},"npx","npx skills add Krishp091205\u002Fgemini-config --skill clerk-chrome-extension-patterns",{"tool":45,"command":46},"bunx","bunx skills add Krishp091205\u002Fgemini-config --skill clerk-chrome-extension-patterns",{"tool":48,"command":49},"pnpm","pnpm dlx skills add Krishp091205\u002Fgemini-config --skill clerk-chrome-extension-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fclerk-chrome-extension-patterns\u002FSKILL.md",true,[53,59,62,65,68,71,75,81],{"path":54,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":57,"sourceHtmlUrl":58},"evals\u002Fevals.json","REFERENCE","参考文档",4935,"https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fclerk-chrome-extension-patterns\u002Fevals\u002Fevals.json",{"path":29,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":60,"sourceHtmlUrl":61},3204,"https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fclerk-chrome-extension-patterns\u002Freferences\u002Fcontent-scripts.md",{"path":28,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":63,"sourceHtmlUrl":64},3992,"https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fclerk-chrome-extension-patterns\u002Freferences\u002Fcreate-clerk-client.md",{"path":30,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":66,"sourceHtmlUrl":67},3811,"https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fclerk-chrome-extension-patterns\u002Freferences\u002Fheadless-extension.md",{"path":27,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":69,"sourceHtmlUrl":70},4223,"https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fclerk-chrome-extension-patterns\u002Freferences\u002Fsync-host.md",{"path":72,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":73,"sourceHtmlUrl":74},"templates\u002Fchrome-ext-basic-auth\u002Fpackage.json",450,"https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fclerk-chrome-extension-patterns\u002Ftemplates\u002Fchrome-ext-basic-auth\u002Fpackage.json",{"path":76,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":79,"sourceHtmlUrl":80},"templates\u002Fchrome-ext-basic-auth\u002Fsrc\u002Fpopup.tsx","OTHER","其他",1138,"https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fclerk-chrome-extension-patterns\u002Ftemplates\u002Fchrome-ext-basic-auth\u002Fsrc\u002Fpopup.tsx",{"path":82,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":83,"sourceHtmlUrl":84},"templates\u002Fchrome-ext-basic-auth\u002Ftsconfig.json",163,"https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fclerk-chrome-extension-patterns\u002Ftemplates\u002Fchrome-ext-basic-auth\u002Ftsconfig.json",[86,94,101,108,115,122],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":90,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":18},"01M7B0GYVAXB2M99PR4Z3N1WW0","skill-repair","Use this to fix and re-install agent skills that have failed installation.\nThis skill provides the necessary context and permissions to surgically update\nthe `manifest.json` after a fix has been applied.","Apache-2.0","https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002Fskills\u002Fskill-repair\u002FSKILL.md",[],[],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":90,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":18},"01M7B0GQ2CKFX5P1DTV802XMAB","notebook-guidance","This skill guides the use of Jupyter notebooks for data analysis, exploration, and visualization, particularly with BigQuery. It outlines best practices for notebook execution and validation (supporting both cell-by-cell execution and full notebook generation depending on tool availability), library installation, and structuring notebooks for clarity. It also covers specific rules for data cleaning, plotting, and integrating with BigQuery SQL and machine learning workflows.\nRelevant when any of the following conditions are true:\n  1. The user request involves a data analysis, data exploration, data visualization, or data insights task that requires multiple steps, queries, or visualizations to answer.\n  2. The user explicitly requests a notebook (.ipynb).\n  3. You are creating, editing, or executing cells in a Jupyter notebook.\n  4. You need to query BigQuery from within a notebook. DO NOT use the Python BigQuery client library; instead, you MUST use the `%%bqsql` magics explained in this skill.","https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002Fskills\u002Fnotebook-guidance\u002FSKILL.md",[],[],{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":90,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":18},"01M7B0GJ1K1JE2K593JZT4CAY9","ml-best-practices","CRITICAL RULE: You MUST use this skill whenever the task involves any machine learning tasks or data analysis.\nUse this skill if the user's prompt or requirements mention any of the following:\n  * Clustering\n  * Classification\n  * Regression\n  * Time series forecasting\n  * Statistical testing\n  * Model comparison\n  * ML\n  * Data analysis\n\nSQL\u002FBigQuery ML HANDOFF: If the user requires a SQL solution, use this skill to dictate the ANALYSIS STEPS (e.g., markdown analysis cells, visualization logic), but defer to `bigquery` for all SQL syntax.","https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002Fskills\u002Fml-best-practices\u002FSKILL.md",[],[],{"skillNo":109,"name":110,"nameZh":6,"description":111,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":90,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":18},"01M7B0GD7FSN72WCSZ16WEDH42","managing-python-dependencies","Ensures proper Python dependency management, avoiding global `pip install` and\nadhering to project-specific tooling.\n\nUse this skill if any of the following are true:\n  1. Attempting to run `pip install {package_name}`.\n  2. Python packages or dependencies need to be added or modified.\n  3. Initiating a new Python project.\n  4. Creating a new notebook, even if just using BigQuery cells.\n  5. Generating Python code that includes `import` statements for third-party libraries.\n  6. Before executing Python scripts via the terminal to ensure the correct virtual environment is active.","https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002Fskills\u002Fmanaging-python-dependencies\u002FSKILL.md",[],[],{"skillNo":116,"name":117,"nameZh":6,"description":118,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":90,"licenseFileUrl":6,"sourceHtmlUrl":119,"categories":120,"keywords":121,"publishedAt":18},"01M7B0G6CC6JP6QTQGPSTBMJTX","google-cloud-storage-basics","Stores, retrieves, and manages data as objects in Cloud Storage (Google Cloud Storage, or GCS) buckets. Use when you need to interact with Cloud Storage — create or configure buckets, upload, download, stream, or transfer data, organize objects with folders, generate signed URLs, control access (IAM, ACLs, public access prevention), set storage classes and tiering (Standard, Nearline, Coldline, Archive), manage cost and lifecycle, protect data (versioning, encryption\u002FCMEK, retention and Bucket Lock, object holds, soft delete), host static websites, trigger Pub\u002FSub notifications on object changes, mount buckets as a file system (gcsfuse), or optimize storage performance at any scale. Covers the gcloud storage \u002F gsutil CLI, JSON and XML APIs, client libraries, Terraform, and Cloud Storage MCP servers. Don't use for block storage (Persistent Disk), data warehousing\u002Fanalytics (BigQuery), or databases (Cloud SQL, Spanner, Bigtable, Firestore).","https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002Fskills\u002Fgoogle-cloud-storage-basics\u002FSKILL.md",[],[],{"skillNo":123,"name":124,"nameZh":6,"description":125,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":90,"licenseFileUrl":6,"sourceHtmlUrl":126,"categories":127,"keywords":128,"publishedAt":18},"01M7B0G2DF32KW9A77S99QBZ4Q","gcs-security-assessment","Assesses security posture, evaluates risks, and checks SAIF compliance for Google Cloud Storage buckets or projects. Use when the user requests security scans, vulnerability checks, or SAIF assessments. Don't use when: The user is asking about non-GCS resources (Compute Engine, GKE, etc.), investigating a live production outage, or asking general security questions not tied to a specific project or bucket.","https:\u002F\u002Fgithub.com\u002FKrishp091205\u002Fgemini-config\u002Fblob\u002Fmain\u002Fskills\u002Fgcs-security-assessment\u002FSKILL.md",[],[]]