JS Rendering & Browser Control
Learn how to use a render parameter how to define browser instructions in Web Scraper API so you can scrape complex dynamic pages.
JavaScript Rendering
If the page you want to scrape uses JavaScript to load its data into the DOM, add the render parameter to your request. The page is then fully rendered before we return the result, in one of two formats:
html
The raw HTML of the fully rendered page
png
A Base64-encoded screenshot (PNG) of the rendered page
Request sample
curl --user "USERNAME:PASSWORD" \
'https://realtime.oxylabs.io/v1/queries' \
-H "Content-Type: application/json" \
-d '{"source": "universal", "url": "https://www.example.com", "render": "html"}'import requests
from pprint import pprint
# Structure payload.
payload = {
'source': 'universal',
'url': 'https://www.example.com',
'render': 'html',
}
# Get response.
response = requests.request(
'POST',
'https://realtime.oxylabs.io/v1/queries',
auth=('USERNAME', 'PASSWORD'),
json=payload,
)
# Instead of response with job status and results url, this will return the
# JSON response with the result.
pprint(response.json())JavaScript rendering takes more time to scrape the page. Please set timeout on the client side to 180 seconds if using Realtime or Proxy Endpoint integration methods.
To ensure lowest traffic consumption, our system does not load unnecessary assets during page rendering.
Forcing rendering on specific pages
For successful scraping, some page types of specific domains require rendering due to their dynamic content. For these, our system automatically enforces rendering even if you don't set the render parameter, so you always get accurate, reliable data from these otherwise difficult pages.
Please note that rendered jobs consume more traffic compared to non-rendered jobs.
The full list of affected targets is maintained in the file below. We want our users to be fully aware of this when scraping the following pages:
If you wish to disable rendering, you can do so by adding the following parameter to your requests:
Browser instructions
When a page needs interaction, such as clicking a button, entering a search term, or scrolling to load more items, you can define your own browser_instructions that run while the page is rendered.
The easiest way to build browser instructions is the AI-powered visual builder in the Web Scraper API Playground. Read about it here.
Quick start
First of all, browser instructions require the render parameter, either html or png, and are provided as a list in the browser_instructions field. Each item in the list is executed in order.
Say you want to search for pizza boxes on a website — type the term into the search field, click the search button, and wait 5 seconds for the results to load:
The result contains the HTML after the instructions have run:
Scraped HTML should look like this:

Fetching browser resources
We provide a standalone browser instruction for fetching browser resources.
The function is defined here:
Using fetch_resource will result in job returning the first occurrence of a Fetch/XHR resource that matches the format provided instead of the HTML that is being targeted.
Let’s say we want to target a GraphQL resource that is fetched when visiting a product page organically in the browser. We will provide job information as such:
These instructions will result in a result as such:
List of supported browser instructions
General arguments
All the instructions defined below have a consistent set of arguments. The arguments are as follows.
type
Type:
Enum["click", "input", "scroll", "scroll_to_bottom", "wait", "wait_for_element", "fetch_resource"]Description: Browser instruction type.
Required:
true
timeout_s
Type:
intDescription: How long until action is skipped if not completed in time.
Restrictions: 0 <
timeout_s<= 60Default value: 5
wait_time_s
Type:
intDescription: How long to wait before executing next action.
Restrictions: 0 <
wait_time_s<= 60Default value: 0
on_error
Type:
Enum["error", "skip"]Description: Indicator what to do with instructions in case this instruction fails:
"error": Stops the execution of browser instructions."skip": Continues with the next instruction.
Default value:
"error"
Example with general arguments
Instructions
click
Description: Clicks an element and wait a set count of seconds.
Args:
type: str = "click"selector: dicttype: Enum["xpath", "css", "text"]value: str
Example:
input
Description: Enters a text into a selected element.
Args:
type: str = "input"selector: dicttype: Enum["xpath", "css", "text"]value: str
value: str
Example:
scroll
Description: Scrolls a set count of pixels.
Args:
type: str = "scroll"x: inty: int
Example:
scroll_to_bottom
Description: Scrolls to bottom for a set count of seconds.
Args:
type: str = "scroll_to_bottom"
Example:
wait
Description: Waits a set count of seconds.
Args:
type: str = "wait"
Example:
wait_for_element
Description: Waits for element to load for a set count of seconds.
Args:
type: str = "wait_for_element"selector: dicttype: Enum["xpath", "css", "text"]value: str
Example:
fetch_resource
The fetch_resource instruction must be the final instruction in the browser instructions list; any subsequent instructions will not be executed.
Description: Fetches the first occurrence of a Fetch/XHR resource matching the set pattern.
Args:
type: str = "fetch_resource"filter: str(RegEx expression)on_error: Enum["error", "skip"]
Example:
Instruction validation
Any inconsistency in regards to instruction format will result in a 400 status code and a corresponding error message.
For example, payload as such:
Will result in:
Troubleshooting
Status codes
See our response codes outlined here. Status codes in regards to instructions validation are documented here.
Errors and warnings
If there’s an error or warning resulting from your browsing actions, you’ll find it in the outcome under the keys browser_instructions_error or browser_instructions_warnings. For instance, if you’ve sent the following browser instructions and the expected xpath isn’t located on the page, the result will include a warning.
browser_instructions:
Results:
Unexpected error happened while converting browser instructions to actions.
Unexpected error happened while executing {action.type} browser instructions.
Action {action.type} timed out.
Unable to find selector type {selector.type} with value {selector.value} on the page.
Last updated
Was this helpful?

