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.
| Function | Description |
|---|---|
status | Return the raw account status API response without summarizing, redacting body fields, or adding calculated fields. |
scrapeHtml | Retrieve the raw HTML of a page. Browser rendering is optional. |
scrapeMarkdown | Retrieve a page as clean Markdown. Browser rendering is optional. |
getScreenshot | Capture a base64 PNG screenshot of the full page, the first viewport, or a custom viewport. Browser rendering is always enabled. |
scrapeBrand | Extract a website's colors, typography, logos, and social links as JSON. |
scrapeJson | Extract structured JSON from a page using a natural-language prompt. Append Json Schema: and a JSON schema to shape the output. |
webSearch | Search the web and return ranked results with titles, URLs, descriptions, and sources. |
Requirements
- Node.js 18 or later
- ES modules: save examples as
.mjsfiles or set"type": "module"in yourpackage.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/sdkAuthentication
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:
| Property | Type | Description |
|---|---|---|
status_code | number | HTTP status code of the API response |
data | T (default unknown) | The API response body. JSON becomes JavaScript values, text stays a string, and binary bodies become a Node.js Buffer |
headers | Record<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.
| Parameter | Type | Default | Description |
|---|---|---|---|
url | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
timeout | number (integer) | 300 | Maximum seconds to wait for the scrape, from 1 to 330. The HTTP request allows 30 additional seconds. |
waitForSelector | string | Omitted | CSS selector or text to wait for on the page before returning the result, up to 500 characters. |
geoCode | string | Omitted | Two-letter country code to load the page from, sent in lowercase. Omit it to load the page from the United States. |
maxAge | number (integer) | 0 | Return 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. |
maxRetries | number (integer) | Omitted | Maximum 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
browserRendering | boolean | Omitted | Whether 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. |
warmStart | boolean | false | Whether to open the site's home page first to warm the session before loading the target URL. |
blockResources | boolean | false | Whether 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.
| Function | Fixed fields |
|---|---|
scrapeHtml | html=true and markdown=false, plus browserRendering=true when a screenshot is set |
scrapeMarkdown | markdown=true, html=false, and screenshot=false |
getScreenshot | browserRendering=true, html=false, and markdown=false |
scrapeBrand | action=brand-scraping and bundle=none |
scrapeJson | agent=general |
webSearch | action=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:
| Parameter | Type | Default | Description |
|---|---|---|---|
screenshot | false or string | false | Screenshot 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:
| Parameter | Type | Default | Description |
|---|---|---|---|
screenshot | string | "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:
| Parameter | Type | Default | Description |
|---|---|---|---|
prompt | string | "Extract all data as complete as possible." | Instructions describing the data to extract. Append Json Schema: and a JSON schema to shape the output. |
html | boolean | true | Whether to include the page HTML in the response. |
screenshot | boolean | false | Whether 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
query | string | Required | Search query text, trimmed before sending, containing 1 to 1000 characters. |
country | string | Omitted | Two-letter country code to search from, sent in lowercase. Omit it to search from the United States. |
numResults | number (integer) | 10 | Number 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.
| 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" |
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_TOKENandMRSCRAPER_API_KEY. - Use camelCase option names, not snake_case.
- Page timeouts are integers from 1 to 330.
status,scrapeBrand, andwebSearchhave 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 6 | Version 7 |
|---|---|
super, proxyCountry, proxy, waitUntil, returnCookie | Removed |
saveResult | Removed; 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 type | ScreenshotArea and ScreenshotCapture types |
maxAgeis new on every page function.scrapeHtmlacceptsscreenshot, andscrapeJsonacceptswarmStart,blockResources, andwaitForSelector.browserRenderingis omitted unless set, so the API switches to a browser only when a request is blocked.getScreenshotno longer accepts it and always sendsbrowserRendering=true.geoCodeand thewebSearchcountryoption are omitted unless set, so the API uses the United States. ThescrapeJsonhtmloption now defaults totrue.- Page timeouts accept up to 330 seconds.
Earlier versions
- Version 5 to 6:
scraper_apiwas replaced byscrapeHtml,scrapeMarkdown, andgetScreenshot,accountbystatus, andweb_searchbywebSearch, and all options became camelCase.statusreturns 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 intoscraper_api. Upgrade directly to the 7.x functions above. - Version 3:
web_searchmoved toaction: "websearch"withcountryandnum_results. Version 3.1.0 addedaccount. - Version 2:
fetch_contentwas renamedscraper_apiin version 3. - Version 1:
fetchHtmland 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 Method | MrScraper Equivalent |
|---|---|
| Scrape a URL with HTML output | scrapeHtml |
| Scrape a URL with Markdown output | scrapeMarkdown |
| Scrape a URL with a screenshot | getScreenshot |
| Scrape a URL with JSON extraction | scrapeJson |
| Scrape a URL with branding | scrapeBrand |
| Search | webSearch |
Python SDK
Install and use mrscraper-sdk, the async Python client for the MrScraper API, to retrieve pages as HTML, Markdown, or screenshots, extract brand details and structured JSON, search the web, and check account status.
LangChain SDK
Use MrScraper as LangChain tools via the langchain-mrscraper package to retrieve pages as HTML, Markdown, or screenshots, extract brand details and structured JSON, search the web, and check account status from agents.