canghe-url-to-markdown
Fetch any URL and convert to markdown using Chrome CDP. Supports two modes - auto-capture on page load, or wait for user signal (for pages requiring login). Use when user wants to save a webpage as markdown.
1How It Works & Mechanism
The core mechanism drives a local real Chrome instance via CDP to load any URL, then converts the rendered HTML into clean markdown.
Fetches any URL via Chrome CDP and converts HTML to clean markdown.
Provides two capture modes: auto (captures once the network is idle) and --wait (captures after a user keypress signal).
- Two capture modes: auto or wait-for-user
In wait mode, it prints a prompt and blocks waiting for a newline on stdin, triggering extraction once received.
console.log("Page opened. Press Enter when ready to capture...");
The script launches Chrome itself (enumerating common installation paths by platform, overridable via URL_CHROME_PATH).
export function findChromeExecutable(): string | null {
Discovers the CDP endpoint via the local debugging port (http://127.0.0.1:<port>/json/version).
const res = await fetchWithTimeout(`http://127.0.0.1:${port}/json/version`, { timeoutMs: 5_000 });
Converts HTML to markdown using sanitize + turndown, falling back to plain text extraction on failure.
return turndown.turndown(sanitized);
Outputs markdown with YAML front matter saved to url-to-markdown/<domain>/<slug>.md, appending a timestamp on collision.
YAML front matter with `url`, `title`, `description`, `author`, `published`, `captured_at` fields, followed by converted markdown content.
Chrome path, data directory, and profile directory can all be overridden via environment variables.
| `URL_CHROME_PATH` | Custom Chrome executable path |
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | bun / npx -y bun(运行 scripts/main.ts) |
| cli | 本机 Chrome/Chromium/Edge(由 cdp.ts 定位并 spawn,用 CDP 驱动) |
| network | 用户指定的目标 URL(浏览器真实加载该页面及其子资源) |
4Recommended Governance & Evidence
- scripts/: Executes local script or command: npx -y bun ${SKILL_DIR}/scripts/main.ts <url> [--wait] [-o out.md] [--timeo
- 网络端点: Declares external network access: User-specified target URL: real browser loads the page (including its sub-resources and page-initiated requests)
- 本地工作目录: File read/write and artifact output: url-to-markdown/<domain>/<slug>.md (body + YAML metadata)
5Second-Pass Verification
- [ok] 网络调用定位 — 风险扫描『網路請求』命中 cdp.ts 的 fetch/WebSocket 与 http://127.0.0.1:${port}/json/version;均为本机调试端口,目标页网络由 Chrome 自身发起。
- [ok] 不读凭证 — 风险扫描『憑證/環境變數』命中项均为路径/目录类(URL_CHROME_PATH/URL_DATA_DIR/URL_CHROME_PROFILE_DIR/APPDATA/XDG_DATA_HOME)与 ${SKILL_DIR}/$HOME 文档文本,无密钥/cookie 读取。
- [ok] 独立 profile 而非用户主 profile — paths.ts resolveUrlToMarkdownChromeProfileDir 指向用户数据根/canghe-skills/url-to-markdown/chrome-profile。
- [ok] 无站点适配器/无冒充 — §1 清单只有 6 个文件,无 X/YouTube 等适配器;cdp.ts 无 InnerTube/UA 伪装类代码,与上游 baoyu-url-to-markdown 的红档成因不同。
- [ok] 无安全降级 — 风险扫描『危險旗標/防護繞過』与『沙箱/未受控執行』均无命中;未见 remote-allow-origins=*/--no-verify 等。
- [ok] 两模式与写盘路径属实 — main.ts 的 waitForUserSignal 打印 'Press Enter when ready to capture...';main.ts 以 writeFile(outputPath,...,'utf-8') 落盘。
- [ok] 档位复核 — 有常规网络调用、无凭证、无绕过 → yellow;相较上游红档按证据差异降档,已在 reason 说明。
- [ok] 元数据与 commit — commit=dd0bf355955b4c82b764740b4183c86a72ba0e0c,license=MIT(仓库根),installs=null。
6Verdict & Scenarios
bc953895075e756e…