SDKs

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
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/sdk

Authentication

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:

PropertyTypeDescription
status_codenumberHTTP status code of the API response
dataT (default unknown)Parsed JSON when the API returns JSON, otherwise the response text
headersRecord<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.

ParameterTypeRequiredDefaultDescription
urlstringYes-Target page URL (first argument)
tokenstringNo-Per-request token override
htmlbooleanNotrueReturn HTML content
markdownbooleanNofalseReturn Markdown content
timeoutnumberNo120Page timeout in seconds (1-300)
geo_codestringNo"US"Two-letter country code for geolocation
proxy_countrystring | nullNo-Optional proxy country
browser_renderingboolean | nullNo-true forces browser rendering, false disables it, unset tries without a browser first and falls back automatically
screenshotbooleanNofalseCapture a screenshot. Also forces browser rendering
superbooleanNofalseEnable real device routing
use_proxybooleanNotrueAllow the service to use a proxy
proxystring | nullNo-Custom proxy in username:password@host:port format
home_pagebooleanNofalseVisit the site's root page before the target URL
wait_for_selectorstring | nullNo-CSS selector to wait for before returning content
block_resourcesboolean | nullNofalseBlock images, CSS, and fonts to speed up the request
bypass_proxybooleanNofalseEnable the API's proxy bypass behavior
cookie_jarstring | nullNo-Cookie configuration, e.g. "domain=example.com&country=us&max_used=100&max_age=50m"
headersobject | string | nullNo-Headers forwarded to the target site, as an object or JSON string
max_retriesnumberNo3Maximum number of retries
token_capnumber | nullNo-Optional token budget for retries
streamboolean | nullNo-Request a streamed response. The SDK buffers it into the normal return value
discard_token_secretstringNo""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.

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:

ParameterTypeRequiredDefaultDescription
urlstringYes-Search query or Google search URL (first argument)
tokenstringNo-Per-request token override
rawbooleanNotrueReturn HTML. When true, format is ignored
format"json" | "html"No"json"Response format. Only used when raw is false
regionstring | nullNo-Country code (e.g., "us")
languagestring | nullNo-Language code (e.g., "en")
pagenumber | nullNo-Result page, starting at 1
render_jsbooleanNofalseRender JavaScript-dependent result features
timeoutnumberNo600Request 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:

ParameterTypeRequiredDefaultDescription
tokenstringNo-Per-request token override
timeoutnumberNo30HTTP request timeout in seconds. Must be positive

Account summary (result.data, typed as AccountSummary):

PropertyTypeDescription
subscription_statusstring | nullSubscription status, such as "active"
enterprisebooleanWhether the account is on an enterprise plan
token_usagenumberTokens used in the current period
token_limitnumberToken limit for the current period
token_remainingnumberRemaining tokens, never below 0
usage_percentnumberToken usage as a percentage of the limit
rate_limitnumberRequest rate limit
rate_ttlnumberRate-limit window
auto_renewbooleanWhether the subscription renews automatically
ends_atstring | nullSubscription end date
userobjectname, 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

PropertyTypeDescription
messagestringHuman-readable error message
statusnumber | undefinedHTTP status code (401, 429, 500, etc.) or undefined for network errors
namestringAlways "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 MrScraperError before accessing error properties
  • Log errors with appropriate context for debugging
  • Implement retry logic for network errors (when status is undefined)
  • 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 2Version 3
fetch_content(url, options)scraper_api(url, options)
google_serp(queryOrUrl, options)web_search(queryOrUrl, options)
FetchContentOptionsScraperApiOptions
GoogleSerpOptionsWebSearchOptions

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 fetchHtml with scraper_api and googleSerp with web_search. Both now return a response wrapper instead of only the API payload, and options use snake_case (for example, geoCode is now geo_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 MethodMrScraper Equivalent
Scrape a URL with HTML or Markdown outputscraper_api with html: true and/or markdown: true
Scrape a URL with a screenshotscraper_api with screenshot: true
Searchweb_search

On this page