baoyu-danger-gemini-web
Generates images and text via reverse-engineered Gemini Web API. Supports text generation, image generation from prompts, reference images for vision input, and multi-turn conversations. Use when other skills need image generation backend, or when user requests "generate image with Gemini", "Gemini text generation", or needs vision-capable AI generation.
1How It Works & Mechanism
The implementation is based on a custom-written Gemini Web client (TypeScript port of the open-source gemini_webapi), treating web-based private APIs as an SDK—which enables generating text and images without an official API Key.
| `scripts/gemini-webapi/*` | TypeScript port of `gemini_webapi` (GeminiClient, types, utils) |
Endpoints are concentrated in constants.ts: INIT retrieves the page token, GENERATE uses the StreamGenerate private endpoint, ROTATE_COOKIES rotates session cookies, UPLOAD sends reference images, and BATCH_EXEC routes through batchexecute.
'https://gemini.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate',
The first step of authentication is fetching the SNlM0e access token from the webpage: performs a GET to gemini.google.com/app, extracts it from HTML via regex, and includes it in all subsequent generation requests.
const m = text.match(/\"SNlM0e\":\"(.*?)\"/);
Credentials originate from browser session cookies (__Secure-1PSID / __Secure-1PSIDTS): it first attempts to read a local cookie file, falling back to reading cookies from a browser via CDP, and by default reuses an already running local Chrome debugging session.
const existingCookies = hasExplicitProfile ? null : await fetch_cookies_from_existing_chrome(30_000, verbose);
Cookies and tokens are persisted: cookies.json stores __Secure-1PSID/1PSIDTS, etc., and a background scheduled task refreshes 1PSIDTS via RotateCookies and writes it back to disk.
this.cookies['__Secure-1PSIDTS'] = newTs;
Generation requests are form-encoded POSTs: the body carries at (access token) and f.req (nested JSON array), and the response is chunked streaming text from the web version that must be unpacked to extract the main content.
const body = new URLSearchParams({ at: this.access_token, 'f.req': f_req }).toString();
Multi-turn conversations are implemented by saving Gemini chat metadata into local session files: --sessionId reuses the same metadata to continue conversations, and message history is also recorded in JSON.
Session files stored in data directory under `sessions/<id>.json`.
Using the reverse-engineered interface explicitly requires upfront consent: first-time use requires writing consent.json (accepted + disclaimerVersion 1.0), exiting immediately if declined.
1. Check if consent file exists with `accepted: true` and `disclaimerVersion: "1.0"`
It also serves as an image backend: --image generates images (defaulting to generated.png), --reference/--ref provides vision input, and --promptfiles reads prompts from files, positioning it within the repo as an exceptional 'self-as-backend' skill.
Skills that **are themselves** image-generation backends — currently `baoyu-image-gen`, `baoyu-image-gen` (deprecated), and `baoyu-danger-gemini-web` — do NOT include a `## Image Generation Tools` section.
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| network | gemini.google.com(INIT 页面 + StreamGenerate 私有接口 + batchexecute) |
| network | accounts.google.com(RotateCookies 轮换 1PSIDTS) |
| network | www.google.com(基础页/常量) |
| network | content-push.googleapis.com(参考图上传) |
| package | baoyu-chrome-cdp ^0.1.1(npm,用于发现/启动/接管 Chrome 调试会话并读 cookie) |
| cli | bun / npx(${BUN_X} 运行时) |
| cli | 本机 Chrome/Chromium/Edge 可执行文件(CDP 取 cookie;路径可由 GEMINI_WEB_CHROME_PATH 覆盖) |
4Recommended Governance & Evidence
- SKILL.md / 脚本: Calls undocumented or reverse-engineered private APIs / spoofs client identity
- SKILL.md / 脚本参数: Bypasses automation detection, disables host sandboxes, or skips SSL certificate verification
- SKILL.md / 会话存储: Reads or reuses browser user login states and session cookies
- 本地凭据 / 浏览器配置: Reads user login cookies/sessions/keyrings: browser session cookies: __Secure-1PSID / __Secure-1PSIDTS (from local cookies.json or via CDP Network)
- scripts/: Executes local scripts or commands: scripts/main.ts (run with bun; launches or attaches to Chrome debugging sessions on demand)
- 网络端点: Declares external network access: https://gemini.google.com/app (INIT to retrieve SNlM0e token)
- 本地工作目录: File I/O and artifact output: cookies.json (credential persistence: writes __Secure-1PSID/1PSIDTS)
5Second-Pass Verification
- [ok] 逆向 API 而非官方 API(red 主因之一) — constants.ts 直指 gemini.google.com 的 StreamGenerate 私有路径;get-access-token.ts 用正则从页面抓 SNlM0e;SKILL.md/description 自述 reverse-engineered,README 有 Disclaimer 段落。
- [ok] 读取浏览器 cookie(red 主因之二) — load-browser-cookies.ts 走 CDP(引用 'Network.getCookies')读 cookie;get-access-token.ts 优先本地 cookie 文件,失败回落 CDP;client.ts 在 init/refresh 两处写 cookie 文件。
- [ok] CDP 复用已运行 Chrome 调试会话 — SKILL.md 原文与 load-browser-cookies.ts 的 fetch_cookies_from_existing_chrome(30_000, ...) 一致;另有 hasExplicitProfile 判断(设了 --profile-dir 或 GEMINI_WEB_CHROME_PROFILE_DIR 才跳过复用)。
- [ok] token 落盘 — cookie-file.ts write_cookie_file → writeFile(p, JSON.stringify(payload, null, 2));rotate-1psidts.ts 另写 .cached_1psidts_<sid>.txt。paths.ts 默认数据目录可用 GEMINI_WEB_DATA_DIR/GEMINI_WEB_COOKIE_PATH 覆盖。
- [ok] 无 TLS 降级 / 无 stealth 反检测 / 无任意代码执行 — grep rejectUnauthorized / NODE_TLS / --ignore-certificate 与 webdriver / patchright / blink-features 均零命中;无 eval/new Function/远程脚本加载;Chrome 以本机真实 profile 启动(--remote-debugging-port),未做指纹伪装。
- [ok] consent 门禁存在但为“软门禁” — SKILL.md 要求先建 consent.json 再使用;但门禁由 agent 按文档执行,脚本自身不校验该文件——属文档级约束,已在 risks 写明。
- [ok] meta 元数据 — GitHub API:MIT、25926 stars、pushed_at 2026-09-10T15:13:43Z;本地 HEAD 与 pin 1567581c26ec… 一致。
6Verdict & Scenarios
076923f8aed80181…