diff --git a/skills/get-api-key/LICENSE.txt b/skills/get-api-key/LICENSE.txt new file mode 100644 index 00000000..f2f43974 --- /dev/null +++ b/skills/get-api-key/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Browserbase, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/skills/get-api-key/SKILL.md b/skills/get-api-key/SKILL.md new file mode 100644 index 00000000..86649ad0 --- /dev/null +++ b/skills/get-api-key/SKILL.md @@ -0,0 +1,232 @@ +--- +name: get-api-key +description: Generic browser-automation skill that navigates an authenticated SaaS dashboard, creates or reveals an API key, and returns the secret. Reads the vendor's own docs first to learn the flow, then drives the UI via the `browse` CLI. Use when the user says "get an API key from ", "grab a token for ", "create an API key on ", or wants to pull a freshly-issued secret from any SaaS without doing it manually. +compatibility: "Requires the `browse` CLI (browse 0.7.1+). For remote-mode (cloud browser) flows, also requires `BROWSERBASE_API_KEY` + `BROWSERBASE_PROJECT_ID` and the companion `cookie-sync` skill. Local-mode flows need Chrome launched with `--remote-debugging-port=9222`." +license: MIT +allowed-tools: Bash +--- + +# Get API Key — Generic SaaS Browser Skill + +## Purpose + +Drive an authenticated SaaS dashboard via the `browse` CLI to extract a working API key — created on the spot, or revealed if the dashboard supports re-showing existing ones. Designed to work on **any** SaaS dashboard by reading the vendor's own docs to learn the flow, then executing it. + +## When to Use + +- User asks for an API key / token / secret from a SaaS site they're already logged into. +- User wants to programmatically rotate keys. +- User wants to provision a key for a script and doesn't want to click through the UI. + +Do NOT use this skill when: +- The user wants to sign up or log in (this skill assumes auth is already established). +- The user needs a service-account or org-level credential gated behind admin approval (out of scope — skill will fail gracefully). + +## Prerequisites — Auth setup (do this FIRST, then call the workflow) + +The skill assumes `browse status` reports `browserConnected: true` and the daemon's current page is the user's authenticated dashboard (NOT a sign-in page). Pick one of two setup paths: + +### Option A — Local Chrome (simplest; uses user's tabs) + +```bash +browse stop # kill any prior daemon +browse open --auto-connect # attach to local Chrome with remote-debugging on +browse get url # confirm you're NOT on /sign-in +``` + +The user's local Chrome must already be logged into the target site and launched with `--remote-debugging-port=9222`. On Chrome 136+ the default profile blocks the debug port unless either `chrome://flags/#allow-remote-debugging-for-primary-user-profile` is enabled or Chrome is launched with an explicit `--user-data-dir`. Trade-off: subsequent `browse` commands hijack the user's tab — use Option B if they're working in Chrome. + +### Option B — Remote (Browserbase cloud; leaves local Chrome alone) + +Requires `BROWSERBASE_API_KEY` + `BROWSERBASE_PROJECT_ID` env vars, plus the `cookie-sync` skill. + +```bash +# 1. Sync cookies from local Chrome into a persistent Browserbase context +node ~/.claude/skills/cookie-sync/scripts/cookie-sync.mjs --persist --domains +# → outputs: "Session ID: " and "Context ID: " — keep both + +# 2. Stop any existing browse daemon, attach to the cloud session via CDP +browse stop +WS_URL="wss://connect.browserbase.com?apiKey=${BROWSERBASE_API_KEY}&sessionId=" +browse open --cdp "$WS_URL" +browse get url # confirm authenticated +``` + +**If cookie-sync can't reach local Chrome** (Chrome 136+ debug-port mitigation, or no local Chrome at all): create a fresh Browserbase session via API, point the user at the live debugger URL, and have them log into the target site manually inside the cloud browser. The persistent context will retain the cookies. + +```bash +# Create session + get live debugger URL +RESP=$(curl -s -X POST "https://api.browserbase.com/v1/sessions" \ + -H "X-BB-API-Key: $BROWSERBASE_API_KEY" -H "Content-Type: application/json" \ + -d "{\"projectId\":\"$BROWSERBASE_PROJECT_ID\",\"keepAlive\":true,\"browserSettings\":{\"context\":{\"id\":\"\",\"persist\":true}}}") +SID=$(echo "$RESP" | python3 -c "import sys,json;print(json.load(sys.stdin)['id'])") +curl -s "https://api.browserbase.com/v1/sessions/$SID/debug" \ + -H "X-BB-API-Key: $BROWSERBASE_API_KEY" \ + | python3 -c "import sys,json;print(json.load(sys.stdin)['debuggerFullscreenUrl'])" +# Send that URL to the user, wait for them to confirm login, then attach browse. +``` + +### ⚠️ Remote-mode caveat: 5-minute idle expiry + +Browserbase sessions die after ~5 minutes of inactivity even with `keepAlive: true`. When this happens, the `browse` daemon **still reports `browserConnected: true`** but every command times out with `spawnSync browse ETIMEDOUT` or `No active page in session`. The persistent context (cookies) survives. Recovery: create a fresh session from the same context ID, reattach `browse` via `--cdp `, resume. To prevent it: send a `browse get url` ping every ~3 minutes during long flows. + +## Browse CLI Reference (browse 0.7.1) + +Once attached (either option), use these — **no env-switching needed**: + +- `browse get url` — confirm where the browser is sitting (also doubles as a keepalive ping) +- `browse open ` — navigate (no flags needed; daemon stays attached) +- `browse snapshot` — accessibility tree; each element gets a `[X-Y]` ref. PRIMARY perception tool. +- `browse click [X-Y]` — click by ref from latest snapshot (include brackets) +- `browse fill ` — fill input AND press Enter (clears existing text — PREFERRED over `type`) +- `browse type ` — type into focused element (no clear; rarely needed) +- `browse select "