AI Browser 24小時穩定運行指南
AI Browser 24小時穩定運行指南
本教程介紹如何搭建一個 穩定、長期運行的 AI 瀏覽器環境。
適用於
- AI Agent
- 自動化瀏覽
- Web automation
- AI 助手
- 自動測試系統
目標
- 瀏覽器 24小時運行
- 自動 reconnect
一、啟動 Chrome 調試模式
Mac / Linux
google-chrome \ --remote-debugging-port=9222 \ --user-data-dir=/tmp/ai-browser \ --disable-infobars \ --disable-background-timer-throttling \ --disable-renderer-backgrounding \ --disable-backgrounding-occluded-windows \ --no-first-run \ --no-default-browser-check
Windows
chrome.exe ^ --remote-debugging-port=9222 ^ --user-data-dir=C:\ai-browser ^ --disable-infobars ^ --disable-background-timer-throttling ^ --disable-renderer-backgrounding ^ --disable-backgrounding-occluded-windows ^ --no-first-run ^ --no-default-browser-check
二、為什麼這些參數重要
這些參數可以避免:
- tab sleep
- JS timer 停止
- 自動化斷線
三、測試瀏覽器調試接口
打開:
http://localhost:9222如果看到:
DevTools listening on ws://...說明瀏覽器正常。
四、配置 agent-browser 自動連接
創建配置文件:
Linux / Mac
~/.agent-browser/config.json
Windows
%USERPROFILE%\.agent-browser\config.json內容:
{ "autoConnect": true, "host": "127.0.0.1", "port": 9222 }
五、測試 AI 控制
運行:
agent-browser snapshot如果返回 DOM tree:說明連接成功。
六、穩定導航方法
推薦:
agent-browser eval "window.location.href=https://example.com"不推薦:
agent-browser open原因:
- open 可能創建新 tab
- eval 更穩定
七、防止瀏覽器斷線
Chrome 可能因為以下原因斷開:
- Chrome crash
- DevTools session 被回收
- 系統資源限制
八、Watchdog 腳本
創建文件:watch-browser.sh
#!/bin/bash
while true do if ! curl -s http://localhost:9222 > /dev/null then echo "Chrome not running, restarting..." pkill chrome google-chrome \ --remote-debugging-port=9222 \ --user-data-dir=/tmp/ai-browser \ --disable-infobars \ --no-first-run \ --no-default-browser-check & fi sleep 10 done 運行:
bash watch-browser.sh效果:
- Chrome crash 自動重啟
- 調試端口自動恢復
九、保存登錄狀態
因為使用:--user-data-dir
瀏覽器會保存:
- cookies
- 登錄狀態
- local storage
- session
十、AI 多 Tab 控制
獲取當前 tabs:
agent-browser list

