ScraperFlyAI-ready Web Data API

request control

Scraping API User-Agent Header control

Request headers can influence how public pages respond. ScraperFly helps teams set User-Agent deliberately, compare desktop and mobile variants, keep request context reproducible, and combine headers with rendering, sessions, routing, and response formats only when evidence supports it.

Client context

Send the User-Agent that makes the response reproducible

User-Agent is one of the clearest request signals a public website can read. It can influence layout, device variant, content order, language hints, redirects, lazy loading, and how a target page responds to the same URL.

ScraperFly helps teams treat that signal deliberately: compare a clean baseline, choose a consistent client context, and keep header choices visible alongside rendering, sessions, routing, and output format.

User-Agentrequest contextbaseline comparison
Developers comparing desktop and mobile page responses using User-Agent request context

What is the User-Agent header in web scraping?

The User-Agent header is a request header that describes the client making the HTTP request. In web scraping workflows, it helps define the client context a public target sees when it returns a page. That context can affect whether the target returns a desktop layout, a mobile layout, a simplified page, a localized variant, a fallback response, or markup shaped for a particular browser family.

User-Agent should not be treated as a trick. It is part of the request profile. A good scraping workflow keeps it explicit, testable, and reproducible. If the target response changes when the User-Agent changes, the team can document that behavior and choose the signal that matches the data, layout, and output format the product needs.

Practical takeaway: set User-Agent when it makes public page capture more consistent, not because every request needs a custom header.

When should a scraping workflow set User-Agent?

Set User-Agent when the target response depends on client context. A public page may return different navigation, product cards, links, cookie prompts, mobile markup, lazy-loading behavior, or content blocks depending on the browser signal it receives. For teams building parsers, monitors, AI ingestion, or QA workflows, those differences can decide whether the response is useful.

The first step is comparison. Fetch the page with a baseline request, then test the User-Agent context that matches the intended workflow. Compare status, final URL, content type, response size, HTML structure, rendered output, text, Markdown, screenshot state, and the fields your downstream code expects. If the header changes the page in a useful way, keep it in the request profile. If it does not, leave the request simpler.

Target behavior Why User-Agent may matter What to compare
Desktop and mobile layouts differ The parser may need one stable template DOM structure, visible text, links, and screenshot state.
Content order changes by client Cards, filters, or navigation can move Target fields and selector stability across samples.
Fallback or simplified page appears The target may return a different response shape Status, content type, response size, and final URL.
Rendering behavior changes Frontend code can branch by client context Raw HTML versus rendered HTML and screenshot evidence.
Regional or consent state varies User-Agent may combine with language, cookies, or routing Headers, sessions, country context, and visible page state.

How is User-Agent different from custom headers?

User-Agent is one header inside the broader request context. Other headers can carry accepted language, content type expectations, referrer context, cookies, or application-specific request details when the public workflow requires them. User-Agent is often the most visible because many websites use it to decide which layout or client experience to return.

A clean integration keeps each header purposeful. Do not bundle a large set of headers into every request just because one target needed one signal. Start with the minimum context that returns the right public page, then add headers only when samples show they improve consistency. For broader request-context planning, the custom headers scraping API page covers how headers fit into the full request profile.

Do User-Agent headers replace rendering, sessions, or routing?

No. Headers, rendering, sessions, and routing solve different problems. User-Agent changes client context. Rendering runs browser execution when content is built by JavaScript. Sessions preserve state across related requests. Routing changes delivery path or geography when target behavior varies by network or location. A page may need one of these controls, several of them, or none of them.

The practical path is to isolate the variable. Test User-Agent first when the question is client shape. Test JavaScript rendering when the page source is incomplete. Use sessions when related requests depend on shared cookies or continuity. Review routing only when response evidence suggests a delivery or location difference rather than a header mismatch.

Control What it changes Use it when Do not use it for
User-Agent Client identity signal The target returns different public page variants by client context Solving every access or JavaScript problem.
Other headers Language, accepted formats, referrer, or request context The public workflow needs explicit header context Copying unrelated browser headers blindly.
Rendering Browser execution and rendered page state Useful content appears after JavaScript runs Static pages where source HTML already contains the data.
Sessions Continuity across related requests Cookies or shared state affect the next public response Independent pages with no state dependency.
Routing Network or country delivery context Response evidence shows location or route changes the result Header mismatches or parser assumptions.

How should teams debug User-Agent differences?

Debugging starts with side-by-side samples. Capture the same URL with the baseline profile and the intended User-Agent context. Compare final URL, status, content type, response size, HTML structure, rendered page, screenshot, and extracted fields. If the page changes layout, check whether your parser expects the right variant. If the page becomes incomplete, inspect whether the missing content is a rendering issue, a consent state, a cookie state, or a target template difference.

Usage evidence matters here. A log that records the request profile makes it easier to reproduce a good result and explain a bad one. When multiple teams touch the workflow, explicit User-Agent handling prevents silent drift: the parser, QA reviewer, and backend integration all know which client context produced the captured page.

How does User-Agent choice affect cost?

User-Agent itself is a lightweight control compared with browser rendering, visual files, premium routing, or long waits. It can even reduce cost when it helps a team avoid unnecessary escalation. If a target simply needs consistent client context, a deliberate header profile may be enough. If the page still returns incomplete content, then rendering, wait timing, sessions, or routing can be tested separately.

That is the ScraperFly buying path in miniature: start with the smallest request that can prove the target, add the next control only when evidence supports it, and keep request weight visible before volume grows. The API Builder helps compare request profiles, while pricing and the credit cost calculator help estimate the workflow after the profile is known.

Where should developers start?

Start with one representative public URL. Fetch it with the lightest profile, then test the User-Agent context your workflow expects. If the result changes, decide whether the desktop, mobile, rendered, or localized variant is the correct source for your product. Choose the output format that fits the downstream consumer: HTML for parsers, text or Markdown for content workflows, JSON metadata for diagnostics, screenshots or PDFs for visual proof.

The goal is simple: make request context explicit enough that every scrape is easier to reproduce, debug, and scale.

User-Agent requirements

Set client context when the target varies by request signal

Some public pages change markup, layout, content order, language hints, redirects, or rendering behavior based on User-Agent. Compare the response against a baseline so the final profile is intentional and easy to reproduce.

Raw HTML response mapped to visible page data
01

Raw HTML availability

Check whether the fields you need are already present in the first HTML response.

Best first test for simple pages, articles, docs, listings, and product details.

Before and after JavaScript rendering comparison
02

JavaScript dependency

Compare raw HTML with the rendered DOM or screenshot before turning on browser rendering.

Use rendering when raw HTML is only a shell and scripts create the useful content.

Cookies, consent, session and access context for scraping
03

State & access context

Identify whether cookies, consent, login boundaries, pagination, or the same visitor state affect the response.

Use sessions and headers when continuity changes the data you receive.

Regional content variations across countries and routes
04

Geo/content variation

Test whether country, language, currency, inventory, SERP, ads, or route reputation changes the result.

Use geo or premium routing only when the target proves the response varies by route.

Checks before setting User-Agent

Where is the target field?

Find whether the field exists in raw HTML, rendered DOM, an API call, structured data, a file, or a later interaction state.

What changes the response?

Sample a few URLs and compare status, final URL, content length, redirects, empty states, and visible result differences.

What context is required?

Mark any dependency on consent, locale, cookies, headers, authentication boundary, pagination, filters, or previous requests.

What does failure look like?

Define the signals for blocked, partial, stale, redirected, empty, timed-out, or region-mismatched responses before scaling.

How User-Agent changes scraping setup

Fetch mode

Raw HTML availability decides whether the first request can stay simple or needs rendering, waits, screenshots, or extraction.

Request context

State requirements decide whether to add headers, cookies, sessions, consent handling, or a stable visitor profile.

Routing choice

Geo and reputation findings decide whether standard routing is enough or a country/premium route is justified.

Validation rules

Known failure states become checks for retries, escalation, QA review, and deciding when a lighter profile is still complete.

Header-aware request builder

Build scraping requests with the client signal your workflow needs

User-Agent belongs in the request profile when it produces a better public response. Test the impact first, then combine headers with rendering, sessions, country routing, or stronger delivery only when evidence supports it.

UA
Baseline

Compare User-Agent variants against a clean baseline

Status, final URL, content type, response size, and output shape reveal whether the signal changes the result.

User-Agentbaseline
MOB
Device behavior

Check mobile and desktop differences before parsing

Responsive pages can change navigation, content order, links, overlays, or lazy loading by client context.

desktopmobile
HDR
Controls

Keep headers separate from heavier choices

A header can be enough for some pages; others need rendering, sessions, country targeting, or stronger routing.

headersrender

Controls that shape User-Agent scraping

url

The public page being fetched.

headers

Request context such as User-Agent when needed.

format

The response shape used to compare output.

render

Browser execution when client context affects rendered behavior.

cURL example

Generate Markdown with the same request shape you can move into production

curl "https://scraperfly.com/api/v1?url=https%3A%2F%2Fexample.com&format=markdown" \
  -H "apikey: YOUR_API_KEY"

Header cost control

Use lightweight request context before reaching for heavier controls

A deliberate User-Agent is often lighter than browser rendering, visual capture, or stronger routing. Test whether client context solves the target first, then add heavier controls only when the response proves they matter.

A lightweight HTML request returning a simple response
01

Basic fetch

Use a basic fetch when public HTML already contains the fields you need.

Lightest request profile; keep it when the response is complete.

JavaScript rendering producing a complete DOM
02

Rendering

Use rendering when raw HTML is a shell and JavaScript completes the page.

Heavier profile; use it only when browser output changes the result.

Several requests preserving cookies and visitor state
03

Stateful session

Use sessions when cookies, consent, locale, or pagination change the response.

Heavier state profile; preserve it only when continuity matters.

Request routing through geo and higher quality routes
04

Premium routing & geo

Use premium routing or geo only when origin, country, reputation, or regional content changes the result.

Heaviest routing profile; apply it only to targets that prove they need it.

What can make User-Agent workflows heavier

More infrastructure work

Browser rendering, routing choices, and longer waits mean the platform has to do more than return a simple response.

More target uncertainty

Redirects, empty states, rate limits, and challenge pages often require stronger delivery options or retries.

More state to preserve

Cookies, sessions, consent, and multi-page flows add moving parts that a plain stateless fetch does not have.

More evidence to return

Screenshots, PDFs, rendered output, and richer response artifacts are useful, but they are heavier than plain HTML.

How to keep header-based scraping predictable

Sample before scale

Test a small URL set first and group targets by the lightest profile that returns complete data.

Do not render by default

Inspect raw HTML before turning on rendering. Many public pages already contain the data you need.

Escalate by evidence

Move up only when the response shows missing content, state dependency, geo variance, or routing problems.

Measure useful results

Optimize around valid records delivered, not raw request volume. A lighter profile is best only when it stays complete.

Header FAQ

Common questions about User-Agent and header-based scraping

User-Agent is useful when it changes public page behavior. Keep it tested, documented, and tied to response evidence.

Header answers
Signal

What User-Agent changes

User-Agent helps define the client context seen by the target.

What is User-Agent in scraping?

User-Agent is a request header that describes the client making the request. Some public pages use it to choose desktop, mobile, or browser-specific response variants.

When should I set User-Agent?

Set it when baseline samples show that client context changes the response in a way that matters for parsing, monitoring, rendering, or visual proof.

Testing

How to compare responses

Treat User-Agent as a testable variable, not a hidden default.

What should I compare after changing User-Agent?

Compare final URL, status, content type, response size, HTML structure, rendered output, screenshot state, and extracted fields.

Should I copy every browser header?

No. Use the minimum header context that improves the public response and keep each added header tied to evidence.

Controls

Headers with other options

Headers work alongside rendering, sessions, and routing when the target needs them.

Do headers replace rendering?

No. Headers affect request context. Rendering runs browser execution when JavaScript builds useful content after the initial response.

Can User-Agent work with sessions?

Yes. Headers and sessions can be combined when a public workflow needs both client context and continuity across related requests.

Cost

Keeping it practical

Header context should keep workflows clearer, not heavier by habit.

Can User-Agent reduce request cost?

It can help when a lightweight header profile returns the right page without unnecessary rendering, routing, or visual capture.

Does User-Agent guarantee access?

No. It helps define request context, but access, routing, timing, and target-response problems still need separate evidence.