feat: add login command for no-popup + cookies headless mode#40
Open
cklxx wants to merge 3 commits intojackwener:mainfrom
Open
feat: add login command for no-popup + cookies headless mode#40cklxx wants to merge 3 commits intojackwener:mainfrom
cklxx wants to merge 3 commits intojackwener:mainfrom
Conversation
db7ced5 to
eff1ed6
Compare
Author
|
@jackwener 佬,搞个静默的打开模式 chrome 不弹窗 |
added 3 commits
March 18, 2026 18:29
Implement "不抢窗口 + 有 cookie" flow using Playwright storage state: **Usage:** 1. Run `opencli login` once — opens your Chrome (extension mode), saves all cookies to ~/.opencli/session.json 2. Run `opencli --headless <site> <cmd>` — headless browser with your saved cookies, no popup window **How it works:** - login: connects via extension (has all user cookies), calls browser_storage_state (requires --caps storage) to save full cookie jar (including HttpOnly) to session file - --headless: passes --storage-state to @playwright/mcp so the headless browser context starts with all saved cookies **Changes:** - `src/browser/discover.ts`: add defaultSessionFile() → ~/.opencli/session.json; buildMcpArgs now loads --storage-state when session file exists (headless), accepts caps[] for capability flags, uses --user-data-dir only in CI - `src/browser/page.ts` + `src/types.ts`: add saveStorageState(filename) - `src/browser/mcp.ts` + `src/runtime.ts`: thread caps[] through connect() - `src/main.ts`: add `opencli login` command - `src/browser.test.ts`: add headless buildMcpArgs tests
storageState is only applied in browser.newContext() (isolated context), not in launchPersistentContext() which is the default. Without --isolated, the storage state file is silently ignored and cookies are never loaded.
Code fixes: - discover.ts: fix copy-paste comment error on userDataDir param - main.ts: move headless domain navigation inside runWithTimeout so it is bounded by the command timeout (previously unbounded) README (en + zh-CN): - Highlight no-popup mode as top feature - Add "No-popup mode" quick-start section with opencli login + --headless - Update prerequisites tip to mention login + headless workflow
3d12368 to
dca9adc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
opencli logincommand: opens Chrome via extension mode once to save cookies to~/.opencli/session.json--headlessflag: loads saved cookies via--storage-statefor silent background execution with full login state--isolatedis required with--storage-state(works withnewContext(), notlaunchPersistentContext())Usage
Test Plan
opencli loginsaves session fileopencli --headless bilibili mereturns logged-in user info--storage-statepassed)npm test)