SuperAPI AI Directory

clone-page

Frontend & websites

View repository

Updated 10-16 00:00

About this skill

Clone Webpage

Use Playwright to progressively collect page data, then restore HTML/CSS in stages.

Prerequisites: Node.js >= 18 (Playwright + Chromium are installed automatically on first run)

Collection Script

From scripts/ in the skill directory, run:

node scripts/clone.mjs <url> <command> [options]

Two Restoration Modes

🚀 Fast Restoration (recommended to start with this)

Suitable for quickly producing a prototype, uses fewer tokens, completes in a few minutes.

Collect:

node scripts/clone.mjs <url> quick -o ./clone-data --scroll

Data source priority:

  1. ⭐⭐⭐⭐⭐ screenshot.png — visual truth, use it as the standard
  2. ⭐⭐⭐⭐ theme.json — design tokens such as colors, fonts, spacing
  3. ⭐⭐⭐ skeleton.json — DOM skeleton (understand hierarchy and semantic tags)

Restoration steps:

  1. Look at screenshot.png, understand the overall page layout
  2. Read theme.json, extract key design tokens (primary color, fonts, spacing, border radius, shadows)
  3. Skim skeleton.json --depth=2, understand the major section divisions
  4. In the order header → main → footer, write HTML/CSS section by section with reference to the screenshots
  5. Use the values in theme.json as CSS variables
# 渐进式读取数据
node scripts/query.mjs ./clone-data summary
node scripts/query.mjs ./clone-data skeleton --depth=2

🎨 High-Precision Restoration

Suitable for production environments, restores to the pixel level. Adds additional collection on top of fast restoration.

Collect:

# 先执行 quick(如果还没有)
node scripts/clone.mjs <url> quick -o ./clone-data --scroll

# 然后逐 section 深入采集样式
node scripts/clone.mjs <url> styles -o ./clone-data --selector "header"
node scripts/clone.mjs <url> styles -o ./clone-data --selector "main > section:nth-child(1)"
node scripts/clone.mjs <url> styles -o ./clone-data --selector "main > section:nth-child(2)"
node scripts/clone.mjs <url> styles -o ./clone-data --selector "footer"

# 需要时:交互态
node scripts/clone.mjs <url> interact -o ./clone-data --hover "nav a:first-child"

# 需要时:响应式截图
node scripts/clone.mjs <url> responsive -o ./clone-data

# 最后:下载资源
node scripts/clone.mjs <url> assets -o ./clone-data

Data source priority:

  1. ⭐⭐⭐⭐⭐ screenshot.png — still use screenshots as the standard
  2. ⭐⭐⭐⭐⭐ sections/*/nodes.json — precise DOM structure + selectors
  3. ⭐⭐⭐⭐⭐ sections/*/styles.json — complete computedStyle
  4. ⭐⭐⭐⭐ theme.json — design tokens
  5. ⭐⭐⭐ sections/*/screenshot.png — per-section screenshot comparison

Restoration steps:

  1. Same as fast restoration Steps 1-3
  2. View the list of collected sections:
    node scripts/query.mjs ./clone-data sections
    
  3. Restore section by section:
    # 查看 section 的完整数据(DOM + 样式)
    node scripts/query.mjs ./clone-data section header
    
    • According to the nodes.json in children , strictly build the hierarchy
    • According to the styles.json in styleId , apply precise styles
    • Compare with screenshot.png and fine-tune
  4. If the section styles are not precise enough, you can further narrow the selector scope and collect again
  5. If hover/focus states are needed, use the interact command to collect them
  6. Use the images and fonts in the assets/ directory

Collection Command Quick Reference

Command Purpose Output
quick Fast mode = init + skeleton screenshot + meta + theme + skeleton
full Full mode = init + skeleton + responsive + assets The above + responsive screenshots + resources
init Screenshots + metadata + design tokens screenshot.png, meta.json, theme.json
skeleton DOM skeleton (without styles) skeleton.json
styles --selector "X" Complete styles for the specified area sections/X/nodes.json + styles.json + screenshot.png
interact Interaction state screenshots interactions/*.png + *-styles.json
responsive Multi-viewport screenshots responsive/*.png
assets Download images/fonts/SVG assets/

Query Command Quick Reference

node scripts/query.mjs <dir> summary                  # 概览
node scripts/query.mjs <dir> skeleton --depth=2        # 骨架(前 2 层)
node scripts/query.mjs <dir> subtree n2 --depth=3      # 某节点子树
node scripts/query.mjs <dir> node n15                  # 单节点(含已采集样式)
node scripts/query.mjs <dir> sections                  # 已采集的 section 列表
node scripts/query.mjs <dir> section header            # 某 section 的完整数据
node scripts/query.mjs <dir> find --tag=button         # 按标签查找
node scripts/query.mjs <dir> find --text="登录"        # 按文本查找
node scripts/query.mjs <dir> find --interactive        # 交互元素
node scripts/query.mjs <dir> file theme.json           # 读取任意文件

Output Directory Structure

clone-data/
├── meta.json              # 元信息(url, title, phases, sections)
├── screenshot.png         # 全页截图
├── theme.json             # 设计令牌
├── skeleton.json          # DOM 骨架树(含 selector)
│
├── sections/              # 按 section 的样式(逐步追加)
│   ├── header/
│   │   ├── nodes.json     # DOM + selector + bbox + styleId
│   │   ├── styles.json    # computedStyle 去重池
│   │   └── screenshot.png
│   └── main-section-nth-child-1/
│       └── ...
│
├── interactions/           # 交互态数据
│   ├── hover-nav-a.png
│   └── hover-nav-a-styles.json
│
├── responsive/             # 多视口截图
│   ├── desktop.png
│   ├── tablet.png
│   └── mobile.png
│
└── assets/                 # 下载的资源
    ├── images/
    ├── fonts/
    ├── svgs/
    └── manifest.json

Pages that require login

# 方法 1: 连接已登录的 Chrome(推荐)
# 先启动 Chrome:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
# 在 Chrome 中登录后运行:
node scripts/clone.mjs https://internal.site.com quick --connect-cdp http://localhost:9222

# 方法 2: 显示浏览器窗口手动登录
node scripts/clone.mjs https://internal.site.com quick --no-headless

Tips

  • The screenshot is the ultimate truth — if the data conflicts with the screenshot, the screenshot prevails
  • Progressive collection — no need to do a full run all at once; first do a quick run to see the result, then add styles as needed
  • selector is the bridge — every node in skeleton.json has a CSS selector, used for precise targeting later
  • Each Phase is independent — data is appended incrementally and will not overwrite existing content
  • Coarse first, then fine — quickly reconstruct the overall framework → compare with the screenshot → fine-tune