Technical SEO

Download the HTML Google sees using Cloudflare

The Cloudflare Crawler skill downloads the HTML that Cloudflare Browser Rendering returns after executing JavaScript with headless Chrome — the same HTML that Google Caffeine indexes. It supports two modes: download a single URL with the /content endpoint, or crawl multiple pages with the /crawl endpoint in async mode. It saves the results as .html files in crawler/output/. Requires a Cloudflare API token with Browser Rendering permission.

$ https://github.com/jorgejaramillo/seoskills/blob/master/crawler/SKILL.md
---
name: cloudflare-crawl
description: >
  Downloads the rendered HTML (after JavaScript execution) of one or more URLs
  with Cloudflare Browser Run: it's what Google indexes. Use it when the user wants to
  crawl a site, download pages, see how Google views a URL, audit a site
  built with React/Angular/Vue, or prepare data for the other SEO skills.
---

# Cloudflare Crawl

Shared database for all skills: leave the rendered HTML on disk so the
audit, internal linking and images work on what Google sees, not
on the initial HTML.

## When to use

- JavaScript site (SPA, Angular, Next without SSR) → **required** before auditing.
- Static/WordPress site → optional; `shared/seo_extract.py` over HTTP is enough.
- To compare initial HTML vs. rendered: use both and compare title, H1 and links.

## Inputs

Ask only for what's missing:
1. Starting URL.
2. **1 URL** or **several** (if several: maximum number of pages, default 10, and whether to discover via `sitemaps`, `links` or `all`).

Credentials: `CF_ACCOUNT_ID` and `CF_API_TOKEN` (*Browser Run – Edit* permission) in `.env`.
If they're missing, ask the user to copy `.env.example` to `.env`.

## Flow

Each Bash call is a fresh shell: **always start with this block**. Load the token
from `.env` without ever writing it in the command; don't print it or `echo` it.

```bash
set -a; source .env; set +a
D=example.com                                   # domain without www
OUT=crawler/output/$D; mkdir -p "$OUT"
API="https://api.cloudflare.com/client/v4/accounts/$CF_ACCOUNT_ID/browser-run"
AUTH=*** Bearer $CF_API_TOKEN"
SLUG='def slug: sub("^https?://[^/]+/?"; "") | gsub("[^A-Za-z0-9]+"; "-") | sub("^-+"; "") | sub("-+$"; "") | if . == "" then "home" else .[:150] end;'
```

### 1a. Download 1 or a few URLs (`/content`)

Repeat per URL:

```bash
URL=https://example.com/contacto
F=$(jq -rn --arg u "$URL" "$SLUG"'$u | slug').html
curl -s -X POST "$API/content" -H "$AUTH" -H "Content-Type: application/json" \
  -d "$(jq -n --arg u "$URL" '{url: $u, rejectResourceTypes: ["image","media","font","stylesheet"], gotoOptions: {waitUntil: "networkidle2", timeout: 30000}}')" \
  | jq -r 'if .success then .result else ("ERROR " + (.errors | tostring)) end' > "$OUT/$F"
head -c 200 "$OUT/$F"          # if it starts with "ERROR", report the error and don't continue with that URL
M="$OUT/_manifest.json"; [ -f "$M" ] || echo '[]' > "$M"
jq --arg u "$URL" --arg f "$F" 'map(select(.url != $u)) + [{url: $u, status: 200, file: $f}]' "$M" > "$M.tmp" && mv "$M.tmp" "$M"
```

### 1b. Crawl several URLs (`/crawl`, async)

1. **Start** and note the `JOB`:

```bash
curl -s -X POST "$API/crawl" -H "$AUTH" -H "Content-Type: application/json" \
  -d "$(jq -n --arg u "https://example.com" '{url: $u, limit: 50, source: "sitemaps", formats: ["html"], render: true, rejectResourceTypes: ["image","media","font","stylesheet"]}')" \
  | jq -r '.result // .errors'
```

`source`: `sitemaps` (what the site declares), `links` (what's discovered by navigating) or `all`.
`render: false` is faster for static sites.

2. **Wait**: check the status (with `?limit=1` the response is light). Repeat every ~10 s
   until it's no longer `running`; if it takes long, keep polling in separate calls.

```bash
JOB=...   # the id of the previous step
curl -s "$API/crawl/$JOB?limit=1" -H "$AUTH" | jq -r '.result | "\(.status) \(.finished)/\(.total)"'
```

Final states: `completed`, `errored`, `cancelled_due_to_limits`, `cancelled_due_to_timeout`.

3. **Download results** (paginated with `cursor` if they exceed 10 MB), split them into one `.html`
   per URL and create the manifest:

```bash
JOB=...
: > "$OUT/_records.jsonl"; CUR=""
while :; do
  R=$(curl -s "$API/crawl/$JOB${CUR:+?cursor=$CUR}" -H "$AUTH")
  jq -c '.result.records[]' <<<"$R" >> "$OUT/_records.jsonl"
  CUR=$(jq -r '.result.cursor // empty' <<<"$R"); [ -n "$CUR" ] || break
done
while IFS= read -r rec; do
  f=$(jq -r "$SLUG"'select(.html) | (.url | slug) + ".html"' <<<"$rec")
  [ -n "$f" ] && jq -r '.html' <<<"$rec" > "$OUT/$f"
done < "$OUT/_records.jsonl"
jq -s "$SLUG"'[.[] | {url, status: (.metadata.status // .status), file: (if .html then (.url | slug) + ".html" else null end)}]' \
  "$OUT/_records.jsonl" > "$OUT/_manifest.json"
rm "$OUT/_records.jsonl"
jq -r 'group_by(.status) | map("\(.[0].status): \(length)") | .[]' "$OUT/_manifest.json"
```

### 2. Extraction + report section

```bash
python3 shared/seo_extract.py --dir "$OUT" -o "$OUT/_pages.json"
```

`_pages.json` is the input for `seo-audit`, `internal-linking` and `seo-images`.

Then write `report/data/$D/cloudflare-crawl.json`. If it already exists, this command preserves
`summary`, `findings` and `actions`:

```bash
S=report/data/$D/cloudflare-crawl.json; mkdir -p "$(dirname "$S")"
OLD=$S; [ -f "$OLD" ] || OLD=/dev/null
jq -n --slurpfile p "$OUT/_pages.json" --slurpfile m "$OUT/_manifest.json" --slurpfile old "$OLD" \
  --arg site "$D" --arg date "$(date +%F)" '
  def st: tostring | if test("^[0-9]") then .[0:1] + "xx" else . end;
  $p[0] as $pages | ($pages | length) as $n | ($m[0] | map(.status | st)) as $s | ($old[0] // {}) as $o |
  def state($bad): if $bad == 0 then "good" elif $bad < $n * 0.3 then "warn" else "bad" end;
  ($s | map(select(test("^[45]") or . == "errored")) | length) as $err |
  ($s | map(select(test("^[0-9]|^errored$") | not)) | length) as $skip |
  ($pages | map(select(.word_count < 300)) | length) as $thin |
  ($pages | map(select((.headings.h1 | length) == 0)) | length) as $noh1 |
  {skill: "cloudflare-crawl", title: "Crawl (rendered HTML)", site: $site, generated: $date,
   source: "\($n) pages rendered with Cloudflare Browser Run", score: null,
   summary: ($o.summary // ""), findings: ($o.findings // []), actions: ($o.actions // []), charts: [], code: [],
   kpis: [
     {label: "Pages downloaded", value: $n, status: "info"},
     {label: "Errors (4xx/5xx)", value: $err, status: (if $err == 0 then "good" else "bad" end)},
     {label: "URLs not downloaded", value: $skip, status: "info", hint: "skipped / disallowed / cancelled"},
     {label: "Average words", value: (if $n > 0 then ($pages | map(.word_count) | add / $n | floor) else 0 end), status: "info"},
     {label: "Thin content (<300 words)", value: $thin, status: state($thin)},
     {label: "No H1 after render", value: $noh1, status: state($noh1), hint: "If it is missing in the rendered HTML, Google does not see it either"}],
   tables: [{title: "Crawled pages", columns: ["URL", "Status", "Title", "Words", "Int. links"], auto: true,
     rows: ($pages | sort_by(.word_count) | map([.url, (.status // "-"), (.title // "—"), .word_count, .links_internal]))}]}
  ' > "$S.tmp" && mv "$S.tmp" "$S"
```

### 3. Analysis (Claude)

Complete `summary`, `findings` and `actions` in the JSON (no `score`: this skill measures coverage,
not quality). To avoid reading all of `_pages.json`, query it with `jq`, e.g.
`jq -r '.[] | select((.headings.h1 | length) == 0) | .url' "$OUT/_pages.json"`. Look for:
- Pages with errors or empty after render (no title/H1) → content that depends on JS and fails.
- Content that only appears after render (if you compared with `seo_extract.py` over HTTP).
- Site sections that didn't show up in the crawl (blocked? no links? outside the sitemap?).
- `disallowed` URLs: the crawler respects robots.txt; cross-check with the `robots-txt` skill.

### 4. Report

```bash
python3 report/build_report.py  --open
```

## Rules

- **The token never appears in a command, a file or the output**: only `$CF_API_TOKEN` loaded from `.env`.
- Always save HTML, never markdown: HTML is the source of truth.
- The crawler respects robots.txt and anti-bot protection: if a site blocks, say so; don't try to bypass it.
- Free plan limits: https://developers.cloudflare.com/browser-run/limits/ — check before large crawls.
- `/crawl` results stay 14 days in Cloudflare: if the job already finished, just repeat step 3 with the same `JOB`.