Files
broswer-automation/docs/TOOLS_zh.md
nasir@endelospay.com d97cad1736 first commit
2025-08-12 02:54:17 +05:00

530 lines
9.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Chrome MCP Server API 参考 📚
所有可用工具及其参数的完整参考。
## 📋 目录
- [浏览器管理](#浏览器管理)
- [截图和视觉](#截图和视觉)
- [网络监控](#网络监控)
- [内容分析](#内容分析)
- [交互操作](#交互操作)
- [数据管理](#数据管理)
- [响应格式](#响应格式)
## 📊 浏览器管理
### `get_windows_and_tabs`
列出当前打开的所有浏览器窗口和标签页。
**参数**:无
**响应**
```json
{
"windowCount": 2,
"tabCount": 5,
"windows": [
{
"windowId": 123,
"tabs": [
{
"tabId": 456,
"url": "https://example.com",
"title": "示例页面",
"active": true
}
]
}
]
}
```
### `chrome_navigate`
导航到指定 URL可选择控制视口。
**参数**
- `url` (字符串,必需):要导航到的 URL
- `newWindow` (布尔值,可选)创建新窗口默认false
- `width` (数字,可选)视口宽度像素默认1280
- `height` (数字,可选)视口高度像素默认720
**示例**
```json
{
"url": "https://example.com",
"newWindow": true,
"width": 1920,
"height": 1080
}
```
### `chrome_close_tabs`
关闭指定的标签页或窗口。
**参数**
- `tabIds` (数组,可选):要关闭的标签页 ID 数组
- `windowIds` (数组,可选):要关闭的窗口 ID 数组
**示例**
```json
{
"tabIds": [123, 456],
"windowIds": [789]
}
```
### `chrome_go_back_or_forward`
浏览器历史导航。
**参数**
- `direction` (字符串,必需)"back" 或 "forward"
- `tabId` (数字,可选):特定标签页 ID默认活动标签页
**示例**
```json
{
"direction": "back",
"tabId": 123
}
```
## 📸 截图和视觉
### `chrome_screenshot`
使用各种选项进行高级截图。
**参数**
- `name` (字符串,可选):截图文件名
- `selector` (字符串,可选):元素截图的 CSS 选择器
- `width` (数字,可选)宽度像素默认800
- `height` (数字,可选)高度像素默认600
- `storeBase64` (布尔值,可选):返回 base64 数据默认false
- `fullPage` (布尔值,可选)捕获整个页面默认true
**示例**
```json
{
"selector": ".main-content",
"fullPage": true,
"storeBase64": true,
"width": 1920,
"height": 1080
}
```
**响应**
```json
{
"success": true,
"base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
"dimensions": {
"width": 1920,
"height": 1080
}
}
```
## 🌐 网络监控
### `chrome_network_capture_start`
使用 webRequest API 开始捕获网络请求。
**参数**
- `url` (字符串,可选):要导航并捕获的 URL
- `maxCaptureTime` (数字,可选)最大捕获时间毫秒默认30000
- `inactivityTimeout` (数字,可选)无活动后停止时间毫秒默认3000
- `includeStatic` (布尔值,可选)包含静态资源默认false
**示例**
```json
{
"url": "https://api.example.com",
"maxCaptureTime": 60000,
"includeStatic": false
}
```
### `chrome_network_capture_stop`
停止网络捕获并返回收集的数据。
**参数**:无
**响应**
```json
{
"success": true,
"capturedRequests": [
{
"url": "https://api.example.com/data",
"method": "GET",
"status": 200,
"requestHeaders": {...},
"responseHeaders": {...},
"responseTime": 150
}
],
"summary": {
"totalRequests": 15,
"captureTime": 5000
}
}
```
### `chrome_network_debugger_start`
使用 Chrome Debugger API 开始捕获(包含响应体)。
**参数**
- `url` (字符串,可选):要导航并捕获的 URL
### `chrome_network_debugger_stop`
停止调试器捕获并返回包含响应体的数据。
### `chrome_network_request`
发送自定义 HTTP 请求。
**参数**
- `url` (字符串,必需):请求 URL
- `method` (字符串,可选)HTTP 方法(默认:"GET"
- `headers` (对象,可选):请求头
- `body` (字符串,可选):请求体
**示例**
```json
{
"url": "https://api.example.com/data",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": "{\"key\": \"value\"}"
}
```
## 🔍 内容分析
### `search_tabs_content`
跨浏览器标签页的 AI 驱动语义搜索。
**参数**
- `query` (字符串,必需):搜索查询
**示例**
```json
{
"query": "机器学习教程"
}
```
**响应**
```json
{
"success": true,
"totalTabsSearched": 10,
"matchedTabsCount": 3,
"vectorSearchEnabled": true,
"indexStats": {
"totalDocuments": 150,
"totalTabs": 10,
"semanticEngineReady": true
},
"matchedTabs": [
{
"tabId": 123,
"url": "https://example.com/ml-tutorial",
"title": "机器学习教程",
"semanticScore": 0.85,
"matchedSnippets": ["机器学习简介..."],
"chunkSource": "content"
}
]
}
```
### `chrome_get_web_content`
从网页提取 HTML 或文本内容。
**参数**
- `format` (字符串,可选)"html" 或 "text"(默认:"text"
- `selector` (字符串,可选):特定元素的 CSS 选择器
- `tabId` (数字,可选):特定标签页 ID默认活动标签页
**示例**
```json
{
"format": "text",
"selector": ".article-content"
}
```
### `chrome_get_interactive_elements`
查找页面上可点击和交互的元素。
**参数**
- `tabId` (数字,可选):特定标签页 ID默认活动标签页
**响应**
```json
{
"elements": [
{
"selector": "#submit-button",
"type": "button",
"text": "提交",
"visible": true,
"clickable": true
}
]
}
```
## 🎯 交互操作
### `chrome_click_element`
使用 CSS 选择器点击元素。
**参数**
- `selector` (字符串,必需):目标元素的 CSS 选择器
- `tabId` (数字,可选):特定标签页 ID默认活动标签页
**示例**
```json
{
"selector": "#submit-button"
}
```
### `chrome_fill_or_select`
填充表单字段或选择选项。
**参数**
- `selector` (字符串,必需):目标元素的 CSS 选择器
- `value` (字符串,必需):要填充或选择的值
- `tabId` (数字,可选):特定标签页 ID默认活动标签页
**示例**
```json
{
"selector": "#email-input",
"value": "user@example.com"
}
```
### `chrome_keyboard`
模拟键盘输入和快捷键。
**参数**
- `keys` (字符串,必需):按键组合(如:"Ctrl+C"、"Enter"
- `selector` (字符串,可选):目标元素选择器
- `delay` (数字,可选)按键间延迟毫秒默认0
**示例**
```json
{
"keys": "Ctrl+A",
"selector": "#text-input",
"delay": 100
}
```
## 📚 数据管理
### `chrome_history`
使用过滤器搜索浏览器历史记录。
**参数**
- `text` (字符串,可选):在 URL/标题中搜索文本
- `startTime` (字符串,可选)开始日期ISO 格式)
- `endTime` (字符串,可选)结束日期ISO 格式)
- `maxResults` (数字,可选)最大结果数默认100
- `excludeCurrentTabs` (布尔值,可选)排除当前标签页默认true
**示例**
```json
{
"text": "github",
"startTime": "2024-01-01",
"maxResults": 50
}
```
### `chrome_bookmark_search`
按关键词搜索书签。
**参数**
- `query` (字符串,可选):搜索关键词
- `maxResults` (数字,可选)最大结果数默认100
- `folderPath` (字符串,可选):在特定文件夹内搜索
**示例**
```json
{
"query": "文档",
"maxResults": 20,
"folderPath": "工作/资源"
}
```
### `chrome_bookmark_add`
添加支持文件夹的新书签。
**参数**
- `url` (字符串,可选):要收藏的 URL默认当前标签页
- `title` (字符串,可选):书签标题(默认:页面标题)
- `parentId` (字符串,可选):父文件夹 ID 或路径
- `createFolder` (布尔值,可选)如果不存在则创建文件夹默认false
**示例**
```json
{
"url": "https://example.com",
"title": "示例网站",
"parentId": "工作/资源",
"createFolder": true
}
```
### `chrome_bookmark_delete`
按 ID 或 URL 删除书签。
**参数**
- `bookmarkId` (字符串,可选):要删除的书签 ID
- `url` (字符串,可选):要查找并删除的 URL
**示例**
```json
{
"url": "https://example.com"
}
```
## 📋 响应格式
所有工具都返回以下格式的响应:
```json
{
"content": [
{
"type": "text",
"text": "包含实际响应数据的 JSON 字符串"
}
],
"isError": false
}
```
对于错误:
```json
{
"content": [
{
"type": "text",
"text": "描述出错原因的错误消息"
}
],
"isError": true
}
```
## 🔧 使用示例
### 完整工作流示例
```javascript
// 1. 导航到页面
await callTool('chrome_navigate', {
url: 'https://example.com',
});
// 2. 截图
const screenshot = await callTool('chrome_screenshot', {
fullPage: true,
storeBase64: true,
});
// 3. 开始网络监控
await callTool('chrome_network_capture_start', {
maxCaptureTime: 30000,
});
// 4. 与页面交互
await callTool('chrome_click_element', {
selector: '#load-data-button',
});
// 5. 语义搜索内容
const searchResults = await callTool('search_tabs_content', {
query: '用户数据分析',
});
// 6. 停止网络捕获
const networkData = await callTool('chrome_network_capture_stop');
// 7. 保存书签
await callTool('chrome_bookmark_add', {
title: '数据分析页面',
parentId: '工作/分析',
});
```
此 API 提供全面的浏览器自动化功能,具有 AI 增强的内容分析和语义搜索特性。