Headless Chrome is the wrong tool for most scraping jobs, and serverless makes that obvious. AWS Lambda caps deployment packages at 250 MB unzipped; a Playwright install with Chromium blows past that before you write any business logic, so you maintain a layer, pay for 1 GB of memory to render pixels you ignore, and inherit a multi-second cold start.
The actual job — fetch a URL, strip the navigation and cookie banners, hand the model readable markdown — is one HTTP call. This post runs that call from Cloudflare Workers, Vercel Edge Functions, and AWS Lambda, with code for caching, retries, and fan-out, plus real latency and failure data.
A browser-based scraper does five jobs. Only one needs a browser.
| Job | Who does it |
|---|---|
| DNS, TLS, redirects, decompression | Markdownify API |
| Execute JavaScript, wait for hydration | Browser (only if the page needs it) |
| Strip nav, ads, cookie banners, footers | Markdownify API |
| Convert to structured markdown | Markdownify API |
| Extract title, description, word counts | Markdownify API |
For documentation, blogs, changelogs, pricing pages, and most marketing sites, the server-rendered HTML already contains the content.
curl -s -G "https://fetchapi.tech/v1/markdownify" \
--data-urlencode "url=https://en.wikipedia.org/wiki/Serverless_computing" \
-o page.json
{
"content": "**Serverless computing** is \"a cloud service category...\"",
"title": "",
"description": "",
"url": "https://en.wikipedia.org/wiki/Serverless_computing",
"word_count": 1562,
"char_count": 17081
}
content is real markdown — headings, lists, links, and code fences survive, so you can chunk on structure later. But title and description are not guaranteed: Wikipedia returned empty strings for both. If you need reliable metadata, call OGSnap.
Failures return HTTP 400 with a specific detail:
curl -s -G "https://fetchapi.tech/v1/markdownify" \
--data-urlencode "url=https://news.ycombinator.com"
# {"detail":"No content could be extracted from this page"}
Use -G with --data-urlencode in scripts: pasting a URL containing & into a query string silently truncates it, a bug that looks like "the API is broken".
It uses only fetch and AbortSignal — available in Workers, Vercel Edge, Lambda's Node 20+, Deno, and Bun.
const ENDPOINT = "https://fetchapi.tech/v1/markdownify";
export async function toMarkdown(url, { timeoutMs = 15000 } = {}) {
const res = await fetch(
`${ENDPOINT}?url=${encodeURIComponent(url)}`,
{
signal: AbortSignal.timeout(timeoutMs),
headers: { accept: "application/json" },
}
);
const body = await res.json().catch(() => ({}));
if (!res.ok) {
const err = new Error(body.detail ?? `markdownify failed: HTTP ${res.status}`);
err.status = res.status;
err.sourceUrl = url;
throw err;
}
return body; // { content, title, description, url, word_count, char_count }
}
Because parsing happens off-box, the Worker's CPU time is essentially JSON parsing — which matters on the free plan. The binding constraint becomes subrequests: six simultaneous connections and 50 subrequests per invocation free (1,000 paid).
const json = (data, status = 200, headers = {}) =>
new Response(JSON.stringify(data), {
status,
headers: { "content-type": "application/json", ...headers },
});
const canonical = (raw) => {
const u = new URL(raw);
for (const key of [...u.searchParams.keys()]) {
if (key.startsWith("utm_")) u.searchParams.delete(key);
}
u.hash = "";
return u.toString();
};
export default {
async fetch(request, env, ctx) {
const target = new URL(request.url).searchParams.get("url");
if (!target) return json({ error: "url query param required" }, 400);
const cache = caches.default;
const cacheKey = new Request(
`https://cache.internal/md?url=${encodeURIComponent(canonical(target))}`
);
let hit = await cache.match(cacheKey);
if (!hit) {
const upstream = await fetch(
`https://fetchapi.tech/v1/markdownify?url=${encodeURIComponent(target)}`,
{ cf: { cacheTtl: 3600, cacheEverything: true } }
);
if (!upstream.ok) {
const { detail } = await upstream.json().catch(() => ({}));
return json({ error: detail ?? "extract failed" }, upstream.status);
}
hit = json(await upstream.json(), 200, {
"cache-control": "public, max-age=3600",
});
ctx.waitUntil(cache.put(cacheKey, hit.clone()));
}
return hit;
},
};
Two cache layers do different work: cf.cacheTtl caches the upstream response at Cloudflare's edge, while caches.default stores your normalized result per colo. The canonical() step makes both useful — ?utm_source=twitter and ?utm_source=newsletter are the same document.
export const runtime = "edge";
export async function GET(req: Request) {
const target = new URL(req.url).searchParams.get("url");
if (!target) {
return Response.json({ error: "url query param required" }, { status: 400 });
}
const upstream = await fetch(
`https://fetchapi.tech/v1/markdownify?url=${encodeURIComponent(target)}`,
{ signal: AbortSignal.timeout(15000) }
);
const data = await upstream.json();
return Response.json(data, {
status: upstream.status,
headers: {
"cache-control": "s-maxage=3600, stale-while-revalidate=86400",
},
});
}
The edge runtime has no Node built-ins or filesystem — nothing to bundle. Browsers need the Node runtime and a far larger function.
import json
import urllib.parse
import urllib.request
API = "https://fetchapi.tech/v1/markdownify"
def lambda_handler(event, context):
url = (event.get("queryStringParameters") or {}).get("url")
if not url:
return {"statusCode": 400, "body": json.dumps({"error": "url required"})}
req = urllib.request.Request(
f"{API}?url={urllib.parse.quote(url, safe='')}",
headers={"Accept": "application/json"},
)
try:
with urllib.request.urlopen(req, timeout=20) as resp:
payload = json.load(resp)
return {"statusCode": 200, "body": json.dumps(payload)}
except urllib.error.HTTPError as e:
detail = json.loads(e.read() or b"{}").get("detail", str(e))
return {"statusCode": e.code, "body": json.dumps({"error": detail})}
The handler is a few kilobytes: no build step, no /tmp extraction, no multi-second cold start.
I ran four URLs three times each.
| URL | Result | Time (first / cached) |
|---|---|---|
en.wikipedia.org/wiki/Serverless_computing |
200 — 1,562 words | 1.21s / 0.20s |
developers.cloudflare.com/workers/ |
200 — only 133 words | 0.48s / 0.25s |
vercel.com/docs/functions |
400 — "Could not fetch URL" | 1.50s |
news.ycombinator.com |
400 — "No content could be extracted" | 0.73s |
The endpoint caches upstream fetches. Wikipedia went from 1.21s to 0.20s on repeat calls — six times faster. Your cache and theirs stack.
Thin results are a real failure mode. The Cloudflare docs URL returned 200 with 133 words, far less than the page visibly contains. A 200 is not a quality guarantee — validate word_count and route thin results to a browser fallback.
"Could not fetch" and "No content" are different problems. The first means blocked, geo-restricted, or dead. The second means the page loaded but had nothing extractable, often a JS-only app. Neither improves on retry, so don't burn three attempts on a 400.
async function withRetry(fn, tries = 3) {
for (let attempt = 0; ; attempt++) {
try {
return await fn();
} catch (err) {
const retryable = !err.status || err.status >= 500;
if (!retryable || attempt === tries - 1) throw err;
const backoff = 500 * 2 ** attempt + Math.random() * 250;
await new Promise((resolve) => setTimeout(resolve, backoff));
}
}
}
Retry timeouts and 5xx. Fail fast on 400s.
Batch jobs are where connection limits bite. On Workers cap concurrency at six; elsewhere 4–8 keeps memory flat and avoids looking like a flood.
async function mapLimit(items, limit, fn) {
const out = new Array(items.length);
let next = 0;
await Promise.all(
Array.from({ length: Math.min(limit, items.length) }, async () => {
while (next < items.length) {
const i = next++;
out[i] = await fn(items[i], i);
}
})
);
return out;
}
const pages = await mapLimit(urls, 6, (u) => withRetry(() => toMarkdown(u)));
Rough math. A 1 GB Lambda doing a 4-second render costs about $0.000067 in compute at $0.0000166667 per GB-second — call it $6.70 per 100,000 pages, before request charges and layer storage.
That beats the $49/mo Enterprise tier (50,000 requests) on raw compute. It excludes what you actually pay for: patching Chromium, rotating proxies, and rewriting selectors every time a site redesigns.
At small scale the comparison isn't close: 2,000 pages a month is $12 on Pro, or 5,000 requests at $0.0024 each. The honest split is that DIY wins on raw compute at high volume with stable targets; the API wins on engineering time, and on targets you don't control.
utm_*, fragments, and trailing slashes, or your hit rate will be terrible.word_count. Treat under ~50 words as a soft failure, not a document.markdownify returns empty fields./v1/transcript and /v1/info are the right tools for video.url from the response, not the URL you requested. Redirects make them diverge, and that divergence is usually the bug.curl -s -G "https://fetchapi.tech/v1/markdownify" \
--data-urlencode "url=https://developers.cloudflare.com/workers/" \
| jq -r '.content' | head -40
One GET request, no browser, no layer, no multi-second cold start. If your function exists mainly to turn a URL into text, that's the whole architecture.