AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

feat(auth): verify Playground prompt & wait for QR-code verification before closing Camoufox login (隔离登录关闭前自动测试 Playground 并等待 QR 验证)

Open Madarchik09 opened this issue 2 weeks ago • 1 comments

背景与问题 (Background & Problem)

在使用 Camoufox 隔离登录(管理端添加/登录账户或 istudio2api setup --login)时,目前一旦用户输入完 Google 账号密码并跳转到 https://aistudio.google.com 取得基础 Cookie(如 SAPISID),Camoufox 就会立即抓取 storage-state.json 并自动关闭浏览器窗口。

但在实际使用中,Google AI Studio 经常不会在登录 Google 账号时立即弹出验证,而是在首次在 Playground 发送请求(GenerateContent)时才触发二次验证 / 手机扫码验证(跳转到 https://aistudio.google.com/verify-account 或弹出 QR 码验证,接口返回 HTTP 403, Code 7: Your account must be verified before it can continue using the Gemini API)。

由于 Camoufox 在登录完成后立刻关闭,用户没机会在该账户对应的隔离指纹浏览器中看到并完成 QR 码验证,导致保存的会话在实际调用时报错 403 verification 或卡住。


建议改进流程 (Proposed Workflow)

希望在 Camoufox 隔离登录流程(internal/camoufoxnative/)保存 Cookie 并关闭窗口前,增加一步 Playground 自动实测与验证等待:

  1. 输入账号密码登录:用户在可见的 Camoufox 窗口中输入账号密码,完成 Google 登录并进入 istudio.google.com/prompts/new_chat。
  2. 自动在 Playground 发送测试文本:Camoufox 不立即关闭,而是自动在 Playground 输入框填入简短测试词(例如 hi)并触发运行,检查页面或响应状态:
    • 情况 A(无 QR 码 / 无需二次验证):如果正常开始响应且未出现 /verify-account 或 QR 码验证弹窗,则立即抓取最新的 Cookie 与 Token(storage-state.json)并自动关闭 Camoufox 窗口。
    • 情况 B(出现 QR 码 / /verify-account 验证):保持 Camoufox 窗口打开,等待用户在窗口内扫码完成验证;当检测到用户完成验证并成功通过 Playground 测试后,再抓取更新后的 Cookie 与 Token 并自动关闭窗口。

English Summary

Currently, during Camoufox isolated login, the browser window closes immediately after Google sign-in as soon as istudio.google.com loads and SAPISID cookies are present. However, Google AI Studio often triggers its QR-code / account verification challenge (/verify-account or HTTP 403 Code 7: Your account must be verified...) only when a prompt is actually submitted in Playground, not during initial sign-in.

Proposal:

  1. After the user logs in with their credentials in Camoufox and reaches Playground, automatically submit a short test prompt in Playground before closing the window.
  2. If no QR-code / verification prompt appears and Playground responds normally: automatically capture cookies/tokens (storage-state.json) and close Camoufox.
  3. If a QR-code / /verify-account challenge appears: keep the Camoufox window open so the user can complete the QR verification inside the isolated browser profile. Once verification is completed, capture the updated cookies/tokens and close Camoufox automatically.

Madarchik09 avatar Nov 16 '26 17:11 Madarchik09

Added in v0.3.14: isolated login now saves the account right away and checks it in the background. If Google asks for verification, the login window stays on the verification page so you can scan the QR code, and the Accounts page has a Verify button (works for Chrome, cookie, and isolated-login accounts).

Mag1cFall avatar Nov 22 '26 13:11 Mag1cFall