npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mtop-devtools/cloud-client

v1.32.0

Published

Cloud client SDK for Mtop DevTools — communicate with local browser via cloud server

Readme

@mtop-devtools/cloud-client

云端客户端 SDK,用于在云端环境中调用本地浏览器能力。

安装

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

使用

方式一:使用 invoke 函数

import { invoke } from '@mtop-devtools/cloud-client';

// 设置环境变量
process.env.MTOP_DEVTOOLS_SERVER_URL = 'ws://your-server.com/ws?token=xxx';

// 调用浏览器能力
const requests = await invoke('get_requests', { count: 5 });
console.log(requests);

// 获取截图
const screenshot = await invoke('get_screenshot', {});

方式二:使用 CloudClient 类

import { CloudClient } from '@mtop-devtools/cloud-client';

const client = new CloudClient({
  serverUrl: 'wss://your-server.com/ws?token=xxx',
  connectTimeoutSec: 30,
  requestTimeoutSec: 60,
});

// 一次性使用
try {
  const logs = await client.invoke('get_logs', { limit: 10 });
  console.log(logs);
} finally {
  client.disconnect();
}

// 长连接复用
await client.invoke('tab_open', { url: 'https://example.com' });
await client.invoke('page_click', { selector: 'button' });
await client.invoke('get_screenshot', {});
client.disconnect();

命令行方式

mtop-devtools-cloud <action> [options]

示例:

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

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

# 使用自定义服务器
mtop-devtools get_logs --server "ws://localhost:8080/ws?token=xxx" --payload '{"limit": 10}'

环境变量:

  • MTOP_DEVTOOLS_SERVER_URL - WebSocket Server 地址(包含 token)

支持的操作

与本地 @mtop-devtools/client 完全一致,包括:

API 调试

  • get_requests - 获取网络请求
  • get_logs - 获取控制台日志
  • get_events - 获取埋点事件
  • get_api_schema - 获取 API Schema

Mock & 请求规则

  • set_mock - 设置 Mock
  • get_mocks - 获取 Mock 列表
  • add_rule - 添加请求规则
  • proxy_request - 代理 HTTP 请求

浏览器操作

  • tab_open / tab_close / tab_list - 标签页管理
  • page_click / page_type / page_scroll / page_press - 页面交互
  • page_eval / page_navigate / page_wait - 页面控制
  • page_upload - 文件上传

页面感知

  • get_screenshot - 获取截图
  • get_selected_element - 获取选中元素
  • page_snapshot - 获取页面快照

详细参数说明请参考 SKILL.md

架构

云端 Agent
  ↓
@mtop-devtools/cloud-client (本进程)
  ↓ (WebSocket)
@mtop-devtools/cloud-server
  ↓ (WebSocket)
@mtop-devtools/cloud-connector (本地)
  ↓ (Unix Socket)
@mtop-devtools/native-host
  ↓
Chrome Extension / CDP

错误处理

try {
  const result = await client.invoke('get_requests', { count: 5 });
} catch (error) {
  if (error.message.includes('Connection timeout')) {
    // 连接超时
  } else if (error.message.includes('Connection closed')) {
    // 连接断开
  } else if (error.message.includes('Request timeout')) {
    // 请求超时
  } else {
    // 其他错误
  }
}

注意事项

  • 确保云端 Server 已启动且可访问
  • 确保本地已运行 @mtop-devtools/cloud-connector
  • 建议使用长连接复用 CloudClient 实例,避免频繁连接
  • 使用完毕后调用 disconnect() 释放资源