灵盾浏览器本地 API 使用说明
本地 API 运行在当前电脑,用于让 ERP、RPA、自动化测试脚本或内部工具控制本客户端的浏览器环境。你可以创建环境、打开环境、关闭环境、删除环境,并在打开后取得 Puppeteer、Selenium、Debugger 和 WebDriver 连接信息。
Base URL: http://127.0.0.1:19088
使用前请先在客户端「API 中心」启动本地 API。默认只允许当前电脑访问,需要局域网调用时再开启局域网访问。
Quick Check
cURL
curl "http://127.0.0.1:19088/health"
成功返回
{
"success": true,
"data": {
"status": "running",
"host": "127.0.0.1",
"port": 19088
}
}
接口列表
所有接口都通过客户端本地 API 调用,环境查询和分页由服务端完成,本地接口只作为当前电脑的控制入口。
| 方法 | 地址 | 说明 | 常见用途 |
|---|---|---|---|
| GET | /health | 查看本地 API 是否运行 | 脚本启动前检查 |
| GET | /status | 查看开放状态、端口和访问范围 | 运维巡检 |
| GET | /docs | 返回接口列表和线上文档地址 | 快速发现接口 |
| GET | /openapi | 返回接口说明摘要 | 内部工具集成 |
| GET | /profiles?page=1&pageSize=20&keyword= | 服务端分页查询环境 | 按名称、ID 或编码检索 |
| POST | /profiles/random | 按后台指纹规则树创建随机环境 | 批量初始化环境 |
| POST | /profiles | 创建指定指纹环境 | 精确指定 UA、WebGL、TLS 等 |
| GET | /profiles/{idOrCode} | 按环境 ID、自增 ID 或 6 位编码查询环境 | 打开前确认环境 |
| POST | /profiles/{idOrCode}/start | 打开环境并返回自动化连接信息 | Puppeteer / Selenium 接管 |
| POST | /profiles/{idOrCode}/close | 关闭环境 | 结束当前浏览器窗口 |
| POST | /profiles/{idOrCode}/stop | 关闭环境,等同于 close | 兼容不同调用习惯 |
| DEL | /profiles/{idOrCode} | 删除环境,删除前会尝试关闭会话 | 清理无效环境 |
POST
/profiles/random
创建随机环境
随机环境会从后台指纹规则树取值,保证 Windows 环境不会随机到 Linux UA、macOS 字体或不匹配的 WebGL/TLS。
browserType浏览器类型,当前使用 Chrome。browserMajor浏览器主版本,例如 138。osType操作系统,例如 Windows 11、Windows 10、macOS、Linux。fingerprintPlatform平台节点,例如 windows-x64、macos-arm64、linux-x64。
cURL
JSON
curl -X POST "http://127.0.0.1:19088/profiles/random" \
-H "Content-Type: application/json" \
-d '{
"name": "API 随机环境",
"browserType": "Chrome",
"browserMajor": "138",
"osType": "Windows 11",
"fingerprintPlatform": "windows-x64",
"startupUrls": "https://example.com"
}'
POST
/profiles
创建指定指纹环境
当你需要确定的浏览器环境时,可以手动指定指纹字段。手动指定的值应当与浏览器版本、系统和平台匹配。
时区、语言和 WebRTC 默认建议跟随代理出口。手动指定时需要同时提供具体值。
cURL
指定指纹
curl -X POST "http://127.0.0.1:19088/profiles" \
-H "Content-Type: application/json" \
-d '{
"name": "API 指定指纹环境",
"browser": "Chrome",
"os": "Windows 11",
"startupUrls": "https://example.com",
"fingerprint": {
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
"timezoneMode": "跟随代理",
"languageMode": "跟随代理",
"webRtcMode": "指定当前 IP",
"screenResolution": "1920x1080",
"hardwareConcurrency": "8",
"deviceMemory": "8",
"webglMode": "噪声",
"webglVendor": "Google Inc. (Intel)",
"webglRenderer": "ANGLE (Intel, Intel(R) UHD Graphics Direct3D11 vs_5_0 ps_5_0, D3D11)",
"fontMode": "随机",
"tlsMode": "随机"
}
}'
POST
/profiles/{idOrCode}/start
打开环境并返回连接信息
{idOrCode} 可以替换为环境 ID、用户内自增 ID 或 6 位环境编码。默认会加载该环境已启用的浏览器插件;如不加载插件,可传 {"loadPlugins": false}。
debugPort浏览器 DevTools 调试端口。puppeteer.browserURLPuppeteer 连接地址。selenium.debuggerAddressSelenium 附加到已打开浏览器的调试地址。webdriver.pathchrome.exe 平级目录下的 WebDriver 路径。
Start
Response
curl -X POST "http://127.0.0.1:19088/profiles/A1B2C3/start" \
-H "Content-Type: application/json" \
-d '{"source":"local-api"}'
成功返回 JSON 示例
{
"success": true,
"data": {
"profile": { "id": "egprof_xxx", "name": "API 随机环境" },
"session": { "id": "sess_xxx" },
"launch": {
"pid": 12345,
"debugPort": 28901,
"automation": {
"debugger": {
"httpUrl": "http://127.0.0.1:28901",
"listUrl": "http://127.0.0.1:28901/json/list",
"versionUrl": "http://127.0.0.1:28901/json/version",
"websocketUrl": "ws://127.0.0.1:28901/devtools/page/xxx"
},
"puppeteer": {
"browserURL": "http://127.0.0.1:28901",
"browserWSEndpoint": "ws://127.0.0.1:28901/devtools/page/xxx"
},
"selenium": {
"debuggerAddress": "127.0.0.1:28901",
"chromeDriverPath": "D:\\Chrome\\chromedriver.exe"
},
"webdriver": {
"path": "D:\\Chrome\\chromedriver.exe",
"detected": true
}
}
}
}
}
自动化连接示例
打开环境后,外部工具不需要重新启动浏览器,只需要连接返回的 Debugger 或 WebDriver 信息即可。
推荐先调用打开环境接口,再把返回的连接信息交给 Puppeteer、Playwright 或 Selenium。
Puppeteer
Selenium
import puppeteer from "puppeteer-core";
const response = await fetch("http://127.0.0.1:19088/profiles/A1B2C3/start", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ source: "puppeteer-demo" })
});
const result = await response.json();
const browser = await puppeteer.connect({
browserURL: result.data.launch.automation.puppeteer.browserURL
});
const pages = await browser.pages();
await pages[0].goto("https://example.com");
Selenium 附加到已打开窗口
import { Builder } from "selenium-webdriver";
import chrome from "selenium-webdriver/chrome.js";
const automation = result.data.launch.automation;
const options = new chrome.Options();
options.debuggerAddress(automation.selenium.debuggerAddress);
const service = new chrome.ServiceBuilder(automation.webdriver.path);
const driver = await new Builder()
.forBrowser("chrome")
.setChromeOptions(options)
.setChromeService(service)
.build();
POST
/profiles/{idOrCode}/close
DEL
/profiles/{idOrCode}
关闭与删除环境
关闭环境只结束当前浏览器窗口,环境数据仍然保留。删除环境会移除该环境记录,删除前会尝试关闭正在运行的会话。
Close
Delete
curl -X POST "http://127.0.0.1:19088/profiles/A1B2C3/close" \
-H "Content-Type: application/json" \
-d '{}'
curl -X DELETE "http://127.0.0.1:19088/profiles/A1B2C3"
指纹字段关系表
后台规则树结构为:浏览器类型 -> 浏览器主版本 -> 操作系统 -> 平台 -> 指纹类型 -> 候选值。如果一个值依赖另一个值,它会作为上一个值的子项,例如 WebGL Renderer 依赖 GPU。
| 字段 | 位置 | 取值范围或内容 | 依赖关系 | 说明 |
|---|---|---|---|---|
browserType | profiles/random | Chrome | 根节点 | 浏览器类型 |
browserMajor | profiles/random | 138 或后台已维护主版本 | browserType | 浏览器主版本 |
osType | profiles/random | Windows 11;Windows 10;macOS;Linux | browserMajor | 操作系统 |
fingerprintPlatform | profiles/random | windows-x64;windows-arm64;macos-arm64;macos-x64;linux-x64 | osType | 指纹平台 |
name | profiles/random 或 profiles | 1-120 个字符 | 无 | 环境名称 |
groupId | profiles/random 或 profiles | 已存在分组 ID | 无 | 不传使用默认分组 |
proxyId | profiles/random 或 profiles | 已存在代理 ID | 无 | 不传则不绑定代理 |
startupUrls | profiles/random 或 profiles | URL 文本,可换行 | 无 | 启动后打开的网址 |
browserVersionId | profiles/random 或 profiles | 后台浏览器版本 ID | platform | 不传使用默认浏览器版本 |
fingerprint.userAgent | profiles | 后台 UA 候选或完整 UA 字符串 | browserMajor + osType + platform | 必须与系统平台匹配 |
fingerprint.timezoneMode | profiles | 跟随代理;手动指定 | proxy | 默认跟随代理出口 |
fingerprint.timezone | profiles | IANA 时区,例如 Asia/Shanghai | timezoneMode=手动指定 | 手动指定时必填 |
fingerprint.languageMode | profiles | 跟随代理;手动指定 | proxy | 默认跟随代理出口 |
fingerprint.language | profiles | BCP47 语言,例如 zh-CN;en-US | languageMode=手动指定 | 手动指定时必填 |
fingerprint.webRtcMode | profiles | 指定当前 IP;手动指定 IP;禁用 | proxy | 默认跟随代理出口 IP |
fingerprint.webRtcIp | profiles | IPv4 | webRtcMode=手动指定 IP | 手动指定时必填 |
fingerprint.geolocationMode | profiles | 跟随代理;手动指定;禁用 | proxy | 默认跟随代理出口 |
fingerprint.screenResolution | profiles | 1366x768;1440x900;1536x864;1600x900;1920x1080;2560x1440 | platform | 屏幕分辨率 |
fingerprint.hardwareConcurrency | profiles | 2;4;6;8;10;12;16;24;32 | platform | CPU 线程数 |
fingerprint.deviceMemory | profiles | 2;4;8;16;32 | platform | 设备内存 GB |
fingerprint.canvasMode | profiles | 真实;噪声 | 无 | Canvas 指纹模式 |
fingerprint.clientRectsMode | profiles | 真实;噪声 | 无 | ClientRects 指纹模式 |
fingerprint.audioContextMode | profiles | 真实;噪声 | 无 | AudioContext 指纹模式 |
fingerprint.webglMode | profiles | 真实;噪声;禁用 | GPU | WebGL 指纹模式 |
fingerprint.webglVendor | profiles | 后台 WebGL vendor 候选 | GPU | 需要与 renderer 成对 |
fingerprint.webglRenderer | profiles | 后台 WebGL renderer 候选 | GPU | 需要与 vendor 成对 |
fingerprint.fontMode | profiles | 随机;手动指定;禁用 | platform | 基础字体默认包含 |
fingerprint.fonts | profiles | 字体名数组 | platform | 附加字体候选 |
fingerprint.tlsMode | profiles | 随机;指定 | platform | TLS 指纹模式 |
fingerprint.tlsProfile | profiles | 后台 TLS 候选 JSON | tlsMode=指定 | 指定 TLS 时传入 |
fingerprint.mediaDevicesMode | profiles | 真实;模拟;禁用 | platform | 媒体设备模式 |
fingerprint.mediaDevices | profiles | JSON videoInput/audioInput/audioOutput | mediaDevicesMode=模拟 | 设备数量 |