Skip to main content
This reference documents every function available in Bright Data Scraper Studio’s IDE: the interaction code that controls a browser session, and the parser code that turns HTML into structured records. Each function lists its parameters, return value, and a runnable example.
Functions marked with work only with the Browser worker and throw an error when called from a Code worker. See Browser-only functions for the full list.

How is Scraper Studio code organized?

A Bright Data Scraper Studio scraper uses two code types: You move data from one to the other with parse() (which runs the parser) and collect() (which appends a record to the final dataset).

Interaction functions

Interaction functions run in the scraper’s main JavaScript context and drive the browser or HTTP client. Use them to navigate, wait for elements, interact with the page, capture network traffic, and hand off data to the parser.

Global objects

Navigates the browser to a URL. A 404 status throws a dead_page error by default; override with allow_status. Parameters

request, Make a direct HTTP request

Sends an HTTP request without using a browser. Use on Code worker, or on Browser worker when you want to bypass the browser. Parameters

next_stage, Queue input for the next stage

Runs the next stage of the scraper in a new browser session with the given input. Parameters

run_stage, Run a specific stage

Runs a named stage of the scraper in a new browser session. Parameters

rerun_stage, Re-run the current stage with new input

Runs this stage again with a new input. Use it to fan out work (for example, one re-run per page in a pagination).

load_sitemap, Read URLs from an XML sitemap

Loads a sitemap XML file and returns the URL list. Supports sitemap indexes and gzip-compressed sitemaps. Parameters

resolve_url, Follow a URL through redirects

Returns the final URL that the given URL argument leads to. Parameters

redirect_history, Get the redirect chain

Returns the history of URL redirects since the last navigate() call.

response_headers, Read the last response headers

Returns the response headers from the last page load.

status_code, Read the last response status

Returns the HTTP status code of the last page load.

Waiting on the page ⭐

All wait functions are Browser worker only.

wait, Wait for an element to appear

Parameters

wait_any, Wait for any of several conditions

Waits for any matching condition to succeed. Returns when the first selector resolves.

wait_visible, Wait for an element to be visible

Parameters

wait_hidden, Wait for an element to disappear

Parameters

wait_for_text, Wait for text content

Waits for an element on the page to contain the given text. Parameters

wait_for_parser_value, Wait for a parser field to be populated

Use after tag_response() or tag_script() to wait until the captured data is available. Parameters

wait_network_idle, Wait until the browser network settles

Waits until the browser network has been idle for a given period. Parameters

wait_page_idle, Wait until DOM mutations stop

Waits until no changes are made to the DOM tree for a given period. Parameters

Element interaction ⭐

All interaction functions require Browser worker.

click, Click an element

Clicks an element, waiting for it to appear first. Parameters

right_click, Right-click an element

Same as click but uses the right mouse button.

hover, Hover over an element

Moves the cursor over an element, waiting for it to appear first.

mouse_to, Move the cursor to a coordinate

Parameters

type, Enter text into an input

Waits for the input to appear, then types the given text. Parameters

press_key, Press a special key

Types special keys like Enter or Backspace in the currently focused input.

select, Pick a value from a select element

Parameters

scroll_to, Scroll an element into view

Scrolls the page so a target element is visible. Defaults to natural scrolling; pass immediate: true to jump.

scroll_to_all, Scroll through every matching element

load_more, Trigger lazy-loaded content

Scrolls to the bottom of a list to trigger infinite-scroll loading. Parameters

close_popup, Auto-close popups in the background

Registers a background watcher that closes a popup whenever it appears. See Best practices for the recommended pattern. Parameters

solve_captcha, Solve CAPTCHAs on the page

bounding_box, Get an element’s page coordinates

Returns the page-relative bounding box of the first matched element. Parameters

el_exists, Check if an element is on the page

Parameters

el_is_visible, Check if an element is visible

Parameters

track_event_listeners, Start tracking browser event listeners

Must be called before disable_event_listeners().

disable_event_listeners, Disable event listeners

Stops all event listeners from running on the page. Parameters

freeze_page, Stop further page changes

Forces the page to stop changing, so HTML snapshots reflect exactly what the scraper saw. Experimental.

Network and response tagging ⭐

Tagging captures background network traffic and exposes it to the parser. All tag_* functions are Browser worker only.

tag_response, Save one matching response

Saves the response data from a matching browser request. Parameters

tag_all_responses, Save every matching response

Saves the response data from every matching request as an array.

tag_script, Extract JSON embedded in a <script> tag

Parameters

tag_window_field, Tag a value on the browser window

Parameters

tag_image, Capture an image URL from a DOM element

tag_video, Capture a video URL from a DOM element

Parameters

tag_screenshot, Save a screenshot of the page

Parameters

tag_download, Capture files downloaded by the browser

Parameters

tag_serp, Parse the page as a search engine result page

Parameters

capture_graphql, Capture and replay GraphQL queries

Captures a GraphQL request so you can replay it with different variables. Parameters

Data collection

parse, Run the parser code

Runs the parser code and returns the structured result.

collect, Append a record to the dataset

Adds one record to the scraper’s output. Parameters

set_lines, Set output lines, overriding previous calls

Each call to set_lines() overrides the previous one. Useful when the scraper collects partial data and you want the last known state delivered if a later step throws. Parameters

load_html, Load an HTML string into Cheerio

Parameters

Marking a crawl as a failure

bad_input, Mark the input as invalid

Prevents any retries and reports error_code=bad_input.

blocked, Mark the page as blocked

Reports that the site refused access. error_code=blocked.
Flags the page so it can be filtered from future collections. error_code=dead_page.

detect_block, Detect blocking conditions on the page

Parameters

Session and routing

country, Route through a specific country

Parameters

proxy_location, Fine-grained proxy location

Prefer country() unless you need precise geographic control. Parameters

preserve_proxy_session, Reuse the proxy session across child stages

Parameters

set_session_headers, Set extra HTTP headers

Parameters

Browser configuration ⭐

Browser worker only.

browser_size, Get the current browser window size

Returns {width, height} in pixels.

emulate_device, Emulate a mobile device

Switches the user agent, screen resolution, and device pixel ratio to match a named device. Parameters
  • Blackberry PlayBook / landscape
  • BlackBerry Z30 / landscape
  • Galaxy Note 3 / landscape
  • Galaxy Note II / landscape
  • Galaxy S III / S5 / S8 / S9+ (each with landscape)
  • Galaxy Tab S4 / landscape
  • iPad / iPad Mini / iPad Pro / iPad Pro 11 / iPad (gen 6) / iPad (gen 7) (each with landscape)
  • iPhone 4, 5, 6, 6 Plus, 7, 7 Plus, 8, 8 Plus, SE, X, XR, 11, 11 Pro, 11 Pro Max, 12 / 12 Mini / 12 Pro / 12 Pro Max, 13 / 13 Mini / 13 Pro / 13 Pro Max (each with landscape)
  • JioPhone 2 / landscape
  • Kindle Fire HDX / landscape
  • LG Optimus L70 / landscape
  • Microsoft Lumia 550, 950 (950 with landscape)
  • Nexus 4, 5, 5X, 6, 6P, 7, 10 (each with landscape)
  • Nokia Lumia 520 / landscape, Nokia N9 / landscape
  • Pixel 2, 2 XL, 3, 4, 4a (5G), 5 (each with landscape)
  • Moto G4 / landscape

font_exists, Check browser font support

Asserts that the browser can render the given font family.

html_capture_options, Configure HTML capture

Controls how the HTML snapshot is captured. Parameters

embed_html_comment, Inject a comment into the page HTML

Embeds metadata inside HTML snapshots.

Debugging and observability

console, Log from interaction code

verify_requests, Monitor failed browser requests

Fires a callback on every failed browser request. Parameters

Value constructors

Bright Data Scraper Studio provides typed constructors for structured output fields.

Image, Video, Pdf, Doc, Money

Supported downloaded file types

Scraper Studio supports downloading files through media and document field constructors. Use:
  • new Image() for image files
  • new Video() for video files
  • new Pdf() for PDF files
  • new Doc() for supported document, text, audio, video, and structured file types

Supported new Doc() content types

new Doc() supports the following content types:
example:

URL

Standard Node.js URL class.

Parser functions

Parser code runs after interaction code calls parse(). It receives the captured HTML and any tagged data, and returns a single record (or array of records) to the interaction code. Parser code uses Cheerio, a jQuery-compatible HTML parser.

Globals available in parser code

Cheerio helpers

Bright Data Scraper Studio adds custom Cheerio methods on top of the standard API.

$(selector).text_sane(), Normalize whitespace

Returns text() with all whitespace runs collapsed to a single space and trimmed.

$(selector).filter_includes(text), Filter elements by text content

Filters a selection to elements whose text includes the given substring. Chainable with the rest of the Cheerio API.

Parser value constructors

Image, Video, PDF and Money are also available in parser code and work the same way.

Validate downloaded media type

Use validate_type to check that the downloaded file content matches the expected media type. This option is supported by new Pdf(), new Image(), and new Video(). When validate_type is enabled, Scraper Studio validates the downloaded file after fetching it. If the file content does not match the expected type, the field returns an error instead of a valid downloaded file. Example:
Validation failure example:
For full Cheerio API documentation, see the Cheerio website.

Shadow DOM support

Interaction commands that accept a selector also accept an array of selectors, letting you reach into Shadow DOM trees. Use this with click, wait, type, and other interaction functions. When you pass an array:
  • One selector must target the shadow host element
  • Every selector after it is resolved inside that shadow root
In that example, my-shadow-host is the element with the shadow root attached, and button.submit is resolved inside that shadow root.

Browser-only functions

The following functions require Browser worker and throw not_supported_in_code_worker when called from a Code worker. Use this list to decide which worker your scraper needs. See Worker types to choose between Browser worker and Code worker.

Best practices

Recommended patterns for writing fast, reliable scrapers

Worker types

When to use Browser worker vs Code worker

Basics of web scraping

Core concepts: interaction, parsing, stages, and scale

Develop a scraper

Step-by-step walkthrough of building a scraper in the IDE