Node.js SDK
Install the official @mrscraper/sdk package to fetch page content with the Scraper API and get Google search results from your Node.js applications.
The official @mrscraper/sdk package exposes three functions: scraper_api to fetch page content (HTML, Markdown, or screenshots), web_search to get Google search results, and account to check your subscription and token usage from your Node.js applications.
Requirements
- Node.js 18 or later
- ES Modules enabled in your
package.json
{
"type": "module"
}Package Information
This page documents version 3.1.0. See @mrscraper/sdk on npm for the latest release, version history, and installation details.
Installation
Install the SDK using npm:
npm install @mrscraper/sdkAuthentication
Set your API token as an environment variable. The SDK reads MRSCRAPER_API_TOKEN automatically. You can get your API token from the MrScraper dashboard.
export MRSCRAPER_API_TOKEN="MRSCRAPER_API_TOKEN"Token Override
All functions accept an optional token in their options object if you need to override MRSCRAPER_API_TOKEN for specific requests.
For more information on generating API tokens, see the Generate Token guide.
Quick Start
import { scraper_api, web_search, account, MrScraperError } from "@mrscraper/sdk";
try {
// 1. Fetch page content
const page = await scraper_api("https://example.com");
console.log(page.status_code, page.data);
// 2. Search Google
const search = await web_search("python web scraping", { raw: false });
console.log(search.data);
// 3. Check remaining tokens
const status = await account();
console.log(status.data.token_remaining);
} catch (err) {
if (err instanceof MrScraperError) {
console.error(`[${err.status ?? "network"}] ${err.message}`);
} else {
throw err;
}
}Response Format
All functions are async and resolve to a MrScraperResponse object:
| Property | Type | Description |
|---|---|---|
status_code | number | HTTP status code of the API response |
data | T (default unknown) | Parsed JSON when the API returns JSON, otherwise the response text |
headers | Record<string, string> | Response headers |
You can type data with a generic parameter:
const result = await scraper_api<string>("https://example.com");Core Methods
Scraper API
Use scraper_api to fetch a page through the MrScraper Scraper API. The service handles JavaScript rendering, bot detection, and optional geolocation proxying.
import { scraper_api } from "@mrscraper/sdk";
const result = await scraper_api("https://example.com", {
html: true,
markdown: true,
screenshot: true,
geo_code: "US",
timeout: 120,
// token: "optional_override_token"
});
console.log(result.data);Parameters:
The first argument is the target URL. All other parameters go in the optional options object.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Yes | - | Target page URL (first argument) |
token | string | No | - | Per-request token override |
html | boolean | No | true | Return HTML content |
markdown | boolean | No | false | Return Markdown content |
timeout | number | No | 120 | Page timeout in seconds (1-300) |
geo_code | string | No | "US" | Two-letter country code for geolocation |
proxy_country | string | null | No | - | Optional proxy country |
browser_rendering | boolean | null | No | - | true forces browser rendering, false disables it, unset tries without a browser first and falls back automatically |
screenshot | boolean | No | false | Capture a screenshot. Also forces browser rendering |
super | boolean | No | false | Enable real device routing |
use_proxy | boolean | No | true | Allow the service to use a proxy |
proxy | string | null | No | - | Custom proxy in username:password@host:port format |
home_page | boolean | No | false | Visit the site's root page before the target URL |
wait_for_selector | string | null | No | - | CSS selector to wait for before returning content |
block_resources | boolean | null | No | false | Block images, CSS, and fonts to speed up the request |
bypass_proxy | boolean | No | false | Enable the API's proxy bypass behavior |
cookie_jar | string | null | No | - | Cookie configuration, e.g. "domain=example.com&country=us&max_used=100&max_age=50m" |
headers | object | string | null | No | - | Headers forwarded to the target site, as an object or JSON string |
max_retries | number | No | 3 | Maximum number of retries |
token_cap | number | null | No | - | Optional token budget for retries |
stream | boolean | null | No | - | Request a streamed response. The SDK buffers it into the normal return value |
discard_token_secret | string | No | "" | Value sent in the x-discard-token-secret request header |
Tip
Setting screenshot: true always enables browser rendering, even if you pass browser_rendering: false.
For more examples of what you can fetch, see Scrape HTML, Scrape Markdown, and Get Screenshot.
Web Search
Use web_search to get Google search results. The first argument accepts either query text or a full Google search URL.
import { web_search } from "@mrscraper/sdk";
const result = await web_search("python web scraping", {
raw: false,
format: "json",
region: "us",
language: "en",
page: 1,
// token: "optional_override_token"
});
console.log(result.data);You can also pass a Google search URL. The SDK extracts the q, gl, hl, and start parameters, and any options you pass explicitly override the values from the URL:
const result = await web_search(
"https://www.google.com/search?q=iphone+17&gl=us&hl=en",
);Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Yes | - | Search query or Google search URL (first argument) |
token | string | No | - | Per-request token override |
raw | boolean | No | true | Return HTML. When true, format is ignored |
format | "json" | "html" | No | "json" | Response format. Only used when raw is false |
region | string | null | No | - | Country code (e.g., "us") |
language | string | null | No | - | Language code (e.g., "en") |
page | number | null | No | - | Result page, starting at 1 |
render_js | boolean | No | false | Render JavaScript-dependent result features |
timeout | number | No | 600 | Request timeout in seconds |
Note
raw defaults to true, so results are returned as HTML unless you set raw: false. To get structured JSON, pass raw: false and format: "json".
Account
Use account to check the identity, subscription, token quota, and rate limits of the account that owns the API token.
import { account } from "@mrscraper/sdk";
const result = await account({
timeout: 30,
// token: "optional_override_token"
});
console.log(result.data.subscription_status);
console.log(result.data.token_remaining);
console.log(result.data.user.email);Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
token | string | No | - | Per-request token override |
timeout | number | No | 30 | HTTP request timeout in seconds. Must be positive |
Account summary (result.data, typed as AccountSummary):
| Property | Type | Description |
|---|---|---|
subscription_status | string | null | Subscription status, such as "active" |
enterprise | boolean | Whether the account is on an enterprise plan |
token_usage | number | Tokens used in the current period |
token_limit | number | Token limit for the current period |
token_remaining | number | Remaining tokens, never below 0 |
usage_percent | number | Token usage as a percentage of the limit |
rate_limit | number | Request rate limit |
rate_ttl | number | Rate-limit window |
auto_renew | boolean | Whether the subscription renews automatically |
ends_at | string | null | Subscription end date |
user | object | name, email, and verified |
Note
API keys, billing identifiers, and sensitive response headers are excluded from the result.
TypeScript Types
The package ships its own type definitions:
import type {
ScraperApiOptions,
WebSearchOptions,
AccountOptions,
AccountSummary,
MrScraperResponse,
} from "@mrscraper/sdk";Error Handling
All functions reject with MrScraperError for API, authentication, network, and timeout failures. Invalid options throw a TypeError or RangeError before any request is sent.
Exception Properties
| Property | Type | Description |
|---|---|---|
message | string | Human-readable error message |
status | number | undefined | HTTP status code (401, 429, 500, etc.) or undefined for network errors |
name | string | Always "MrScraperError" |
Example Error Handling
import { scraper_api, MrScraperError } from "@mrscraper/sdk";
try {
await scraper_api("https://example.com");
} catch (err) {
if (err instanceof MrScraperError) {
console.error(`Error: ${err.message}`);
console.error(`Status: ${err.status ?? "network error"}`);
} else {
// Handle unexpected errors
throw err;
}
}Best Practices
- Always wrap SDK calls in try-catch blocks
- Check
err instanceof MrScraperErrorbefore accessing error properties - Log errors with appropriate context for debugging
- Implement retry logic for network errors (when
statusisundefined) - Verify your API token if you encounter status
401
Migrating from Earlier Versions
From Version 3.0
Version 3.1.0 adds the account function and the AccountOptions and AccountSummary types. No existing functions changed.
From Version 2
Version 3 renames the public functions and their option types. Request options and the { status_code, data, headers } response are unchanged.
| Version 2 | Version 3 |
|---|---|
fetch_content(url, options) | scraper_api(url, options) |
google_serp(queryOrUrl, options) | web_search(queryOrUrl, options) |
FetchContentOptions | ScraperApiOptions |
GoogleSerpOptions | WebSearchOptions |
The version 2 names are no longer exported.
From Version 1
fetchHtml, googleSerp, and all AI scraper, manual scraper, and results functions (createAiScraper, rerunAiScraper, bulkRerunAiScraper, rerunManualScraper, bulkRerunManualScraper, getAllResults, getResultById) were removed in version 2.
- Replace
fetchHtmlwithscraper_apiandgoogleSerpwithweb_search. Both now return a response wrapper instead of only the API payload, and options usesnake_case(for example,geoCodeis nowgeo_code). - For scrapers and results, call the REST API directly.
Migration from Firecrawl
If you're migrating from the Firecrawl Node SDK, use this mapping to find equivalent MrScraper functions.
| Firecrawl Method | MrScraper Equivalent |
|---|---|
| Scrape a URL with HTML or Markdown output | scraper_api with html: true and/or markdown: true |
| Scrape a URL with a screenshot | scraper_api with screenshot: true |
| Search | web_search |
Python SDK
Install and use mrscraper-sdk, the typed async Python client for the MrScraper API, to fetch page content with the Scraper API and get Google search results with asyncio.
LangChain SDK
Use MrScraper as LangChain tools via the langchain-mrscraper package—fetch HTML, run AI and manual scrapers, and list results from agents.