指导智能体用 agent-browser 命令打开 GitHub,读取当前登录用户的 Star 列表并按星标数排序输出。
# 使用 Agent Browser 获取 GitHub 已收藏项目
## 目标
使用 Agent Browser 技能登录 GitHub,获取当前已登录用户的已收藏项目,并按星标数量排序。
## 执行步骤(按顺序执行)
1. **启动浏览器并打开 GitHub 首页**
```bash
agent-browser --headed --profile "%HOMEPATH%\.agent-browser\chrome-win64\chrome-profiles\github" open https://github.com && agent-browser wait --load networkidle
```
2. **获取当前已登录用户信息**
```bash
agent-browser snapshot -i
# 在右上角查找用户头像或用户名链接以确认登录状态
# 从页面中提取当前已登录用户的用户名
```
3. **导航到当前用户的 Stars 标签页**
```bash
# 构造 URL:https://github.com/{username}?tab=stars
agent-browser open https://github.com/{username}?tab=stars && agent-browser wait --load networkidle
```
4. **按星标数排序(星标最多优先)**
```bash
agent-browser snapshot -i # 首先获取最新快照以找到排序按钮
agent-browser click @e_sort_button # 点击排序按钮
agent-browser wait --load networkidle
# 从下拉选项中选择“Most stars”
```
5. **获取并记录项目信息**
```bash
agent-browser snapshot -i
# 提取项目名称、描述、星标数和 Fork 数信息
```
## 关键注意事项
### 1. 守护进程问题
- 如果看到“daemon already running”,表示浏览器已在运行
- **重要**:当守护进程已在运行时,`--headed` 和 `--profile` 参数将被忽略,浏览器将继续以当前模式运行
- 可直接继续执行后续命令,无需重新打开
- 若要以 headed 模式重启,必须先执行:`agent-browser close`,然后使用 `--headed` 参数重新打开
### 2. 引用的动态性
- 元素引用(@e1、@e2 等)在每次页面变更后都会变化
- 每次交互前必须执行 `snapshot -i` 以获取最新的引用
- 切勿假设引用是固定的
### 3. 命令执行模式
- 使用 `&&` 连接多个命令,避免重复启动进程
- 每条命令后等待页面加载完成:`wait --load networkidle`
### 4. 登录状态
- 使用 `--profile` 参数指定配置文件目录,以保持登录状态
- 如果登录过期,请手动登录一次以保存状态
### 5. Windows 环境变量扩展
- **重要**:在 Windows 上,环境变量如 `%HOMEPATH%` 必须在使用前扩展为实际路径
- **错误**:`agent-browser --profile "%HOMEPATH%\.agent-browser\chrome-win64\chrome-profiles\github"`
- **正确**:首先执行 `echo $HOME` 获取实际路径,然后使用扩展后的路径
```bash
# 获取 HOME 路径(例如 /c/Users/xxx)
echo $HOME
# 使用扩展后的绝对路径
agent-browser --profile "/c/Users/xxx/.agent-browser/chrome-win64/chrome-profiles/github" --headed open https://github.com
```
- 若不扩展环境变量,将遇到连接错误(例如 `os error 10060`)
### 6. 排序配置
- 点击“Sort by: Recently starred”按钮(通常为引用 e44)
- 选择“Most stars”选项
- 再次获取页面内容
## 常见问题排查
| 问题 | 解决方案 |
|-------|----------|
| daemon already running | 直接执行后续命令,或先关闭再重新打开 |
| Invalid element reference | 执行 snapshot -i 获取最新引用 |
| Page not fully loaded | 添加 wait --load networkidle |
| Need to re-login | 使用 --headed 模式手动登录一次并保存状态 |
| Sorting not applied | 确认已点击正确的排序选项 |
## 结果输出格式
- 项目名称和链接
- 星标数(按降序排列)
- Fork 数
- 项目描述(如可用)# Using Agent Browser to Fetch GitHub Starred Projects
## Objective
Use the Agent Browser skill to log into GitHub and retrieve the starred projects of the currently logged-in user, sorted by the number of stars.
## Execution Steps (Follow in Order)
1. **Launch Browser and Open GitHub Homepage**
```bash
agent-browser --headed --profile "%HOMEPATH%\.agent-browser\chrome-win64\chrome-profiles\github" open https://github.com && agent-browser wait --load networkidle
```
2. **Get Current Logged-in User Information**
```bash
agent-browser snapshot -i
# Find the user avatar or username link in the top-right corner to confirm login status
# Extract the username of the currently logged-in user from the page
```
3. **Navigate to Current User's Stars Tab**
```bash
# Construct URL: https://github.com/{username}?tab=stars
agent-browser open https://github.com/{username}?tab=stars && agent-browser wait --load networkidle
```
4. **Sort by Stars Count (Most Stars First)**
```bash
agent-browser snapshot -i # First get the latest snapshot to find the sort button
agent-browser click @e_sort_button # Click the sort button
agent-browser wait --load networkidle
# Select "Most stars" from the dropdown options
```
5. **Retrieve and Record Project Information**
```bash
agent-browser snapshot -i
# Extract project name, description, stars, and forks information
```
## Critical Notes
### 1. Daemon Process Issues
- If you see "daemon already running", the browser is already running
- **Important:** When the daemon is already running, `--headed` and `--profile` parameters are ignored, and the browser continues in its current running mode
- You can proceed with subsequent commands without reopening
- To restart in headed mode, you must first execute: `agent-browser close`, then use the `--headed` parameter to reopen
### 2. Dynamic Nature of References
- Element references (@e1, @e2, etc.) change after each page modification
- You must execute `snapshot -i` before each interaction to get the latest references
- Never assume references are fixed
### 3. Command Execution Pattern
- Use `&&` to chain multiple commands, avoiding repeated process launches
- Wait for page load after each command: `wait --load networkidle`
### 4. Login Status
- Use the `--profile` parameter to specify a profile directory, maintaining login state
- If login expires, manually log in once to save the state
### 5. Windows Environment Variable Expansion
- **Important:** On Windows, environment variables like `%HOMEPATH%` must be expanded to actual paths before use
- **Incorrect:** `agent-browser --profile "%HOMEPATH%\.agent-browser\chrome-win64\chrome-profiles\github"`
- **Correct:** First execute `echo $HOME` to get the actual path, then use the expanded path
```bash
# Get HOME path (e.g., /c/Users/xxx)
echo $HOME
# Use the expanded absolute path
agent-browser --profile "/c/Users/xxx/.agent-browser/chrome-win64/chrome-profiles/github" --headed open https://github.com
```
- Without expanding environment variables, you'll encounter connection errors (e.g., `os error 10060`)
### 6. Sorting Configuration
- Click the "Sort by: Recently starred" button (typically reference e44)
- Select the "Most stars" option
- Retrieve page content again
## Troubleshooting Common Issues
| Issue | Solution |
|-------|----------|
| daemon already running | Execute subsequent commands directly, or close then reopen |
| Invalid element reference | Execute snapshot -i to get latest references |
| Page not fully loaded | Add wait --load networkidle |
| Need to re-login | Use --headed mode to manually login once and save state |
| Sorting not applied | Confirm you clicked the correct sorting option |
## Result Output Format
- Project name and link
- Stars count (sorted in descending order)
- Forks count
- Project description (if available)