AI Browser 24小时稳定运行指南

3/11/2026
1 min read

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 自动重启脚本。

八、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 不需要每次登录。

十、AI 多 Tab 控制

获取当前 tabs:

agent-browser list

Published in Technology

You Might Also Like