5.4 KiB
name, description
| name | description |
|---|---|
| gemini-web-generate | Generate images through Gemini web interface via a Puppeteer CLI. Supports text-to-image, image-to-image (single/multi reference), multi-turn conversations, session management, and download-only mode. Use when: (1) User asks to generate images with Gemini, (2) User says 'Gemini 生图', (3) Image-to-image or style transfer, (4) Continuing an existing Gemini image conversation. |
Gemini 网页版生图
通过 Puppeteer CLI (scripts/cli.js) 驱动浏览器完成 Gemini 网页生图全流程。
浏览器由 browser 工具管理(CLI 通过 CDP 连接,默认 http://127.0.0.1:9223,可通过 CDP_URL 环境变量覆盖)。
首次使用:
cd <skill-dir>/scripts && npm install
快速开始
node scripts/cli.js generate --prompt "提示词" --mode single
CLI 自动完成:打开标签页 → 导航 → 粘贴参考图 → 输入提示词 → 发送 → 等待生成 → 下载到 scripts/output/originals/ → 关闭标签页(single 模式)。
生图完成后将图片移到目标位置,通过 message 工具发送。
每次生图/下载成功或失败会自动写入日志:scripts/output/logs/YYYY-MM-DD.log,可 cat 或 tail 查看历史记录。
反检测策略
以下策略基于 openclaw-zero-token 项目研究,降低 Gemini 自动化检测风险。
Profile 装饰
浏览器启动后,修改 Chrome Profile 文件使其看起来像真实用户创建的 Profile(而非空白自动化 Profile):
PROFILE="<user-data-dir>/Local State"
# 修改 profile.info_cache.Default.name 为有意义的名字
# 修改 profile.info_cache.Default.profile_color_seed 为合法的 SkColor 值
OpenClaw browser 工具的 Profile 位于 ~/.openclaw/browser/openclaw/user-data/。
干净退出欺骗
每次生图前,将 Preferences 文件的 exit_type 设为 "Normal"、exited_cleanly 设为 true。防止 Chrome 显示崩溃恢复提示,避免"非正常退出"这种自动化特征。
node scripts/cli.js _clean_exit <profile-path>
# 或直接修改: <profile-path>/Default/Preferences → exit_type="Normal", exited_cleanly=true
AIMD 反封延迟
多轮对话生图时,使用 AIMD 算法控制请求间隔(非固定延迟):
- 成功:间隔减半(不低于 baseDelay 的一半)
- 被限流:间隔翻倍(不超过 maxDelay)
- 每次加 0-5 秒随机抖动
通过环境变量可调:GEMINI_BASE_DELAY=15(秒)、GEMINI_MAX_DELAY=120。
所有生图方式
文生图
node scripts/cli.js generate --prompt "提示词" --mode single
图生图
# 单张参考图
node scripts/cli.js generate --prompt "提示词" --image /path/to/ref.png --mode single
# 多张参考图(逗号分隔,最多 10 张)
node scripts/cli.js generate --prompt "提示词" --images "/path/a.png,/path/b.png" --mode single
参考图路径含空格时,先 cd 到目录再用相对路径。
从文件或管道读取提示词
node scripts/cli.js generate --prompt-file /path/to/prompt.txt --mode single
echo "提示词" | node scripts/cli.js generate --prompt stdin --mode single
多轮对话
# 首轮(不加 --mode,保持标签页)
node scripts/cli.js generate --prompt "画一幅日落"
# 续次(不加 --mode,间隔自动调整)
node scripts/cli.js generate --session <id> --prompt "加入一艘小船"
# 末轮(--mode single 自动关闭)
node scripts/cli.js generate --session <id> --prompt "最终调整" --mode single
通过对话链接继续
node scripts/cli.js generate --chatUrl "https://gemini.google.com/app/xxxx" --prompt "换成水彩风格"
仅下载已有图片
对话已有生成图片时,不加 --prompt 直接下载:
node scripts/cli.js generate --chatUrl "https://gemini.google.com/app/xxxx" --mode single
结果处理
成功
图片在 scripts/output/originals/。移到目标位置后发送。
超时或失败
node scripts/cli.js status --session <id> --wait
| 状态 | 处理 |
|---|---|
done |
node scripts/cli.js download --session <id> |
generating |
继续等待 |
error |
报告错误,调整提示词重试 |
加 --screenshot 可在出错/超时时自动截图辅助诊断。
会话管理
node scripts/cli.js sessions # 列出活跃会话
node scripts/cli.js find_session --chatUrl "<url>" --open # 找回丢失的 session
node scripts/cli.js close --session <id> # 关闭会话
node scripts/cli.js download --session <id> # 下载已生成图片
node scripts/cli.js status --session <id> [--wait] # 检查状态
generate 参数参考
| 参数 | 说明 | 默认值 |
|---|---|---|
--prompt |
提示词。"stdin" 从标准输入读取 |
必填(与 --chatUrl 共用时可省略,进入纯下载模式) |
--prompt-file |
从文件读取提示词 | - |
--image |
单张参考图 | - |
--images |
多张参考图,逗号分隔,最多 10 张 | - |
--session |
复用已有会话 ID | - |
--chatUrl |
Gemini 对话链接 | - |
--mode |
single 生成后关闭标签页 / multi 保持打开 |
multi |
--timeout |
生成超时(毫秒) | 300000 |
--download-timeout |
下载超时(毫秒) | 120000 |
--screenshot |
出错/超时时自动截图 | 关闭 |