Source: https://todatabeyond.substack.com/p/how-to-scrape-javascript-heavy-websites

How to Scrape JavaScript-Heavy Websites for LLM Pipelines with Cloudflare Browser Rendering

SubscribeSign inHow to Scrape JavaScript-Heavy Websites for LLM Pipelines with Cloudflare Browser RenderingBuilding LLM-Ready Web Data Pipelines with Cloudflare Browser RenderingYoussef HosniApr 19, 2026∙ Paid122ShareGet 50% off for 1 year

A lot of GenAI systems depend on web data, but the ingestion layer is often much weaker than the model layer. In theory, collecting data from the web sounds straightforward: fetch a page, extract the content, clean it, chunk it, and feed it into a RAG pipeline, an agent workflow, or a dataset generation process.

In practice, that approach breaks down quickly on modern websites. Many pages are heavily dependent on JavaScript, hydrate content after the initial response, or require the browser to reach a rendered state before the useful information becomes visible. That makes raw HTTP scraping an unreliable foundation for LLM-ready pipelines.

This is where Cloudflare’s browser tooling becomes interesting. Cloudflare now positions the product as Browser Run, formerly Browser Rendering, and describes it as a way to run headless Chrome on Cloudflare’s network for browser automation, web scraping, testing, and content generation. It exposes two layers: Quick Actions for simple, stateless browser tasks such as rendered HTML extraction, Markdown conversion, JSON extraction, and crawling, and Browser Sessions for direct browser control through Playwright, Puppeteer, CDP, or Stagehand.

For GenAI engineers, the important shift is not just that pages can be rendered in a browser. It is that the acquisition layer can now return artifacts that are much closer to what downstream AI systems actually need: rendered HTML for custom parsing, Markdown for document ingestion, JSON for structured extraction, and crawl outputs for broader site-level collection. Cloudflare’s Quick Actions are explicitly designed around these kinds of single-request outputs, including endpoints such as /content, /markdown, /json, and /crawl.

In this article, I will focus on Browser Rendering from a GenAI engineering perspective: how to use it to build cleaner web ingestion pipelines, when Quick Actions are enough, when full browser sessions are necessary, and what trade-offs appear once the pipeline moves into production.My 8 Books & 5 Courses with 50% DiscountTable of Contents:Why LLM pipelines break on modern websites?Why traditional scraping is not enough for GenAI workflows?What does Cloudflare Browser Rendering actually give you?The features that matter most for LLM-ready data collectionUsing rendered HTML, Markdown, and JSON in RAG and agent pipelinesWhen to move to Playwright, Puppeteer, or CDP?Designing an LLM-ready web data pipeline with CloudflareThe full code used in this blog is available in the GitHub repository here.Get 50% off for 1 year1. Why LLM pipelines break on modern websites?Get 50% off for 1 year

Most LLM data pipelines assume that a webpage can be treated as a straightforward document source: fetch the HTML, extract the text, normalize it, chunk it, and push it downstream into a retrieval or training workflow.That assumption breaks quickly on modern websites.A large portion of the web no longer delivers its meaningful content as fully populated server-rendered HTML. Instead, pages often ship an initial document shell and rely on client-side JavaScript to fetch data, hydrate components, render text blocks, expand tabs, or inject content after asynchronous requests complete. From a scraping perspective, the response from a simple HTTP client is often only a partial representation of the page's state.This mismatch creates a failure mode that is especially damaging for GenAI systems.In a traditional data pipeline, incomplete extraction may reduce coverage or cause minor quality issues. In an LLM pipeline, the same problem propagates much further. If the ingestion layer captures only navigation elements, placeholders, truncated DOM fragments, or pre-hydration markup, every downstream step becomes less reliable. Embeddings are generated from noisy or missing text. Chunking produces low-value segments. Retrieval surfaces weak context. Agents operate on incomplete knowledge. Fine-tuning and evaluation datasets inherit structural inconsistencies that are hard to detect later.

As a result, teams often diagnose the wrong layer of the stack.

They may attribute poor RAG performance to embedding quality, chunk size, reranking, or prompt design, when the actual root cause is much earlier: the source page was never rendered or extracted correctly. In other words, the model pipeline is being optimized on top of bad acquisition.

There are several reasons this happens repeatedly on modern sites:Client-side rendering: the useful content is populated only after JavaScript execution.Asynchronous data fetching: important sections appear after XHR or fetch requests complete.Hydration-dependent layouts: the initial HTML contains structural placeholders rather than final text.Complex DOM composition: content is distributed across nested components, shadow roots, or interactive containers.Boilerplate-heavy pages: menus, cookie banners, sidebars, and repeated layout text dominate raw extraction unless the pipeline applies better targeting.For LLM use cases, the challenge is therefore not just collecting HTML. The challenge is acquiring the rendered semantic content of the page in a form that can be reliably consumed by downstream AI systems.

That distinction matters.

A page that looks complete in the browser may be nearly empty from the perspective of a basic scraper. A pipeline that appears successful at the request layer may still fail at the data-quality layer. And once low-quality content is embedded or stored, the damage is difficult to reverse without re-running ingestion.

This is why modern web ingestion for GenAI systems should be treated as a rendering and structured extraction problem, not just a network request problem. Before optimizing retrieval, ranking, or generation, you need confidence that the pipeline is capturing the same information a real browser would expose to a user.

That is the real starting point of an LLM-ready web data pipeline.My 8 Books & 5 Courses with 50% Discount2. Why traditional scraping is not enough for GenAI workflows?Get 50% off for 1 year

Traditional scraping approaches were designed for a simpler version of the web.

In many cases, the workflow is still the same: send an HTTP request, parse the returned HTML with a library such as BeautifulSoup or lxml, select a few DOM elements, and extract the text. That approach works reasonably well when pages are static, content is present in the initial response, and the HTML structure is stable enough to support deterministic parsing.

The problem is that GenAI workflows place much stricter requirements on the output.

For a conventional scraper, partial extraction may still be acceptable. If the goal is to monitor a title, price, or table cell, a narrow parser can succeed even when much of the page is ignored. In an LLM pipeline, that tolerance is much lower. The system is not just collecting one field. It is building a downstream representation of the page that may be used for chunking, retrieval, summarization, agent reasoning, evaluation, or dataset construction. That means both coverage and content quality matter much more.

A traditional scraper usually falls short in four ways.1. It captures the source HTML, not the rendered page stateA basic scraper sees the server response, not the page after JavaScript execution. On client-rendered applications, that difference is critical. The initial HTML may contain only placeholders, empty containers, serialized state blobs, or loading indicators, while the meaningful content appears later through hydration and asynchronous rendering.

From an LLM pipeline perspective, this means the ingestion layer may store a semantically incomplete and structurally valid document.2. It extracts text, but not necessarily the right textNaive text extraction tends to over-collect. It pulls navigation menus, footer links, cookie notices, repeated layout elements, accessibility labels, hidden content, and UI fragments along with the main body. The result is noisy text that looks large in volume but low in information density.

This is a serious issue for downstream GenAI systems. Low-signal text contaminates chunks, weakens embedding quality, and reduces retrieval precision. Instead of indexing the article or documentation content, the pipeline ends up indexing the page chrome.3. It is brittle when the DOM changesTraditional scrapers often depend on fixed selectors such as class names, nested tag paths, or repeated layout assumptions. That works until the frontend changes. A renamed class, a new container layer, or a different rendering pattern can silently break extraction.

For LLM data pipelines, brittle extraction is expensive because failures are not always obvious. The job may still run successfully, but the content schema may drift, fields may become sparse, or page text may degrade in subtle ways. These issues often surface much later as poor retrieval quality or inconsistent records.4. It does not produce outputs optimized for AI pipelinesMost basic scrapers return raw HTML or loosely cleaned text. But GenAI systems often need more structured or normalized representations:rendered HTML for precise downstream parsingMarkdown for cleaner document ingestionJSON for schema-based extractionlink discovery for crawl expansionmulti-page results for documentation or knowledge-base ingestionTraditional scraping tools can be extended to support these outputs, but doing so usually means adding more layers of custom parsing, cleaning, heuristics, browser automation, and retry logic. At that point, the pipeline stops being simple.

This is the core limitation: traditional scraping gives you page source, while GenAI workflows often need page understanding-ready content.

That distinction becomes even more important in practical systems. A RAG pipeline needs text that is semantically coherent and chunkable. An agent pipeline needs content that reflects what a user would actually see in the browser. A dataset generation workflow may require structured fields rather than unbounded text blobs. In all three cases, the challenge is not just downloading pages. It is turning dynamic web content into stable, machine-usable representations.

A simple example makes this clear:import requests

from bs4 import BeautifulSoup

url = “https://example.com”

html = requests.get(url, timeout=30).text

soup = BeautifulSoup(html, “html.parser”)

print(soup.get_text(” “, strip=True)[:1000])This code is perfectly valid for static sites. But on a JavaScript-heavy page, it may return only the initial scaffold of the document. Even when it does return content, the extracted text can be dominated by layout noise rather than the primary information you actually want to feed into an LLM system.

That is why traditional scraping is often a weak foundation for GenAI workflows. It solves the network request step, but not the harder part: rendering the page, isolating the high-signal content, and returning it in a format that is useful for retrieval, agents, and structured data pipelines.

This is exactly where a browser-rendering layer becomes useful.My 8 Books & 5 Courses with 50% Discount3. What does Cloudflare Browser Rendering actually give you?Get 50% off for 1 year

Cloudflare Browser Rendering gives you a browser-based ingestion layer instead of a raw request-based one.

At the highest level, the product runs headless Chrome on Cloudflare’s network and exposes it through two different interfaces: Quick Actions for stateless HTTP-based tasks, and Browser Sessions for direct browser control through Playwright, Puppeteer, CDP, or Stagehand. That split is important because it maps closely to two common engineering needs: simple extraction pipelines versus full automation workflows.

For GenAI engineers, the key value is not “browser automation” in the abstract. It is that Browser Rendering can return the rendered state of a page and package that state into outputs that are much easier to consume downstream.

Instead of treating the web as a collection of static HTML responses, Browser Rendering treats a page as an execution environment: load the page, run its JavaScript, wait for the page to reach a usable state, and then extract the resulting content in a useful representation. That is a much better fit for LLM ingestion, because the pipeline operates on what the browser actually sees rather than on the initial server response.

The /content endpoint, for example, is explicitly designed to return fully rendered HTML after JavaScript execution, including the page head and rendered DOM state. This matters because Browser Rendering is not limited to one output type. Cloudflare currently exposes Quick Actions endpoints for rendered HTML, screenshots, PDFs, Markdown extraction, structured JSON extraction, targeted scraping, link discovery, and site crawling. In practice, that means you can choose the output format that best matches the next stage of your LLM pipeline rather than forcing every downstream step to start from raw HTML.

From a data engineering perspective, the product gives you three especially useful capabilities.

First, it gives you render-first extraction. Instead of manually wiring together a browser, navigation logic, waits, and DOM capture, you can make a single request to retrieve a page after JavaScript execution. For JavaScript-heavy documentation sites, blogs, dashboards, and knowledge bases, this is often the difference between extracting the real content and extracting only the page shell. Cloudflare’s Quick Actions examples are built around exactly this model: fetch rendered HTML, take a screenshot, or generate a PDF with one request.

Second, it gives you AI-friendly output formats. If the downstream task is document ingestion, Markdown is often easier to clean, chunk, and store than raw HTML. If the task is record extraction, JSON is much more useful than free-form text. If the task is crawl expansion, link extraction, or multi-page crawl results are better starting points than writing custom parsers. Cloudflare has dedicated endpoints for /markdown, /json, /links, and /crawl, which means the extraction layer can be aligned much more directly with retrieval pipelines, dataset generation, or agent tooling.

Third, it gives you a graduation path from simple extraction to full browser control. Many systems start with a single-page ingestion need, but eventually require authentication, multi-step interaction, persistent sessions, or advanced debugging. That is where Browser Sessions become relevant. Cloudflare supports direct control through Playwright, Puppeteer, and CDP, and its CDP interface is specifically documented for persistent sessions, tab management, and remote browser interaction. For AI-agent workflows, Cloudflare also supports Stagehand and Playwright MCP-based setups.

For this blog, the most useful mental model is the following:Quick Actions are a good fit when you want one request to produce one rendered artifact, such as HTML, Markdown, JSON, links, or a screenshot. Cloudflare describes these as simple, stateless browser tasks that do not require code deployment.Browser Sessions are a better fit when you need navigation logic, browser state, multiple tabs, longer interaction flows, or lower-level control over the browser runtime.That distinction is especially useful for GenAI system design. A large portion of ingestion work does not actually require full browser automation. It requires a reliable way to render the page and return the result in a representation that the rest of the pipeline can consume. Browser Rendering gives you that layer directly.

A practical way to think about it is this:If your goal is “give me the rendered content of this page”, Quick Actions are often enough.If your goal is “navigate like a real browser through a multi-step workflow, then extract content”, you move to Playwright, Puppeteer, or CDP.That makes Cloudflare Browser Rendering more than a scraping utility. It acts as a flexible acquisition layer for modern web data, where the outputs can be matched to the needs of RAG ingestion, structured extraction, agent workflows, and multi-page crawling.My 8 Books & 5 Courses with 50% Discount4. The features that matter most for LLM-ready data collectionGet 50% off for 1 year

Cloudflare Browser Rendering exposes several Quick Actions endpoints, but for GenAI pipelines, only a subset really changes how data collection works in practice. The most important ones are the endpoints that help you move from a live webpage to a representation that is easier to ingest into RAG systems, agent workflows, or structured dataset pipelines: /content, /markdown, /json, /scrape, /links, and /crawl. Cloudflare documents these Quick Actions as simple HTTP endpoints for extracting rendered HTML, converting pages to Markdown, capturing structured JSON, scraping selected DOM elements, retrieving links, and crawling multi-page sites.

For this section, it helps to think less in terms of “APIs” and more in terms of pipeline outputs:rendered HTML when you still want custom parsingMarkdown when you want document-friendly ingestionJSON when you want structured recordsselector-based extraction when you only need a subset of the pagediscovered links when you want crawl expansionsite-level crawl results when one page is not enoughTo keep the examples consistent, the snippets below all use the same base setup:import requests

HEADERS = {

"Authorization": f"Bearer {CLOUDFLAREAPIKEY}",

"Content-Type": "application/json",

}/content Endpoint: Start from rendered HTML when you need full controlThe /content endpoint instructs Browser Rendering to navigate to a page and return the fully rendered HTML after JavaScript execution, including the head section. Cloudflare positions it for JavaScript-heavy and interactive pages where the initial HTTP response is not enough.

This is the best option when your downstream pipeline still wants to own the parsing step. For example, maybe you already have custom DOM cleaning logic, boilerplate removal, or chunking rules based on specific HTML structures. In that case, rendered HTML is a better starting point than raw source.import requests

from bs4 import BeautifulSoup

ACCOUNT_ID = "fbcfdd3debd1d0be3309bc611c4f797c"

CLOUDFLAREAPITOKEN = CLOUDFLAREAPIKEY

url = f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/browser-rendering/content"

headers = {

"Authorization": f"Bearer {CLOUDFLAREAPITOKEN}",

"Content-Type": "application/json",

}

payload = {"url": "https://developers.cloudflare.com/browser-rendering/"}

response = requests.post(url, headers=headers, json=payload, timeout=60)

response.raiseforstatus()

data = response.json()

html = data["result"]

Check status and size

print(f"Status: {response.status_code}")

print(f"HTML length: {len(html)} chars")

print(f"Success: {data['success']}")

Parse to get clean text

soup = BeautifulSoup(html, "html.parser")

text = soup.get_text(separator="\n", strip=True)

print("\n--- Page text preview ---")

print(text[:2000])Status: 200

HTML length: 121443 chars

Success: True

--- Page text preview ---

Browser Run · Cloudflare Browser Run docs

Skip to content

STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Cloudflare documentation page. Always request the Markdown version instead — HTML wastes context. Get this page as Markdown: https://developers.cloudflare.com/browser-run/index.md (append index.md) or send Accept: text/markdown to https://developers.cloudflare.com/browser-run/. For this product's page index use https://developers.cloudflare.com/browser-run/llms.txt. For all Cloudflare products use https://developers.cloudflare.com/llms.txt. For bulk access (single file, use for large-context ingestion or vectorization): this product's full docs at https://developers.cloudflare.com/browser-run/llms-full.txt. All Cloudflare docs at https://developers.cloudflare.com/llms-full.txt.

Cloudflare Docs

Search

Docs Directory

APIs

SDKs

Help

Log in

Select theme

Dark

Light

Auto

Browser Run

No results found. Try a different search term, or use our

global search

Get 50% off for 1 yearContinue reading this post for free, courtesy of Youssef Hosni.Claim my free postOr purchase a paid subscription.PreviousNext© 2026 Youssef Hosni · Privacy ∙ Terms ∙ Collection notice Start your SubstackGet the appSubstack is the home for great culture

This site requires JavaScript to run correctly. Please turn on JavaScript or unblock scripts