With browser.use_real_profile on and a local backend, the Desktop in-app Browser tab (persist:hermes-preview) now opens sites signed in with the user's real browser profile, like the agent's real-profile browser does. No cookie decryption is added. The existing real-profile browser (the user's real binary on the Hermes-owned snapshot, real_profile_cdp()) decrypts its own store with the OS keychain; a new hidden `hermes browser export-signins --json` reads it over CDP (Storage.getCookies), re-checks consent for the owning profile, and writes the list to its stdout pipe only (it refuses a terminal stdout). Electron main (electron/preview-signins.ts; main.ts gets the registration) runs that as a local child of the owning profile with the same runtime resolution as `gateway ensure`, decides "local" from the route's resolved connection (never a renderer flag), sets the cookies on the partition, and records only their identities (url, name, domain, path) under userData so consent-off removes exactly those, not cookies the user signed into by hand and not ones another consenting profile still imported. Partitioned (CHIPS) cookies are skipped rather than widened. The renderer gets counts only. It syncs on app launch with the toggle on (main window), after the Settings toggle or first-open prompt saves, and from a new "Re-import sign-ins" action under the toggle. Toggle and prompt copy now say the in-app browser is signed in too (en + 8 overlays).
60 lines
2.7 KiB
Python
60 lines
2.7 KiB
Python
"""``hermes browser`` subcommand parser."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
|
|
|
|
def build_browser_parser(subparsers) -> None:
|
|
"""Attach the ``browser`` subcommand to ``subparsers``."""
|
|
browser_parser = subparsers.add_parser(
|
|
"browser", help="Real-profile browsing helpers (close a browser locking its profile)",
|
|
description="Helpers for real-profile browsing (browser.use_real_profile). "
|
|
"close-profile terminates the browser process tree holding your "
|
|
"default profile so Hermes can copy it — DESTRUCTIVE (unsaved tabs "
|
|
"in that browser are lost). The agent runs this only after you "
|
|
"approve closing the browser.")
|
|
browser_subparsers = browser_parser.add_subparsers(dest="browser_action")
|
|
browser_close = browser_subparsers.add_parser(
|
|
"close-profile",
|
|
help="Close the browser locking your real profile (asks nothing — "
|
|
"run only with the user's explicit OK; loses unsaved tabs)")
|
|
browser_close.add_argument(
|
|
"--browser",
|
|
help="Override detected default browser (chrome/edge/brave/brave-origin/chromium)")
|
|
|
|
# Desktop-only plumbing (help hidden): Electron main reads the real-profile browser's cookies through it
|
|
# to sign the in-app browser in (hermes_cli/browser_preview_signins.py).
|
|
browser_export = browser_subparsers.add_parser("export-signins", help=argparse.SUPPRESS)
|
|
browser_export.add_argument("--json", action="store_true")
|
|
|
|
def _dispatch_browser(_args):
|
|
from hermes_cli.browser_connect import (
|
|
UNSUPPORTED_CHANNEL, close_browser_holding_profile, detect_default_chromium,
|
|
real_profile_data_dir)
|
|
|
|
action = getattr(_args, "browser_action", None)
|
|
if action == "export-signins":
|
|
from hermes_cli.browser_preview_signins import run_export_signins
|
|
return run_export_signins(_args)
|
|
if action != "close-profile":
|
|
browser_parser.print_help()
|
|
return 2
|
|
browser = getattr(_args, "browser", None) or detect_default_chromium()
|
|
if not browser or browser == UNSUPPORTED_CHANNEL:
|
|
print("✗ No supported Chromium default browser detected.", file=sys.stderr)
|
|
return 1
|
|
src = real_profile_data_dir(browser)
|
|
if not src:
|
|
print(f"✗ Could not resolve the {browser} profile directory.", file=sys.stderr)
|
|
return 1
|
|
closed, msg = close_browser_holding_profile(src)
|
|
if closed:
|
|
print(f"✓ {msg}")
|
|
return 0
|
|
print(f"✗ {msg}", file=sys.stderr)
|
|
return 1
|
|
|
|
browser_parser.set_defaults(func=_dispatch_browser)
|