跪拜 Guibai
← All articles
Frontend · Backend · AI Programming

A Playwright Pipeline That Reverse-Engineers and Rebuilds Any Website with Parallel AI Agents

By 我不是外星人 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Website cloning tools usually produce brittle, single-shot output. This pipeline formalizes the process into a verifiable, concurrent engineering flow where spec documents act as contracts for AI agents. The spec-first, build-second order is what separates a toy from a repeatable build system, and the git-worktree concurrency pattern is directly reusable for any multi-agent code generation task.

Summary

A new open-source pipeline, ai-website-cloner-template, reverse-engineers any website into a functional Next.js codebase. It runs Playwright across three viewports to capture full-page screenshots, extracts computed CSS values from every DOM node, and simulates scroll, click, and hover interactions to document every interactive state. The result is a set of JSON design tokens, a page topology map, and a library of deduplicated icons and downloaded assets.

Component generation follows a spec-driven, multi-agent workflow. Each page section gets a markdown spec under 150 lines that pins exact pixel values, real content, and interaction models. Builder agents work in isolated git worktrees, and an orchestrator merges their output into main only after each merge passes lint, typecheck, and build checks. The pipeline finishes with a visual QA step that captures side-by-side screenshots of the original and the clone across all three viewports, flagging size, color, and layout discrepancies.

On Juejin's homepage, the pipeline restored roughly 70% of the UI fidelity. Mobile viewport testing immediately surfaced three layout bugs—tag wrapping, author truncation, and a button-inside-anchor issue—while desktop and tablet passed in one shot. The project treats website cloning as an engineering discipline, not a one-shot AI prompt.

Takeaways
Three standard viewports (1440×900, 768×1024, 390×844) are used for screenshots because responsive breakpoints must be verified, not guessed.
Design tokens are extracted via getComputedStyle() on every DOM node, not by copying CSS source, which penetrates @apply, CSS variables, and media queries.
Interaction scanning simulates scroll positions, tab clicks, and hover states to capture content changes that static screenshots miss.
Each page section gets a markdown spec under 150 lines with pixel-level styles, real content data, and interaction models before any code is written.
Builder agents work in isolated git worktrees; an orchestrator merges them into main only after each merge passes lint, typecheck, and build.
Visual QA captures side-by-side screenshots of the original and clone across all three viewports, prioritizing size differences, then color, then layout.
On Juejin's homepage, the 'Latest' tab switch dropped article count from 16 to 1, confirming it was a real data fetch, not a pure UI toggle.
Mobile viewport testing immediately exposed three layout bugs: tag wrapping, author truncation, and a button-inside-anchor issue.
Conclusions

Extracting computed styles instead of source CSS is the key architectural decision that makes the pipeline robust across different frameworks and styling approaches.

The 150-line spec budget per section is a practical complexity cap that forces granularity and keeps individual agent tasks focused enough to succeed.

Git worktree concurrency solves the merge-conflict problem that plagues multi-agent code generation, and the 'merge only if it builds' rule enforces a quality gate at every step.

The 2.5-second post-networkidle wait is a reminder that real-world pages with lazy loading and IntersectionObserver are never truly 'done' loading—any scraping tool needs a hydration buffer.

Restoring only 70% UI fidelity on a complex page like Juejin suggests the current ceiling is set by model capability, not pipeline design; the architecture can absorb better models without structural changes.

Concepts & terms
Design Tokens
Platform-agnostic style values (colors, font sizes, spacing) extracted from a live page's computed styles and mapped to Tailwind CSS variables so components can reference them by name rather than hardcoded hex values.
Spec-Driven Development
Writing a detailed markdown specification document that defines pixel-level styles, real content, and interaction models before any component code is generated, serving as a contract for AI builder agents.
Git Worktree
A git feature that lets multiple working trees be attached to the same repository, allowing parallel branches to be checked out simultaneously without cloning the repo again. Used here to isolate each AI agent's work.
getComputedStyle()
A browser API that returns the final computed CSS values for an element after all stylesheets, inline styles, and inheritance are resolved, giving the actual rendered values rather than declared source code.
From the discussion
Featured comments
凉瓜拌面

If it's drawn with canvas, it basically won't achieve the effect at all.

浪乘画舸忆蟾蜍

Let the OP test it.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗