SDKs

Node.js SDK

Install the official @mrscraper/sdk package to retrieve pages as HTML, Markdown, or screenshots, extract brand details and structured JSON, search the web, and check account status from Node.js.

The official @mrscraper/sdk package is an async JavaScript and TypeScript client for the seven MrScraper services. Its functions share their descriptions, parameter meanings, and defaults with the MCP server, the CLI, the Python SDK, and the other integrations.

FunctionDescription
statusReturn the raw account status API response without summarizing, redacting body fields, or adding calculated fields.
scrapeHtmlRetrieve the raw HTML of a page. Browser rendering is optional.
scrapeMarkdownRetrieve a page as clean Markdown. Browser rendering is optional.
getScreenshotCapture a base64 PNG screenshot of the full page, the first viewport, or a custom viewport. Browser rendering is always enabled.
scrapeBrandExtract a website's colors, typography, logos, and social links as JSON.
scrapeJsonExtract structured JSON from a page using a natural-language prompt. Append Json Schema: and a JSON schema to shape the output.
webSearchSearch the web and return ranked results with titles, URLs, descriptions, and sources.

Requirements

  • Node.js 18 or later
  • ES modules: save examples as .mjs files or set "type": "module" in your package.json

Package Information

This page documents version 7.0.0. Version 7.0.0 removes super, proxyCountry, proxy, waitUntil, returnCookie, and saveResult, adds maxAge, accepts custom screenshot viewports, and always saves page results to your dashboard. See Migrating from version 6. See @mrscraper/sdk on npm for the latest release and version history.

Installation

npm install @mrscraper/sdk

Authentication

Get an API key from the MrScraper app and set it as an environment variable:

export MRSCRAPER_API_TOKEN="YOUR_TOKEN"

Every function accepts an optional token in its options object. The SDK uses a nonempty token option first, then MRSCRAPER_API_TOKEN, then MRSCRAPER_API_KEY. Credentials are sent in request headers, never in the request URL.

For more information on generating API tokens, see the Generate Token guide.

Quick Start

import { scrapeHtml } from "@mrscraper/sdk";

const result = await scrapeHtml("https://example.com", {
  browserRendering: true,
  warmStart: true,
  waitForSelector: "body",
  timeout: 120,
  maxRetries: 0,
});
console.log(result.data);

Examples use example.com as the sample target. Replace it for your use case. Scraping and search calls use tokens from your plan.

Response Format

Every function resolves to a MrScraperResponse<T> object:

PropertyTypeDescription
status_codenumberHTTP status code of the API response
dataT (default unknown)The API response body. JSON becomes JavaScript values, text stays a string, and binary bodies become a Node.js Buffer
headersRecord<string, string>Response headers. Sensitive headers are removed for status

Field names inside data are returned as the API sends them and are not converted to camelCase.

{
  "status_code": 200,
  "data": "<html><body>Example page content...</body></html>",
  "headers": {
    "content-type": "text/html; charset=utf-8"
  }
}

Response examples below show selected keys with placeholder values. Actual responses may contain additional fields.

Shared Parameters

The first argument is the target URL (or the search query for webSearch). All other parameters go in the optional options object, which also accepts token. Omit an optional control or pass undefined to leave it unset; explicit false and 0 are sent as given.

Page controls

scrapeHtml, scrapeMarkdown, getScreenshot, and scrapeJson accept these options.

ParameterTypeDefaultDescription
urlstringRequiredAbsolute HTTP or HTTPS URL of the page to process.
timeoutnumber (integer)300Maximum seconds to wait for the scrape, from 1 to 330. The HTTP request allows 30 additional seconds.
waitForSelectorstringOmittedCSS selector or text to wait for on the page before returning the result, up to 500 characters.
geoCodestringOmittedTwo-letter country code to load the page from, sent in lowercase. Omit it to load the page from the United States.
maxAgenumber (integer)0Return a cached result of the same request when it is newer than the selected age, in milliseconds, up to 604800000 (7 days). A cached result costs the same tokens as the original scrape. 0 always scrapes fresh.
maxRetriesnumber (integer)OmittedMaximum number of retries, as a nonnegative integer. Omit this parameter for no limit.

Loading controls

scrapeHtml, scrapeMarkdown, and scrapeJson also accept these options. getScreenshot does not.

ParameterTypeDefaultDescription
browserRenderingbooleanOmittedWhether to load the page in a browser: true always does and false never does. Omit it to load the page without a browser first and switch to a browser automatically if the request is blocked.
warmStartbooleanfalseWhether to open the site's home page first to warm the session before loading the target URL.
blockResourcesbooleanfalseWhether to block images, fonts, and stylesheets while loading the page.

Values always sent

Each function adds its fixed request fields automatically; they are not options. scrapeHtml, scrapeMarkdown, getScreenshot, and scrapeJson also always send saveResult=true, so page results are saved to your dashboard. tokenCap is never sent.

FunctionFixed fields
scrapeHtmlhtml=true and markdown=false, plus browserRendering=true when a screenshot is set
scrapeMarkdownmarkdown=true, html=false, and screenshot=false
getScreenshotbrowserRendering=true, html=false, and markdown=false
scrapeBrandaction=brand-scraping and bundle=none
scrapeJsonagent=general
webSearchaction=websearch

Functions

status

Return the raw account status API response without summarizing, redacting body fields, or adding calculated fields. It takes no service parameters, and its HTTP deadline is fixed at 600 seconds.

import { status } from "@mrscraper/sdk";

const result = await status();
console.log(result.data.data.tokenUsage, result.data.data.tokenLimit);

The API body contains message and data. Account details remain nested in data, including subscriptionItem and scraperAllowance, so the response exposes them at result.data.data.

{
  "status_code": 200,
  "data": {
    "message": "Example response",
    "data": {
      "id": "ACCOUNT_ID",
      "tokenLimit": 100000,
      "tokenUsage": 2500,
      "stripeStatus": "active",
      "user": {
        "name": "Example user",
        "email": "user@example.com",
        "isVerified": true
      },
      "subscriptionItem": {
        "name": "Example plan",
        "tokenLimit": 100000
      },
      "scraperAllowance": {
        "remaining": 97500,
        "plans": [{ "remaining": 97500 }]
      }
    }
  },
  "headers": {
    "content-type": "application/json; charset=utf-8"
  }
}

scrapeHtml

Retrieve the raw HTML of a page. Browser rendering is optional.

Accepts page controls, loading controls, and:

ParameterTypeDefaultDescription
screenshotfalse or stringfalseScreenshot to capture with the HTML: false for none, full for the entire page, top for the first viewport, or a WIDTHxHEIGHT viewport from 100 to 3840 pixels with an optional -ZOOM percent from 25 to 300, such as 1280x800 or 1920x1080-75. Setting a screenshot also sends browserRendering=true.
import { scrapeHtml } from "@mrscraper/sdk";

const result = await scrapeHtml("https://example.com", {
  browserRendering: true,
  waitForSelector: "body",
});
console.log(result.data);

The response body is HTML text. With a screenshot, data is an object containing html and a base64 screenshot:

{
  "status_code": 200,
  "data": {
    "html": "<html>...</html>",
    "screenshot": "BASE64_IMAGE_DATA"
  },
  "headers": {
    "content-type": "application/json; charset=utf-8"
  }
}

scrapeMarkdown

Retrieve a page as clean Markdown. Browser rendering is optional.

Accepts page controls and loading controls.

import { scrapeMarkdown } from "@mrscraper/sdk";

const result = await scrapeMarkdown("https://example.com", {
  maxAge: 86400000,
  warmStart: true,
});
console.log(result.data);

The response body is Markdown text.

getScreenshot

Capture a base64 PNG screenshot of the full page, the first viewport, or a custom viewport. Browser rendering is always enabled.

Accepts page controls and:

ParameterTypeDefaultDescription
screenshotstring"full"Screenshot area to capture: full for the entire scroll height, top for the first viewport, or a WIDTHxHEIGHT viewport from 100 to 3840 pixels with an optional -ZOOM percent from 25 to 300, such as 1280x800 or 1920x1080-75.
import { writeFile } from "node:fs/promises";
import { getScreenshot } from "@mrscraper/sdk";

const result = await getScreenshot("https://example.com", {
  screenshot: "1280x800",
  timeout: 120,
});
if (typeof result.data === "object" && typeof result.data?.screenshot === "string") {
  await writeFile("page.png", Buffer.from(result.data.screenshot, "base64"));
}

The response body is JSON containing a base64 PNG screenshot and the page HTML, which the API includes even though html=false is sent.

{
  "status_code": 200,
  "data": {
    "html": "<html>...</html>",
    "screenshot": "BASE64_PNG_DATA"
  },
  "headers": {
    "content-type": "application/json; charset=utf-8"
  }
}

scrapeBrand

Extract a website's colors, typography, logos, and social links as JSON. It takes only the URL; page controls are not accepted. The HTTP deadline is fixed at 120 seconds.

import { scrapeBrand } from "@mrscraper/sdk";

const result = await scrapeBrand("https://example.com");
console.log(result.data.data.brand);

The API body contains message and a data object with job_id, status, url, final_url, brand, and error. Brand details are at result.data.data.brand.

{
  "status_code": 200,
  "data": {
    "data": {
      "job_id": "JOB_ID",
      "status": "succeeded",
      "url": "https://example.com",
      "final_url": "https://example.com",
      "brand": {
        "name": "Example brand",
        "colors": { "background": "#ffffff", "text": "#222222" },
        "typography": { "body": { "font_family": "Example font" } }
      },
      "error": null,
      "bundle_url": null
    },
    "message": "Example response"
  },
  "headers": {
    "content-type": "application/json"
  }
}

scrapeJson

Extract structured JSON from a page using a natural-language prompt. Append Json Schema: and a JSON schema to shape the output.

Accepts page controls, loading controls, and:

ParameterTypeDefaultDescription
promptstring"Extract all data as complete as possible."Instructions describing the data to extract. Append Json Schema: and a JSON schema to shape the output.
htmlbooleantrueWhether to include the page HTML in the response.
screenshotbooleanfalseWhether to include a base64 screenshot in the response.

The request uses GET. If the encoded URL exceeds 8,000 characters, it switches to POST with url, prompt, and agent in the body; page controls remain in the query.

import { scrapeJson } from "@mrscraper/sdk";

const result = await scrapeJson("https://example.com", {
  prompt:
    'Extract the first 2 items with title and price. Json Schema: {"type":"array","items":{"type":"object","properties":{"title":{"type":"string"},"price":{"type":"string"}},"required":["title","price"]}}',
  browserRendering: true,
});
console.log(result.data.data);

Extraction results are in the API body's data field and follow the requested schema. Response metadata includes thread_id, token_usage, status, error, runtime, and cookies. html contains the page HTML unless disabled; markdown and screenshot can be empty strings.

{
  "status_code": 200,
  "data": {
    "success": true,
    "data": [{ "title": "Example item", "price": "10.00" }],
    "thread_id": "THREAD_ID",
    "token_usage": 1,
    "html": "<html>...</html>",
    "markdown": "",
    "screenshot": "",
    "status": "Results ready",
    "error": "",
    "runtime": 1.23,
    "cookies": []
  },
  "headers": {
    "content-type": "application/json"
  }
}

webSearch

Search the web and return ranked results with titles, URLs, descriptions, and sources. The first argument is the search query. The HTTP deadline is fixed at 120 seconds.

ParameterTypeDefaultDescription
querystringRequiredSearch query text, trimmed before sending, containing 1 to 1000 characters.
countrystringOmittedTwo-letter country code to search from, sent in lowercase. Omit it to search from the United States.
numResultsnumber (integer)10Number of search results to request, as an integer from 10 to 100. Fewer results may be returned.
import { webSearch } from "@mrscraper/sdk";

const result = await webSearch("site:example.com documentation", {
  country: "id",
  numResults: 20,
});
for (const item of result.data.data) {
  console.log(item.rank, item.title, item.url);
}

The API body contains success, message, a data array, and tokenUsage. Each result includes rank, title, url, description, and source.

{
  "status_code": 200,
  "data": {
    "success": true,
    "message": "Example response",
    "data": [
      {
        "rank": 1,
        "title": "Example result",
        "url": "https://example.com",
        "description": "Example result description.",
        "source": "example.com"
      }
    ],
    "tokenUsage": 1
  },
  "headers": {
    "content-type": "application/json; charset=utf-8"
  }
}

TypeScript Types

The package ships its own type definitions:

import type {
  StatusOptions,
  PageOptions,
  LoadingOptions,
  HtmlOptions,
  MarkdownOptions,
  ScreenshotOptions,
  JsonOptions,
  BrandOptions,
  PageData,
  ScreenshotArea,
  ScreenshotCapture,
  WebSearchOptions,
  WebSearchResponse,
  WebSearchResult,
  MrScraperResponse,
} from "@mrscraper/sdk";

Pass a generic type when you know the shape of the response body:

import { scrapeJson } from "@mrscraper/sdk";

const result = await scrapeJson<{ data: { title: string } }>(
  "https://example.com",
  { prompt: "Extract the page title" },
);
console.log(result.data.data.title);

Error Handling

Authentication, HTTP, network, and timeout failures throw MrScraperError. Invalid arguments throw a TypeError or RangeError before any request is sent.

PropertyTypeDescription
messagestringHuman-readable error message
statusnumber | undefinedHTTP status code (401, 429, 500, etc.), or undefined for network errors
namestringAlways "MrScraperError"
import { scrapeHtml, MrScraperError } from "@mrscraper/sdk";

try {
  await scrapeHtml("https://example.com");
} catch (error) {
  if (error instanceof MrScraperError) {
    console.error(error.status ?? "network error", error.message);
  } else {
    throw error;
  }
}

Troubleshooting

  • If authentication fails, check MRSCRAPER_API_TOKEN and MRSCRAPER_API_KEY.
  • Use camelCase option names, not snake_case.
  • Page timeouts are integers from 1 to 330. status, scrapeBrand, and webSearch have fixed deadlines and do not accept a timeout.

Migrating from Earlier Versions

From Version 6

Version 7.0.0 keeps the seven functions and changes their options.

Version 6Version 7
super, proxyCountry, proxy, waitUntil, returnCookieRemoved
saveResultRemoved; page results are always saved to your dashboard
scrapeMarkdown(url, { html: true })scrapeMarkdown(url) for Markdown, or scrapeHtml(url) for HTML
getScreenshot(url, { html, markdown, blockResources, browserRendering })getScreenshot(url, { screenshot }); the API still returns the page HTML
screenshot: "full" or "top"Also accepts a WIDTHxHEIGHT[-ZOOM] viewport, such as "1280x800"
WaitUntil typeScreenshotArea and ScreenshotCapture types
  • maxAge is new on every page function. scrapeHtml accepts screenshot, and scrapeJson accepts warmStart, blockResources, and waitForSelector.
  • browserRendering is omitted unless set, so the API switches to a browser only when a request is blocked. getScreenshot no longer accepts it and always sends browserRendering=true.
  • geoCode and the webSearch country option are omitted unless set, so the API uses the United States. The scrapeJson html option now defaults to true.
  • Page timeouts accept up to 330 seconds.

Earlier versions

  • Version 5 to 6: scraper_api was replaced by scrapeHtml, scrapeMarkdown, and getScreenshot, account by status, and web_search by webSearch, and all options became camelCase. status returns the raw API body.
  • Version 4 to 5: the format-specific 4.x functions (scraper_html, scraper_markdown, get_screenshot, scraper_json, scraper_multiple_page, scraper_sitemap, scrape_brand, get_brand) were merged into scraper_api. Upgrade directly to the 7.x functions above.
  • Version 3: web_search moved to action: "websearch" with country and num_results. Version 3.1.0 added account.
  • Version 2: fetch_content was renamed scraper_api in version 3.
  • Version 1: fetchHtml and the AI scraper, manual scraper, and results functions were removed in version 2. 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 outputscrapeHtml
Scrape a URL with Markdown outputscrapeMarkdown
Scrape a URL with a screenshotgetScreenshot
Scrape a URL with JSON extractionscrapeJson
Scrape a URL with brandingscrapeBrand
SearchwebSearch

On this page