How to Scrape JavaScript-Heavy Websites

Scrape JavaScript-heavy sites the light way: View Source checks, wait selectors, Firecrawl actions, and Apify Cheerio vs Playwright from the docs.

Summarize this post with AI

A 22-minute read, or the key points in about 30 seconds, in the assistant you already use.

Opens in a new tab with the prompt filled in. Nothing passes through this site.

curl returns a shell. View Source is empty. Your selector finds nothing. The page looks fine in Chrome.

That is the classic JavaScript-heavy scrape failure. The HTML your HTTP client got is a bootstrap document. The product list, price and reviews only appear after the browser runs React, Vue or Next.js and waits for a follow-up API call.

So how do you scrape JavaScript-heavy websites without burning hours on flaky sleeps?

Below is the decision path I use from the docs: prove whether you need a browser at all, wait on the right signal, then choose a render API like Firecrawl, an Apify actor, or self-hosted Playwright. Pair it with robots.txt etiquette for scrapers before you scale.

Some links are affiliate links; they don't change your price.

Editorial cover of a browser window where empty markup fills into content cards after an amber render pulse

Why do JavaScript-heavy pages break naive scrapers?

Because the first response is often not the page you see.

A naive scraper does one GET, parses the bytes, and looks for CSS selectors. On a server-rendered blog that works. On a client-rendered app, those bytes are a nearly empty root div, a script tag and a spinner.

Crawlee's own guide shows the trap clearly: View Page Source is the original HTML before JavaScript. Inspect is the live DOM after it. Cheerio and plain HTTP see the first. Playwright and Puppeteer see the second.

That is why "my scraper returned blank" is usually not a selector bug. It is a rendering bug. You asked for the package, and the warehouse only shipped the box.

My take: treat every modern marketing site and SaaS app as guilty until View Source or a Network XHR proves the data was already there.

How can you tell if a page needs a browser?

Run three checks before you open Chromium.

1. View Source vs Inspect

Right-click → View Page Source and search for a unique string from the UI (a product title, a price, a heading). Then open DevTools → Elements and search again.

  • Present in View Source: HTTP + Cheerio (or any HTML parser) is enough.
  • Missing in View Source, present in Elements: something has to execute JavaScript.

2. Disable JavaScript

Apify's academy recommends checking whether the site still shows the data with JavaScript off. If it does, you do not need a browser for that page. If it collapses into a blank shell, you do.

3. Look at the Network tab

Filter XHR/fetch. Often the UI is just a client for a JSON endpoint that already returns the fields you want. If you can replay that request with the right headers and cookies, skip the browser entirely. That path is cheaper, faster and less fragile than driving a headless tab.

Diagram comparing View Source empty shell versus Inspect filled DOM with an amber arrow labelled Render
If View Source is empty and Inspect is full, you have a rendering problem, not a selector problem.

Decision table

What you findLightest tool that fits
Fields in raw HTMLHTTP client + Cheerio / Beautiful Soup
Stable JSON/XHR APIDirect API scrape (still check ToS)
Needs JS, no clicksRender API (Firecrawl) or headless browser
Needs login, zip, Load more, infinite scrollBrowser with actions (Firecrawl actions or Playwright)
Heavy volume, mixed static + dynamicApify hybrid: Cheerio for most, Playwright for the rest

Skip it if: you only need a public RSS feed, sitemap or documented API. Scraping the SPA is the slow path.

Headless browser vs render API: which should you use?

A headless browser is Chromium (or Firefox/WebKit) you control. You own waits, clicks, cookies, proxies and failure modes. Playwright is the usual pick today. Puppeteer still works; Crawlee suggests Playwright if you know neither, because it auto-waits more cleanly.

A render API is someone else's Chromium farm wrapped in an HTTP call. You send a URL (and optional actions). You get markdown, HTML or structured JSON back.

Firecrawl is the one I point people at when the job is "turn this URL into clean markdown for an LLM or pipeline" and they do not want to operate browsers. Details on when each product wins live in my Firecrawl vs Apify comparison.

NeedPrefer
One-off or low volume, markdown outFirecrawl scrape
Custom Actor, queues, scheduling, mixed sitesApify
Full control, local debug, special fingerprintingSelf-hosted Playwright
Mostly static HTML at scaleCheerio / HTTP on Apify

Firecrawl's docs state every scrape already runs in real Chromium, so React, Vue and Next.js pages do not need a special "enable JS" flag. You pay for that convenience in credits and less low-level control. Self-hosted Playwright costs you RAM, ops and your own retry logic.

For turning pages into LLM-ready markdown after you can render them, use the companion guide on scraping a website to markdown for LLMs.

What wait conditions actually work?

Wrong waits are why scrapers flake.

Playwright's own docs mark networkidle as discouraged. It means "no network connections for about 500 ms", not "the content I care about is ready".

Pages with websockets, analytics beacons or long-poll never go idle, so the wait times out. Other pages go quiet between the shell and the real fetch, so networkidle returns too early with an empty list.

Fixed sleeps (waitForTimeout style delays) are for debugging. Too short and you race. Too long and you pay for every page.

Wait on the signal you need

SignalUseFails when
Required element visiblelocator.wait_for / Firecrawl wait with selectorSelector never appears (blocked page, A/B, renamed class)
Specific API responsepage.expect_response before the triggerEndpoint URL changed or is batched differently
Bounded JS predicatepage.wait_for_functionPredicate too loose or never true
Extra settle time (API)Firecrawl waitFor in msUsed as a default instead of a selector
Network quietnetworkidle (discouraged)Beacons never stop, or quiet gap before data fetch
Fixed sleepDebug onlyAlways

Firecrawl splits this into two knobs:

  • waitFor: extra milliseconds on top of its smart-wait (default 0). Docs say use sparingly.
  • Actions wait: either milliseconds or selector (one, not both). Selector waits time out after 30 seconds. Combined waits across actions plus waitFor must stay under 60 seconds, with at most 50 actions per request.

My rule: wait for the product card, the price node, or the JSON response that fills them. Never wait for "the page" in the abstract.

Three wait strategy cards labelled Selector, API response and Sleep with amber highlight on Selector
Wait for the element or the response that carries your fields. Sleep is a last resort.

How do you scrape JS pages with Firecrawl?

Start with a plain scrape. Firecrawl already renders JavaScript.

js
import { Firecrawl } from 'firecrawl-js';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

const doc = await firecrawl.scrape('https://example.com/products', {
  formats: ['markdown'],
  onlyMainContent: true,
  waitFor: 2000,
  timeout: 60000,
});

console.log(doc.markdown);

That pattern matches Firecrawl's advanced scraping guide (as of 6 November 2026). waitFor is an integer in milliseconds. timeout defaults to 60 seconds. onlyMainContent defaults to true so nav and footer noise is stripped before markdown.

When the data needs a click or scroll

Use actions before the final capture. Example shape from the same docs: accept a banner, scroll, click Load more, then wait for a selector.

js
const doc = await firecrawl.scrape('https://example.com/catalog', {
  formats: ['markdown'],
  actions: [
    { type: 'wait', selector: '#catalog' },
    { type: 'click', selector: '#accept' },
    { type: 'scroll', direction: 'down' },
    { type: 'click', selector: '#load-more' },
    { type: 'wait', selector: '.product-card' },
  ],
});

Notes that bite people:

  • write only works after a click that focuses the field.
  • executeJavascript can pull embedded state (for example a Next.js __NEXT_DATA__ script); return values land in actions.javascriptReturns.
  • Actions are not supported when the URL is a PDF.
  • Set maxAge to 0 when you need a fresh render instead of a cached copy (default cache window is two days).

For more request shapes, see Firecrawl API examples and the Next.js Firecrawl tutorial.

Horizontal flow of Firecrawl action cards Wait, Click, Scroll and Scrape connected by amber arrows
Actions run in order. Each step finishes before the next starts.

How do you scrape JS pages with Apify?

Apify's decision is blunt in their academy: prefer plain HTTP when the HTML or XHR already has the data. Reach for a browser when the page is dynamic, blocked by fingerprinting, or needs real interaction.

CheerioCrawler when the HTML is enough

Cheerio parses the response like jQuery on a string. No browser, no images, no layout.

Apify's own migration story reports roughly 10x faster runs and much higher safe concurrency when the target was actually static. Typical concurrency for HTTP scrapers sits in the 10–50 range. Browser crawlers often stay around 1–5 tabs unless you throw serious RAM at them.

PlaywrightCrawler when JavaScript must run

Use Playwright on Apify when:

  • View Source is empty for the fields you need
  • You must click, type, log in or pick a location
  • The site expects a real browser fingerprint and blocks bare HTTP

Keep extraction logic modular so you can run Cheerio on most routes and Playwright on the stubborn ones. That hybrid pattern is what Apify recommends when only a subset of pages is dynamic.

js
import { PlaywrightCrawler } from 'crawlee';

const crawler = new PlaywrightCrawler({
  async requestHandler({ page, request, log }) {
    await page.goto(request.url, { waitUntil: 'domcontentloaded' });
    await page.locator('.product-card').first.waitFor({ state: 'visible' });
    const titles = await page.locator('.product-card h2').allTextContents();
    log.info(`Got ${titles.length} products from ${request.url}`);
  },
  maxConcurrency: 3,
});

await crawler.run(['https://example.com/catalog']);

Notice the wait: a locator for the first product card, not networkidle. That matches current Playwright guidance.

When should you self-host Playwright on a VPS?

Use a VPS when you need long-running browsers, custom proxy routing, sticky sessions, or you want to keep traffic and cookies off a third-party render farm.

Headless Chromium is memory-hungry. Plan for at least 4 GB RAM for a small worker.

On Hostinger's KVM line (as of 6 November 2026), KVM 1 is about $6.49/mo on the promo term (1 vCPU / 4 GB / 50 GB NVMe) and KVM 2 is about $8.79/mo (2 vCPU / 8 GB). Renewal prices are higher — read the term before you commit.

I recommend Hostinger KVM when you want a cheap dedicated box for Playwright or a small Apify-like worker you control.

Self-host when you already know Playwright and the bottleneck is control. Stay on Firecrawl or Apify when the bottleneck is time-to-first-successful-scrape.

What usually goes wrong on JS-heavy sites?

Empty results with a 200 status

The HTTP status is fine. The body is the shell. Fix the wait or switch to a browser/render path.

networkidle hangs forever

Something on the page keeps a connection open. Switch to a selector or expect_response.

Selector works in DevTools, fails in headless

Class names are hashed or A/B tested. Prefer stable attributes (data-testid, role, text) and keep a fallback. Screenshot on failure so you see the blocked or cookie-wall state.

Infinite scroll returns one viewport

You scraped before the scroll handler ran. Scroll in a loop, wait for the item count to grow, and stop when it stalls. Firecrawl's scroll action plus a selector wait covers many "Load more" buttons without a custom browser script.

For every pattern side by side (page numbers, Next links, cursors, Load more and scroll loops) plus the stop rules that keep a crawl from running forever, see my guide to handling pagination and infinite scroll when scraping.

Blocked after a few dozen pages

Fingerprints, datacenter IPs and bursty concurrency get you challenged. Slow down, respect Retry-After, and read how to avoid proxy bans and CAPTCHAs ethically. Pair that with robots.txt etiquette for scrapers.

You scraped something you should not have

Public HTML is not a free pass. Check robots.txt, the site's terms, and whether the data is personal or login-gated. For the legal framing, start with is web scraping legal — this post is technical, not legal advice.

Checklist graphic with four amber tick items for waits, robots, rate limits and tool choice on a dark charcoal card
Most JS scrape outages are waits, blocks or tool mismatch — not missing CSS knowledge.

Which tool should you pick for your next JS scrape?

Use this as the short decision rule:

  • Data already in HTML or a JSON API → HTTP / Cheerio. Do not open a browser.
  • Need a rendered page as markdown, low ops → Firecrawl with waitFor or actions.
  • Need queues, scheduling, hybrid static+dynamic at scale → Apify Cheerio + Playwright.
  • Need full control, custom proxies, long workers → Playwright on a Hostinger KVM VPS.

The goal is the lightest tool that still returns the fields you need. Heavier is not more professional. It is just more expensive to run and harder to debug.

Frequently asked questions

Do I need Playwright for every modern website?▾
No. Many "JS sites" still ship the fields in the first HTML or expose a JSON endpoint. Check View Source and the Network tab first. Use a browser only when the data appears after client-side rendering or interaction.
What is the difference between Firecrawl waitFor and a wait action?▾
waitFor is a fixed extra delay in milliseconds on top of Firecrawl's smart-wait. A wait action can take either milliseconds or a CSS selector. Prefer the selector form when you know the element that means "ready". Combined waits must stay under 60 seconds.
Why does Playwright networkidle keep timing out?▾
Because Playwright treats networkidle as "no connections for about 500 ms", and many apps never go quiet. Analytics, websockets and long-poll keep the network busy. Wait for your selector or API response instead. Playwright documents networkidle as discouraged for that reason.
Is scraping a JavaScript site legal?▾
It depends on what you collect, how you access it, and the site's terms — not on whether the page used React. robots.txt is a strong etiquette signal but not a statute by itself. Read a practical overview in [is web scraping legal](/blog/is-web-scraping-legal) before you scale a crawler, and stay away from login-gated personal data you are not allowed to have.
Can Firecrawl click Load more and infinite scroll?▾
Yes, through actions. Use click on the Load more control, or scroll, then wait for a selector that only appears after new items render. Cap the loop with your own logic or multiple scrapes so you do not burn the full 60-second wait budget on one page.
Cheerio or Playwright on Apify for a mixed site?▾
Default to Cheerio for routes where View Source already has the data. Route only the dynamic paths through PlaywrightCrawler. Apify's own write-ups show large speed and memory wins when you stop using a browser on static pages.

If your next scrape is a single JS-heavy URL you need as clean markdown, start with Firecrawl and a selector wait. If you are building a queue of mixed sites, start with Apify and keep Playwright off the static routes. Either way, prove the data is missing from View Source before you pay for a browser.

Share