Files
all-by-skill/skills/gemini-image-web/SKILL.md
T

6.5 KiB

name, description
name description
gemini-image-web Generate images in Gemini web via browser automation, download results, and collect downloaded files into a local target folder with manifest output. Use when users ask to create Gemini web images, need multiple images generated through repeated requests, or need structured outputs (paths, metadata, dedupe) for downstream publishing workflows.

Gemini Image Web

Workflow

  1. Open Gemini web and check whether the user is logged in.
  2. If not logged in, stop and explicitly ask the user to log in.
  3. If logged in, open 工具 and click 创作图片/制作图片.
  4. Set output directory and target image count.
  5. Send one image-generation prompt per request until target count is reached.
  6. For each request, wait until generation ends (停止回答 button disappears), then download the latest image result.
  7. Collect downloaded files into target folder with batch naming, dedupe, and manifest.
  8. Return file paths, manifest path, and failure summary.

1) Prerequisites

  • Ensure browser session can access Gemini (https://gemini.google.com/app).
  • If login, captcha, or MFA is required, pause and ask user to complete it manually.
  • Use the shared Playwright session policy across all skills:
    • Auto session policy: tools/pw derives one Playwright session per CODEX_THREAD_ID (fallback: PLAYWRIGHT_SESSION_OWNER or explicit --session).
    • Invoke Playwright CLI through /Users/xd/java/xhs/tools/pw; use --session <name> only when explicit multi-session isolation is needed.
  • Decide output directory before generation, for example:
    • /Users/xd/java/xhs/output/gemini-image

Quick run:

python3 scripts/run_image_flow.py \
  --prompt "生成一张电影感赛博朋克街景海报,夜晚霓虹,雨天反光,纵向构图。" \
  --target /Users/xd/java/xhs/output/gemini-image \
  --count 1

2) Open Gemini And Enforce Login Gate

  • Navigate to Gemini app page.
  • Check login state via account/avatar area or login controls.
  • If login controls are present (登录, Sign in, or ServiceLogin URL), stop immediately and ask user to log in.
  • Continue only when login is confirmed.
  • If model selection is needed, choose a model that supports image output.

3) Enter Image Creation Tool

  • Click 工具.
  • Click image tool item by visible text priority:
    • 创作图片
    • 制作图片
    • Create image
    • Image
  • If quick-intent card click is intercepted by overlay, retry via 工具 menu item.
  • If image tool is not present after login is confirmed, stop and report capability unavailable for this account/region/model.

4) Multi-Image Generation Strategy

  • Gemini web currently returns one image per request.
  • If user asks for N images, run N requests in sequence.
  • Keep a shared base prompt, then apply per-image variants only when needed.
  • Record a download_start_ts before each download action.

Prompt construction rules:

  • Keep a single clear subject per prompt.
  • Include visual style, lighting, composition, and aspect ratio.
  • Include banned elements only if user requests negative constraints.

5) Wait For Completion (Explicit End Condition)

  • After submit, wait for generation state to appear.
  • Treat generation as complete only when:
    • 停止回答 button disappears, and
    • latest assistant response has downloadable image action.
  • If refs are stale or state is unclear, re-snapshot and retry once.

6) Download Images

  • Download from the latest assistant response block (not old history blocks).
  • Click 下载完整尺寸的图片.
  • Wait for download completion toast/progress to end before next request.
  • Repeat until target count is reached or retry budget is exhausted.

7) Collect Downloaded Files

Use bundled script:

python3 scripts/collect_downloads.py \
  --source /var/folders/.../playwright-mcp-output/<session-id> \
  --source ~/Downloads \
  --target /ABS/PATH/TO/output/gemini-image \
  --since <download_start_unix_ts> \
  --limit <max_to_collect> \
  --expected-count <required_count> \
  --prefix gemini-image \
  --batch-id <run_id> \
  --prompt "<prompt_used>"

Script behavior:

  • Source strategy:
    • Prefer Playwright temp download directory first.
    • Also scan .playwright-cli and fallback to ~/Downloads.
  • Filters to image extensions (png,jpg,jpeg,webp).
  • Uses batch naming (<prefix>-<batch-id>-NN.ext).
  • Dedupes by SHA-256 (current run + existing target files).
  • Captures dimensions (width, height) and writes JSON manifest.
  • Prints absolute output paths and manifest path.

8) Failure Handling By Step

  • Login step:
    • If login/captcha/MFA blocks, stop and ask user to complete manually.
  • Tool-selection step:
    • If 创作图片 is missing after login, stop and report unsupported capability.
  • Generation step:
    • If failed once, retry once with minimal prompt rewrite.
    • If still failing, record failure reason and continue remaining quota if requested.
  • Completion detection step:
    • If 停止回答 does not disappear within timeout, retry snapshot+wait once.
    • If still stuck, mark timeout and skip this request.
  • Download step:
    • If click intercepted or stale ref, re-snapshot and retry once.
    • If no file detected after timeout, mark download failure for that request.
  • Collection step:
    • If no matching files, return manifest with failure status.
    • If dedupe removes all files, return manifest with no_files_after_dedupe.
    • If collected count < required count, return insufficient_files.

9) Return Output

Return:

  • prompt used
  • target count and successful count
  • absolute file paths for collected files
  • manifest absolute path
  • retries, failures, and skipped duplicates

10) Reliability Rules

  • Re-snapshot after navigation, tool switch, and generation completion.
  • If refs are stale or click intercepted, re-snapshot and retry once.
  • Do not assume static selectors across Gemini updates; rely on visible text and role-first matching.

11) Boundaries

  • Do not bypass login verification, captcha, paywalls, or security checks.
  • Do not submit disallowed or unsafe image prompts.
  • Stop before posting to third-party platforms; this skill only generates and collects images.

Scripts

  • /Users/xd/java/xhs/tools/pw: Shared Playwright CLI entrypoint with per-session lock, auto per-thread session resolution, and shared Chrome CDP defaults.
  • scripts/run_image_flow.py: End-to-end runner (login gate, enter image tool, generate, download image, collect files).
  • scripts/collect_downloads.py: Collect recent downloaded images with fallback sources, dedupe, and manifest.