macOS 选择特定 Profile 命令行启动 Chrome

最近在尝试用 Selenium 复用本地 Chrome 浏览器的登录状态时,遇到了 Profile 路径的问题。记录一下 macOS 下快速定位 Chrome 用户 Profile 的方法。

什么是 Chrome 的 Profile?

Chrome 的 Profile 是浏览器用户数据的隔离单元,每个 Profile 独立保存书签、密码、扩展程序等信息。默认情况下,Chrome 会创建名为 Default 的主 Profile,你也可以手动添加多个 Profile(如 Profile 1Profile 2)。

在自动化测试中,通过 --user-data-dir 参数加载已有 Profile,可保留 Cookie 和密码自动填充功能。

查看当前 Profile 的路径

  1. 打开 Chrome 地址栏,输入 chrome://version 并回车。
  2. 在页面中找到 “Profile Path” 字段,显示的路径类似:

     /Users/你的用户名/Library/Application Support/Google/Chrome/Default
    

    这里的 Default 文件夹即为当前用户的 Profile 数据目录 。在父目录下,会看到多个文件夹,如 DefaultProfile 1 等,每个文件夹对应一个 Profile 。

快速启动

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=/Users/kelu/Library/Application\ Support/Google/Chrome --profile-directory=Profile\ 1

macOS Conda 环境 Python 版本切换失败问题排查