Adds a new browser auth type that captures session cookies from a real Chrome/Playwright session and injects them via the existing mitmproxy path. Bundled providers: x-browser, linkedin-browser. The architecture is clean — CLI side does the browser work, daemon stays headless, mitmproxy path is unchanged.
Correctness
Issue: __cookie_expires_at__ key leaks into stored credentials
In browser.py:477, the reserved key is popped from credentials before building the ConnectionRecord:
This is correct. But _export_connection_values in credential_service.py:432 iterates all record.credentials keys and maps them to env vars — if __cookie_expires_at__ were ever not popped (e.g., future code path), it would export as LINKEDIN___COOKIE_EXPIRES_AT__. Low risk given current code, but the sentinel key name is load-bearing and fragile across two layers.
Issue: _validate_credentials_sync silently falls back to httpx when no page
At browser_login.py:910-918, if page is None, it falls back to an httpx GET with the rendered headers. This is exactly the behavior that _validate_browser_credentials in credential_service.py was fixed to avoid (httpx gets 401/403 from LinkedIn/X with valid cookies). In the _try_existing_cookies step, page is used correctly (passed from context.new_page()), but in the CDP path (_try_live_cdp_session), _validate_credentials_sync is called with no page:
python
if _validate_credentials_sync(context, credentials, validate_url, rendered): # page=None
This means the CDP path does the unreliable httpx validation instead of Playwright's page.request. The CDP path should pass a page from context.pages[0] or skip httpx fallback for browser providers.
Issue: CHROME_NOT_FOUND_HINT string truncation
browser_login.py:650:
python
CHROME_NOT_FOUND_HINT = "Chrome not found. Install Google Chrome (or Chromium/Brave), "
Trailing comma, sentence incomplete. This surfaces directly to users via RuntimeError.
Issue: test_resume_empty_credentials_raises is wrong
At test_browser_flow.py:1704-1711:
python
with pytest.raises(AuthenticationFailedError, match="credentials"):
await flow.resume(provider, "test-agent", "default", session, {"credentials": {}})
browser.py:465-468 only checks if not credentials — an empty dict {} is falsy in Python, so the test passes. But the error message is "Browser resume requires 'credentials' dict" — the test accidentally documents a behavior where an empty dict (no cookies captured) raises correctly, which is fine. However there's no explicit test for the case where credentials are a non-empty dict but missing required keys (validation gap).
Architecture / Design
BrowserAction in schemas.py duplicates BrowserConfig from provider.py
BrowserAction (server schema) and BrowserConfig (auth model) carry identical fields. Changes to BrowserConfig won't automatically propagate to BrowserAction. Consider referencing the model or sharing a base.
_derive_jsessionid in browser_login.py is dead weight
browser_login.py:787-791:
python
def _derive_jsessionid(credentials: dict[str, str]) -> None:
"""Fill ``jsessionid`` from the cookie blob when the named cookie is missing."""
normalized = normalize_browser_credentials(credentials)
credentials.clear()
credentials.update(normalized)
This function modifies in-place but is never called directly — _normalize_extracted_credentials on line 794 just delegates to normalize_browser_credentials without the in-place mutation. The function should be removed or the call site corrected.
Shared browser profile across all browser providers
The PR notes this as an open question. The current shared-profile approach means LinkedIn and X sessions share cookies at the filesystem level. If a provider clears cookies (e.g., on sign-out), it could corrupt the other provider's stored profile. Per-provider profiles or at minimum a browser_data_dir default per provider name would be safer.
resume_session vs resume_login_session in client.py
client.py:278-280 adds resume_session which posts to the same endpoint as the existing resume_login_session (line 276). This is a direct duplicate. The new method should replace or alias the old one, not coexist.
This is Twitter's public client Bearer token, widely known and used by many tools. It's not a secret per se, but hardcoding it in the repo means rotation requires a code change. Worth a comment that this is the public app token, not a user secret.
Cookies in logs
browser_login.py:970-975 logs at logger.info with provider_name but not credentials — that's fine. Double-check that no log path accidentally includes credentials dict contents. The Sensitive() annotation on ConnectionRecord.credentials handles vault serialization but not debug logging in browser_login.py.
authorize / PoP auth not applied to browser resume path
The browser resume calls resume_session which hits /auth/sessions/{id}/resume — this is presumably already PoP-protected, but worth confirming the session resume endpoint enforces the same identity guard as other protected routes.
Code Quality
browser_login.py is 658 lines and imports re locally inside _render_headers_sync (line 886) even though re is in stdlib. Minor — move to top-level import.
_LOGIN_URL_PATTERNS tuple (line 666) would benefit from a comment that it's used for cascade bail-out detection, not security.
The SHARED_BROWSER_DATA_DIR = AUTHSOME_BROWSER_DATA_DIR alias (line 656) with comment "kept for backwards-compat" is pre-emptive — there is no prior version of this code on main. Remove it.
docs/internal/browser-review-guide.md is a useful PR artifact but shouldn't ship in main as an internal/ doc. Move content to CONTRIBUTING.md or docs/guides/, or drop the file after merge.
Test Coverage
Coverage is solid for the daemon/service layer. Missing:
No test for run_browser_login dispatcher logic (the login_mode branching in the main entry point) — these are pure-Python paths mockable without Playwright.
No test for _export_connection_values browser branch in credential_service.py.
No test for the _session_response → BrowserAction path in routes/auth.py.
Summary
This is a well-structured PR with clear separation between CLI browser work and daemon logic. The main issues to address before merging:
Fix CDP validation path — pass a page to _validate_credentials_sync in _try_live_cdp_session to avoid httpx fallback.
Remove _derive_jsessionid — dead function.
Remove SHARED_BROWSER_DATA_DIR alias — no backwards compat needed.
Deduplicate resume_session / resume_login_session in client.py.
Fix truncated CHROME_NOT_FOUND_HINT string.
Decide on browser-review-guide.md — don't ship it in main as-is.
User
Tell me in brief what is it doing?
Assistant
PR #301 adds Browser SSO to authsome — the ability to authenticate with sites like X (Twitter) and LinkedIn that don't have OAuth/API-key flows.
How it works:
authsome login x-browser → launches a real Chrome window via Playwright
User logs in interactively; authsome captures the session cookies
Cookies are stored encrypted in the vault
authsome run -- curl https://x.com/... → mitmproxy injects the right Cookie/CSRF headers automatically
Key design choices:
Browser work stays on the CLI side; the daemon remains headless
Uses a dedicated ~/.authsome/browser-data/ profile, not the user's daily Chrome
Login cascade: try live CDP session → try existing stored cookies (headless) → open visible window
Skips httpx re-validation when cookies haven't expired yet (fixes a false TokenExpiredError that LinkedIn/X were triggering)
User
Why is it 3000 lines of code change? Why does it even need playwright in first place?
Assistant
Why 3000 lines?
The bulk breaks down roughly as:
browser_login.py — 658 lines, the biggest offender. It handles Chrome binary detection (3 OSes), 3 login modes (CDP attach / headless / visible), cookie extraction, domain matching, JSESSIONID quoting, header rendering, and validation — all in one file. A simpler design would just: open visible Chrome, wait for cookies. The 3-step cascade ("already logged in?" → "headless?" → "show window") is an optimization that triples the code.
Tests — ~700 lines, reasonable.
docs/internal/browser-review-guide.md — 221 lines of internal PR documentation that shouldn't be in main at all.
The rest (models, flow, schemas, service hooks) is genuinely small — maybe 200–300 lines of real logic.
So roughly half the diff is either over-engineered cascade logic or shouldn't be in the PR.
Why Playwright at all?
The core need is: launch a real Chrome, let the user log in, read the cookies. Playwright is being used for two things:
Launching Chrome with a controlled profile — you could do this with a raw subprocess call.
Reading cookies after login — this is where it gets harder. The real alternative is reading Chrome's on-disk SQLite cookie database directly. That works, but on macOS the cookies are AES-encrypted via the Keychain, and on Linux via GNOME Keyring — you'd need to decrypt them yourself.
Playwright's real value here is the page.request API for validation — it uses Chrome's actual TLS fingerprint, so LinkedIn/X don't reject it as a bot. If you used httpx to validate, you'd get 403s on valid cookies (exactly the bug this PR fixes).
So Playwright is justified, but the surface it's actually used for is small. The CDP fast-path and headless modes are optimization complexity added on top.
User
we can ask for keychain request directly, its not that hard. User can authorize when loggin in
Assistant
Exactly. The approach would be much simpler:
Open ~/Library/Application Support/Google/Chrome/Default/Cookies (SQLite file)
Request the Chrome Safe Storage key from Keychain — macOS shows one authorization dialog, user clicks Allow
AES-decrypt the cookie values (standard v10 prefix format Chrome uses)
Filter by domain, done
Python library browser-cookie3 already does all of this in ~200 lines. On Linux it's the same via GNOME Keyring, Windows via DPAPI.
What this eliminates from the PR:
Playwright runtime dependency entirely (it's heavy — downloads Chromium or needs system Chrome)
The 658-line browser_login.py with its 3-mode cascade
The page.request validation workaround (you'd use the real cookies from the user's actual session, so they'd actually be valid)
The remaining flow becomes:
authsome login x-browser → read Chrome cookie DB → Keychain prompt once → extract and store
If cookies not found yet → tell user "log in to x.com in Chrome first, then re-run"
Optionally, open x.com in the user's default browser via webbrowser.open() and poll the DB
The whole browser_login.py probably shrinks to 80-100 lines. No new heavyweight runtime dep.
This is a reasonable blocker to raise on the PR — the Playwright approach solves a problem that doesn't need solving that way.
User
what dies the library do? browser-cookie3 ?
Assistant
Let me look it up.
Assistant
Key things it does:
Finds Chrome's SQLite cookie database at the known OS path
On macOS: shells out to security find-generic-password -wa 'Chrome' to get the encryption key from Keychain, then decrypts with AES-128-CBC + PBKDF2
On Linux: queries GNOME Keyring (or falls back to hardcoded "peanuts" for systems without a keyring)
On Windows: calls Windows DPAPI via ctypes
Returns a standard Python http.cookiejar.CookieJar you can filter by domain
One important caveat the agent flagged: Chrome locks the SQLite DB while it's running. The library copies the file to a temp path first to work around this — that's the standard trick.
Bottom line for this PR: You'd replace Playwright with something like:
python
import browser_cookie3
cookies = browser_cookie3.chrome(domain_name=".linkedin.com")
That's it. The Keychain dialog appears once on first run. No profile management, no headless Chrome, no polling loop. The user's existing logged-in session is used directly.
The only real limitation is if the user isn't already logged in — then you'd still need to webbrowser.open() the login URL and ask them to come back. But that's a much lighter UX than spinning up Playwright.
User
Make a plan on how the same implememntation would be done on the main branch. Ignore that PR. The core goal is to run browser automations as well
Assistant
Let me explore the main branch codebase in parallel before designing anything.
Assistant
Now I have enough to design the plan. Let me write it.
Assistant
Good constraint. That changes the design: the cookie-reading and login logic should live in auth/, not cli/. I'll revise the plan accordingly before writing the plan file.
Assistant
Now I have everything I need. Let me write the plan file.
Assistant
Let me start implementing. I'll read the key files first, then work through the plan in order.
Assistant
Good, I have everything I need. Let me implement all changes now.
Assistant
Now create browser_cookies.py:
Assistant
Now create the BrowserFlow:
Assistant
Now update credential_service.py — four targeted edits:
Assistant
Now add BROWSER branch to _export_connection_values and _get_auth_headers_from_record:
Assistant
Now update schemas.py:
Assistant
Now update routes/auth.py:
Assistant
Now update cli/main.py:
Assistant
Now create the bundled provider JSON files:
Assistant
Now add browser-cookie3 to pyproject.toml:
Assistant
Now write the tests:
Assistant
Now let's run the tests to see if everything passes:
Assistant
One test failure — the _record helper was masking None. Fix the test:
Assistant
30/30. Now run the full suite to check for regressions:
Assistant
362 passed, no regressions. Let me also run lint and type check:
Assistant
All checks pass. Here's a summary of everything that was implemented:
362 tests passing, ruff clean, ty clean.
What was built
New files in auth/ (the entire core logic):
auth/browser_cookies.py — read_chrome_cookies(), cookies_are_valid(), normalize_jsessionid() using browser-cookie3 with a lazy import
auth/flows/browser.py — BrowserFlow with begin()/resume()/refresh() for the daemon side, plus a static run_login() method for the CLI — all browser logic in one place