← 返回 Skills 市场
ianzlm

Snapshot to API

作者 fafa-ai-data-labs · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
278
总下载
1
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install snapshot-to-api
功能描述
Discover hidden APIs behind web pages and replace expensive browser snapshots with lightweight API calls. Saves ~15-20x tokens and 2x speed on browser automa...
使用说明 (SKILL.md)

Snapshot to API

Replace browser snapshots with direct API calls. 15-20x fewer tokens, 2x faster, 100% complete data.

Why

Browser snapshots return the full DOM tree — menus, buttons, refs, styling — when you only need the data. A typical table page: 45 KB DOM → ~15k tokens, ~15% useful. The same data via API: 3.5 KB JSON → ~1k tokens, ~90% useful.

Core Workflow

Step 1: Open the target page

browser(action=open, url="\x3Ctarget_url>", profile=openclaw)

Purpose: establish cookie/session auth. You don't need to read the page.

Step 2: Discover API endpoints

// Evaluate in the browser tab
() => {
  const entries = performance.getEntriesByType('resource')
    .filter(e => e.name.includes(window.location.hostname) &&
                 !e.name.match(/\.(js|css|png|jpg|webp|svg|woff|ttf)(\?|$)/))
    .map(e => e.name);
  return JSON.stringify(entries, null, 2);
}

This returns all API calls the page made during loading — the data sources behind the UI.

Step 3: Identify the data API

Look for URLs containing:

  • /api/, /v2/, /v3/
  • Keywords matching your data need (schema, table, list, detail, query, search)
  • GET endpoints with query params like id=, name=, type=

Ignore: analytics, tracking, user-info, config, SDK URLs.

Step 4: Test the API via evaluate

// Replace \x3CAPI_PATH> with the path from Step 3
() => {
  return fetch('\x3CAPI_PATH>')
    .then(r => r.json())
    .then(data => {
      // Inspect the structure
      const keys = Object.keys(data?.data || data || {});
      return JSON.stringify({
        topLevelKeys: keys,
        sample: JSON.stringify(data).substring(0, 1000)
      });
    });
}

Step 5: Extract structured data

Once you understand the response shape, write a focused extractor:

() => {
  return fetch('\x3CAPI_PATH>')
    .then(r => r.json())
    .then(data => {
      // Extract only what you need — return clean JSON
      return JSON.stringify({ /* structured result */ });
    });
}

Step 6: Close the browser tab

browser(action=close, targetId="\x3CtargetId>")

Param Tuning

Many APIs need specific parameters to return full data. Common pattern:

  1. Start with the full URL the page used (from Step 2)
  2. Try removing parameters one at a time
  3. ⚠️ Some params return empty data instead of errors when missing — always verify field counts

Cross-Environment Variations

Different environments (regions, clusters, staging/prod) may have:

  • Different base domains (e.g., app.example.com vs app-eu.example.com)
  • Different API path prefixes (e.g., /api/v2/ vs /api_eu/v2/)
  • Different ID suffixes in query params (e.g., @0 vs @10)

Always test each environment separately.

When NOT to Use

  • Write operations (forms, submissions) — keep using browser automation for safety
  • Pages requiring user interaction to load data (click-to-expand, infinite scroll APIs)
  • Auth flows that need OAuth redirects — cookie-based auth only
  • Frequently changing APIs — snapshot may be more maintainable as fallback

Comparison Reference

See references/comparison.md for detailed benchmark data (token counts, timing, completeness).

After Discovery

  1. Update the original Skill — replace snapshot steps with evaluate + fetch
  2. Keep snapshot as fallback — in case the API changes or auth expires
  3. Document the API — path, required params, response structure, environment differences
  4. Log to learnings — record the discovery for future reference
安全使用建议
This skill is coherent and lightweight, but be aware it runs code in a page context and fetches API endpoints using the browser session — so it can return authenticated data (including potentially sensitive information). Only use it on sites where you have permission to access the data, avoid running it on banking/health/government pages or pages with secrets, and redact or limit fields before sending results to external services or an LLM. Review the short helper script (discover_apis.js) yourself; it is not obfuscated and only enumerates same-host resource requests and classifies likely API calls.
功能分析
Type: OpenClaw Skill Name: snapshot-to-api Version: 1.0.0 The 'snapshot-to-api' skill is a legitimate utility designed to optimize browser automation by identifying and calling internal web APIs instead of parsing large DOM snapshots. The core logic in SKILL.md and scripts/discover_apis.js uses standard browser APIs (performance.getEntriesByType and fetch) to discover data sources on the current page, which improves efficiency and reduces token costs. There is no evidence of data exfiltration, malicious execution, or unauthorized access to sensitive system information.
能力评估
Purpose & Capability
Name/description (replace browser snapshots with API calls) match the included SKILL.md and the javascript helper. Required resources are minimal (no env vars, no installs) and appropriate for the stated purpose.
Instruction Scope
Instructions tell the agent to open a browser tab to establish cookie/session auth, run an evaluate script that inspects performance.getEntriesByType('resource') for same-host requests, then fetch discovered API URLs in-page. This is consistent with the goal but explicitly uses the user's browser session (cookies) to access APIs — which can surface authenticated data. The skill does not instruct writing or transmitting data to external endpoints beyond returning JSON to the agent, but the agent will receive potentially sensitive API responses.
Install Mechanism
No install spec; the skill is instruction-only with a small, readable helper script intended to be paste-evaluated in the browser. No downloads, extract, or third-party packages are required.
Credentials
The skill requests no environment variables or external credentials, which is appropriate. However, at runtime it relies on the browser's session cookies/auth (via opening a profile/tab and evaluating fetch in-page). That behaviour is proportional to discovering behind-auth APIs but does mean the agent can access any data available in the active browser session.
Persistence & Privilege
always is false and the skill does not request persistent system-wide privileges or modify other skill configs. Autonomous invocation is allowed (platform default) but is not combined with any surprising permanent presence.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install snapshot-to-api
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /snapshot-to-api 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of snapshot-to-api skill, enabling efficient API discovery and replacement of browser snapshot workflows: - Quickly find and use hidden APIs behind web pages to obtain structured data directly. - Achieve significant performance gains: 15–20x token savings and 2x speed improvement over browser DOM snapshots. - Clear step-by-step workflow provided for API discovery, testing, and data extraction. - Includes guidelines for when to use (or not use) API replacement and tips for handling different environments. - Advice on updating skills, maintaining fallbacks, and documenting discoveries.
元数据
Slug snapshot-to-api
版本 1.0.0
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 1
常见问题

Snapshot to API 是什么?

Discover hidden APIs behind web pages and replace expensive browser snapshots with lightweight API calls. Saves ~15-20x tokens and 2x speed on browser automa... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 278 次。

如何安装 Snapshot to API?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install snapshot-to-api」即可一键安装,无需额外配置。

Snapshot to API 是免费的吗?

是的,Snapshot to API 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Snapshot to API 支持哪些平台?

Snapshot to API 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Snapshot to API?

由 fafa-ai-data-labs(@ianzlm)开发并维护,当前版本 v1.0.0。

💬 留言讨论