npm.io
1.38.3 • Published 15h agoCLI

@mtop-devtools/client

Licence
ISC
Version
1.38.3
Deps
0
Size
66 kB
Vulns
0
Weekly
0

@mtop-devtools/client

本地客户端 SDK 与 CLI,通过 Unix Domain Socket 与 Chrome 扩展的 native host 通信,调用浏览器调试与操作能力。

提供两种用法:类型安全的具名方法(getRequestsproxyRequest 等),以及灵活的底层 invoke(action, payload)

安装

npm install @mtop-devtools/client
# 或
pnpm add @mtop-devtools/client

SDK 使用

import * as client from '@mtop-devtools/client';

// 具名方法(类型安全)
const requests = await client.getRequests({ count: 5 });
const result = await client.proxyRequest({
  url: 'https://api.example.com',
  method: 'GET',
  withCookies: true,
});

// 底层通用方法(灵活扩展)
const data = await client.invoke('proxy_request', { url: '...' });

CLI 使用

安装后提供 mtop-devtools 命令:

# 获取最近 5 个请求
mtop-devtools get_requests --payload '{"count":5}'

# 代理一个 HTTP 请求
mtop-devtools proxy_request --payload '{"url":"https://api.example.com","method":"GET"}'

# 截图并保存
mtop-devtools get_screenshot --output ./screenshot.png

# 从文件读取大体积参数(如 mock 数据)
mtop-devtools set_mock --payload-file ./mock-data.json

# 环境自检
mtop-devtools check

# 查看某个 action 的帮助
mtop-devtools <action> --help

通用选项:

选项 说明
--payload <json> 直接传入 JSON 参数
--payload-file <path> 从文件读取 JSON 参数
--timeout <seconds> 请求超时时间
--compact 紧凑输出
--output <path> 将结果写入文件(如截图)

支持的操作

分类 Actions
API 调试 get_requests get_logs get_events get_api_schema
Mock & 规则 set_mock get_mocks add_rule
网络代理 proxy_request send_mtop_request
标签页 tab_open tab_close tab_list
页面操作 page_click page_type page_scroll page_eval page_press page_wait page_navigate page_upload
页面感知 page_snapshot get_screenshot get_selected_element page_frames
移动端模拟 set_device_emulation
用户信息 get_user_info
录制 record_start record_stop record_get
TDBank tdbank_account

架构

@mtop-devtools/client (CLI / SDK)
  ↓ (Unix Socket)
@mtop-devtools/native-host
  ↓ (Native Messaging)
Chrome Extension / CDP

云端远程调用场景请使用 @mtop-devtools/cloud-client,其操作集与本包完全一致。

构建

pnpm build      # tsc 编译到 dist/,并赋予 cli.js 执行权限
pnpm dev        # tsc --watch
pnpm typecheck  # 仅类型检查

License

ISC

Keywords