|
| 1 | +# Browser Use Cases (Recipes) |
| 2 | + |
| 3 | +This page is intentionally **copy-paste friendly**: concrete prompts, expected artifacts, and small troubleshooting notes. |
| 4 | + |
| 5 | +See also: [Browser Automation (Playwright)](browser-automation.md). |
| 6 | + |
| 7 | +## Prerequisites (Playwright) |
| 8 | + |
| 9 | +Install Playwright (Python): |
| 10 | + |
| 11 | +```bash |
| 12 | +python3 -m pip install playwright |
| 13 | +python3 -m playwright install chromium |
| 14 | +``` |
| 15 | + |
| 16 | +If your Python executable isn't `python3`, set `REXOS_BROWSER_PYTHON` (example: `python`). |
| 17 | + |
| 18 | +## 1) GUI smoke check (example.com) |
| 19 | + |
| 20 | +**Goal:** verify `browser_*` works end-to-end and leaves evidence in your workspace. |
| 21 | + |
| 22 | +=== "Bash (macOS/Linux)" |
| 23 | + ```bash |
| 24 | + mkdir -p rexos-demo && cd rexos-demo |
| 25 | + export REXOS_BROWSER_HEADLESS=0 |
| 26 | + |
| 27 | + rexos agent run --workspace . --prompt "Use browser tools to open https://example.com, read the page, write a 3-bullet summary to notes/example.md, save a screenshot to .rexos/browser/example.png, then close the browser." |
| 28 | + ``` |
| 29 | + |
| 30 | +=== "PowerShell (Windows)" |
| 31 | + ```powershell |
| 32 | + mkdir rexos-demo -Force | Out-Null |
| 33 | + cd rexos-demo |
| 34 | + $env:REXOS_BROWSER_HEADLESS = "0" |
| 35 | + |
| 36 | + rexos agent run --workspace . --prompt "Use browser tools to open https://example.com, read the page, write a 3-bullet summary to notes/example.md, save a screenshot to .rexos/browser/example.png, then close the browser." |
| 37 | + ``` |
| 38 | + |
| 39 | +**What to expect** |
| 40 | + |
| 41 | +- `notes/example.md` |
| 42 | +- `.rexos/browser/example.png` |
| 43 | + |
| 44 | +## 2) Real-world flow: Baidu “today’s weather” (Browser + Ollama) |
| 45 | + |
| 46 | +**Goal:** open a Baidu results page, extract today’s weather info, and save evidence. |
| 47 | + |
| 48 | +### Recommended model (Ollama) |
| 49 | + |
| 50 | +Make sure Ollama has a strong instruction model (example): |
| 51 | + |
| 52 | +```bash |
| 53 | +ollama pull qwen3:4b |
| 54 | +``` |
| 55 | + |
| 56 | +Then set it as default in `~/.rexos/config.toml`: |
| 57 | + |
| 58 | +```toml |
| 59 | +[providers.ollama] |
| 60 | +default_model = "qwen3:4b" |
| 61 | +``` |
| 62 | + |
| 63 | +### Run (GUI mode) |
| 64 | + |
| 65 | +=== "Bash (macOS/Linux)" |
| 66 | + ```bash |
| 67 | + export REXOS_BROWSER_HEADLESS=0 |
| 68 | + |
| 69 | + rexos agent run --workspace . --prompt "Use browser tools to open https://www.baidu.com/s?wd=%E5%8C%97%E4%BA%AC%20%E4%BB%8A%E5%A4%A9%E5%A4%A9%E6%B0%94 . Wait for #content_left, then read the page. Extract today's weather info (conditions, temperature range, wind) from the page text. Write it to notes/weather.md. Save a screenshot to .rexos/browser/baidu_weather.png. Close the browser. If you can't find the weather, say so, but still save the screenshot." |
| 70 | + ``` |
| 71 | + |
| 72 | +=== "PowerShell (Windows)" |
| 73 | + ```powershell |
| 74 | + $env:REXOS_BROWSER_HEADLESS = "0" |
| 75 | + |
| 76 | + rexos agent run --workspace . --prompt "Use browser tools to open https://www.baidu.com/s?wd=%E5%8C%97%E4%BA%AC%20%E4%BB%8A%E5%A4%A9%E5%A4%A9%E6%B0%94 . Wait for #content_left, then read the page. Extract today's weather info (conditions, temperature range, wind) from the page text. Write it to notes/weather.md. Save a screenshot to .rexos/browser/baidu_weather.png. Close the browser. If you can't find the weather, say so, but still save the screenshot." |
| 77 | + ``` |
| 78 | + |
| 79 | +**What to expect** |
| 80 | + |
| 81 | +- `notes/weather.md` |
| 82 | +- `.rexos/browser/baidu_weather.png` |
| 83 | + |
| 84 | +!!! note "If you hit a CAPTCHA" |
| 85 | + Some sites may show CAPTCHAs or block automation. If that happens, try a different query/site, or switch to `web_search` + `web_fetch` when the content is not JS-heavy. |
| 86 | + |
| 87 | +## 3) Wikipedia: open → summarize → screenshot |
| 88 | + |
| 89 | +**Goal:** a stable no-login site for quick demos. |
| 90 | + |
| 91 | +=== "Bash (macOS/Linux)" |
| 92 | + ```bash |
| 93 | + export REXOS_BROWSER_HEADLESS=0 |
| 94 | + |
| 95 | + rexos agent run --workspace . --prompt "Use browser tools to open https://en.wikipedia.org/wiki/Rust_(programming_language) . Read the page. Write a short summary to notes/wiki_rust.md. Save a screenshot to .rexos/browser/wiki_rust.png. Close the browser." |
| 96 | + ``` |
| 97 | + |
| 98 | +=== "PowerShell (Windows)" |
| 99 | + ```powershell |
| 100 | + $env:REXOS_BROWSER_HEADLESS = "0" |
| 101 | + |
| 102 | + rexos agent run --workspace . --prompt "Use browser tools to open https://en.wikipedia.org/wiki/Rust_(programming_language) . Read the page. Write a short summary to notes/wiki_rust.md. Save a screenshot to .rexos/browser/wiki_rust.png. Close the browser." |
| 103 | + ``` |
| 104 | + |
| 105 | +**What to expect** |
| 106 | + |
| 107 | +- `notes/wiki_rust.md` |
| 108 | +- `.rexos/browser/wiki_rust.png` |
| 109 | + |
| 110 | +## 4) (From source) Run the browser + Ollama smoke test |
| 111 | + |
| 112 | +If you're hacking on RexOS itself, you can run the ignored smoke test: |
| 113 | + |
| 114 | +```bash |
| 115 | +REXOS_OLLAMA_MODEL=qwen3:4b cargo test -p rexos --test browser_baidu_weather_smoke -- --ignored --nocapture |
| 116 | +``` |
| 117 | + |
| 118 | +Expected output includes a line like: |
| 119 | + |
| 120 | +- `[rexos][baidu_weather] summary=...` |
| 121 | + |
| 122 | +This test uses a temp workspace and cleans it up. Use the recipes above if you want to keep screenshots and files. |
| 123 | + |
| 124 | +## Tips |
| 125 | + |
| 126 | +- For search engines, consider opening a **results URL** directly (more reliable than typing into the homepage search box). |
| 127 | +- Always `browser_close` at the end (even on errors). |
| 128 | +- Do not enter credentials or complete purchases without explicit user confirmation. |
0 commit comments