Skip to main content

Python browser automation MCP framework for AI Agents

Project description

RootBrowse

AI Agent 的浏览器 — 一个 AI 可以直接操控的浏览器。

它解决什么问题?

AI 时代,浏览器应该是 AI 的工具。但现在的方案有两个问题:

1. 能让 AI 操控的浏览器方案太少了

大部分浏览器自动化框架(Selenium/Playwright)设计目标是给人写脚本用的,不是给 AI 实时操控的。

2. 安装太重了

Selenium 要下载 ChromeDriver,Playwright 要安装几百兆的驱动包。跑一个测试先花半小时装环境。


RootBrowse 就是来解决这两个痛点的:

  • 零驱动 — 基于 DrissionPage,直接用 CDP 控制 Chrome,不需要任何 driver
  • AI 优先 — 专为 AI 实时操控设计,不是给人类写脚本用的

安装只需要一行

pip install rootbrowse-mcp

没有 chromedriver,没有几百兆的 playwright install,就一个包。

对比

Selenium Playwright RootBrowse
安装大小 上百 MB(chromedriver) 几百 MB(playwright) 几 MB
操作方式 click() 封装 click() 封装 run_js()
React 页面 容易失效 容易失效 JS 直接操作,稳定
数据返回 全量 DOM 全量 DOM 渐进式探索
定位方式 CSS selector CSS selector xpath 实时
AI 友好度

核心区别:传统框架是给人用的,RootBrowse 是给 AI 用的。

MCP 快速开始

配置 Claude Code

C:\Users\你的用户名\.claude.jsonmcpServers 中添加:

{
  "mcpServers": {
    "RootBrowseMCP": {
      "command": "python.exe",
      "args": ["-m", "rootbrowse_mcp.server"]
    }
  }
}

command 需要填电脑里真实的 python 解释器路径(此解释器的环境必须已安装 rootbrowse-mcp)。

AI 工作流

init_browser()                    → 初始化浏览器
get_page(url)                     → 打开页面
get_page_regions()                 → 查看有哪些区块
get_region_summary(xpath)          → 查看区块统计
match_element(...)                 → 筛选目标元素
run_js(...)                       → 万能操作(点击/输入/滚动...)

Python 库快速开始

from rootbrowse import Browser

browser = Browser()
browser.get('https://example.com')

# 渐进式探索
regions = browser.view.get_regions()           # 看区块
summary = browser.view.get_region_summary(regions[0].xpath)  # 看统计
elements = browser.view.match_element(tag='a', limit=20)    # 筛选元素

# 万能操作
browser.run_js("document.evaluate('xpath=...', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue?.click()")

browser.close()

核心哲学

封装层不可靠,run_js 是万能接口。点击、输入、获取元素信息,都通过 run_js 完成,AI 自己决定何时用它。

MCP 工具(11 个)

类别 工具 说明
页面扫描 get_page_regions() 获取页面语义区域
get_region_summary(xpath) 区域统计
match_element(...) 按条件筛选元素
浏览器 init_browser(headless) 初始化(必选)
get_page(url) 打开 URL
take_screenshot(path) 截图
close_browser() 关闭浏览器
run_js(code, args) 执行 JavaScript
标签页 new_tab(url) 新建标签页
close_tab() 关闭标签页
switch_tab(index) 切换标签页
状态 save_state(path) 保存会话
load_state(path) 恢复会话

run_js 示例

// 点击
var ele = document.evaluate("xpath=...", document, null,
    XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (ele) ele.click();

// 输入
var ele = document.evaluate("xpath=...", document, null,
    XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (ele) {
    ele.value = arguments[0];
    ele.dispatchEvent(new Event('input', {bubbles: true}));
}

// 长文本分段获取
return document.body.innerText.substring(0, 2000);

技术栈

  • Python >= 3.10
  • DrissionPage — 底层 CDP 引擎
  • FastMCP(MCP 协议实现)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rootbrowse-0.6.1.tar.gz (47.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rootbrowse-0.6.1-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file rootbrowse-0.6.1.tar.gz.

File metadata

  • Download URL: rootbrowse-0.6.1.tar.gz
  • Upload date:
  • Size: 47.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for rootbrowse-0.6.1.tar.gz
Algorithm Hash digest
SHA256 9a857026e51dd43e8593c4dc60d27ae686fab60df93b1e3c295348e38d5a46a8
MD5 c378d254b0c4db57da1065482bc5c101
BLAKE2b-256 9891d31fcc6acd318b4be6595f433f441559c2825eb21741e3ad506f70ace694

See more details on using hashes here.

File details

Details for the file rootbrowse-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: rootbrowse-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for rootbrowse-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c43d42d1f74e54c85be56d92eaf22e75b24d8974e17d346568036627400b810
MD5 aece921e04b96164e3a08873c9706265
BLAKE2b-256 2302a681f01da31f20c9652b737b582d2e4452d4be81eecb6568361a97e22ea8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page