npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mrscraper/sdk

v1.1.3

Published

Official Node.js SDK for the MrScraper API – fetch pages, Google SERP, run AI scrapers, rerun manual scrapers, and retrieve results.

Readme

@mrscraper/sdk

Official Node.js SDK for the MrScraper API.

Scrape any data from any websites. Unblock pages, create and scale AI scrapers, manual scrapers, and retrieve results synchronously and asynchronously. It is stealth, reliable, and scalable. Every action is mirrored on our platform https://app.mrscraper.com

npm version License: MIT

Table of Contents


Installation

npm install @mrscraper/sdk

Requirements

  • Node.js >= 18
  • Your project must use ES Modules. Add "type": "module" to your package.json:

Authentication

Get your API token from your MrScraper dashboard and set it as an environment variable:

export MRSCRAPER_API_TOKEN=your_token_here

Every function also accepts an optional token parameter to override the environment variable on a per-call basis.


Quick Start

import { fetchHtml, createAiScraper, getResultById, MrScraperError } from "@mrscraper/sdk";

try {
  // 1. Fetch raw HTML of a page
  const html = await fetchHtml({ url: "https://example.com" });
  console.log(html);

  // 2. Create an AI scraper and get its result
  const scraper = await createAiScraper({
    url: "https://example.com/products",
    message: "Extract all product names and prices",
    agent: "listing",
  });
  console.log(scraper);
} catch (err) {
  if (err instanceof MrScraperError) {
    console.error(`[${err.status ?? "network"}] ${err.message}`);
  } else {
    throw err;
  }
}

Error Handling

All functions throw a MrScraperError on failure — whether the error comes from the API (4xx/5xx), a network issue, or a timeout. You never need to check a return value; just wrap calls in try/catch.

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

try {
  const html = await fetchHtml({ url: "https://example.com" });
} catch (err) {
  if (err instanceof MrScraperError) {
    console.error(err.message); // Human-readable error message
    console.error(err.status);  // HTTP status code, or undefined for network errors
  }
}

MrScraperError properties:

| Property | Type | Description | |----------|------|-------------| | message | string | Human-readable description of the error | | status | number \| undefined | HTTP status code (e.g. 401, 429, 500). undefined for network/timeout errors | | name | string | Always "MrScraperError" |


API Reference

fetchHtml

Fetches the raw HTML (or JSON) of any URL through MrScraper's Fetch endpoint.

const html = await fetchHtml({
  url: "https://example.com",         // required
  timeout: 120,                       // optional – seconds (1–600), default: 120
  geoCode: "US",                      // optional – 2-letter country code, default: "US"
  blockResources: false,              // optional – block images/CSS/fonts, default: false
  token: "your_token",                // optional – overrides MRSCRAPER_API_TOKEN
});

Options:

| Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | url | string | Yes | — | The URL to fetch | | timeout | number | No | 120 | Request timeout in seconds (1–600) | | geoCode | string | No | "US" | Two-letter ISO country code for geo-targeting | | blockResources | boolean | No | false | Block images, fonts, and CSS to speed up the request | | token | string | No | — | Overrides the MRSCRAPER_API_TOKEN environment variable |

Returns: Promise<string> — the raw HTML (or JSON string) of the page.


createAiScraper

Creates a new AI scraper. Supports three agent types:

  • general — extracts structured data based on your natural-language message
  • listing — optimised for list/collection pages (products, jobs, articles, etc.)
  • map — crawls a site to discover and map all URLs
// General / listing agent
const scraper = await createAiScraper({
  url: "https://example.com/products",
  message: "Extract all product names and prices",
  agent: "listing",           // "general" | "listing" | "map", default: "general"
  proxyCountry: "US",         // optional
});

// Map agent
const scraper = await createAiScraper({
  url: "https://example.com",
  agent: "map",
  maxDepth: 2,                // optional – default: 2
  maxPages: 50,               // optional – default: 50
  limit: 1000,                // optional – default: 1000
  includePatterns: "/blog",   // optional
  excludePatterns: "/admin",  // optional
});

Options:

| Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | url | string | Yes | — | Starting URL to scrape | | message | string | No | "" | Natural-language instructions (general/listing agents) | | agent | "general" \| "listing" \| "map" | No | "general" | Agent type | | proxyCountry | string \| null | No | — | Two-letter proxy country code (general/listing) | | maxDepth | number | No | 2 | Max crawl depth, 0–5 (map agent) | | maxPages | number | No | 50 | Max pages to crawl, 1–1000 (map agent) | | limit | number | No | 1000 | Max results to return, 1–100000 (map agent) | | includePatterns | string | No | "" | URL patterns to include (map agent) | | excludePatterns | string | No | "" | URL patterns to exclude (map agent) | | token | string | No | — | Overrides the MRSCRAPER_API_TOKEN environment variable |

Returns: Promise<unknown> — the API response object.


rerunAiScraper

Reruns an existing AI scraper on a new URL.

const result = await rerunAiScraper({
  scraperId: "your-scraper-id",         // required
  url: "https://example.com/new-page",  // required
  maxDepth: 2,                          // optional
  maxPages: 50,                         // optional
  limit: 1000,                          // optional
  includePatterns: "",                  // optional
  excludePatterns: "",                  // optional
});

Options:

| Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | scraperId | string | Yes | — | ID of the AI scraper to rerun | | url | string | Yes | — | New URL to scrape | | maxDepth | number | No | 2 | Max crawl depth (0–5) | | maxPages | number | No | 50 | Max pages (1–1000) | | limit | number | No | 1000 | Max results (1–100000) | | includePatterns | string | No | "" | URL patterns to include | | excludePatterns | string | No | "" | URL patterns to exclude | | token | string | No | — | Overrides the MRSCRAPER_API_TOKEN environment variable |

Returns: Promise<unknown> — the API response object.


bulkRerunAiScraper

Reruns an AI scraper on multiple URLs at once.

const result = await bulkRerunAiScraper({
  scraperId: "your-scraper-id",
  urls: [
    "https://example.com/page1",
    "https://example.com/page2",
  ],
});

Options:

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | scraperId | string | Yes | ID of the AI scraper to rerun | | urls | string[] | Yes | List of URLs to scrape | | token | string | No | Overrides the MRSCRAPER_API_TOKEN environment variable |

Returns: Promise<unknown> — the API response object.


rerunManualScraper

Reruns a manual (dashboard-configured) scraper on a URL.

const result = await rerunManualScraper({
  scraperId: "your-scraper-id",
  url: "https://example.com/target",
});

Options:

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | scraperId | string | Yes | ID of the manual scraper to rerun | | url | string | Yes | URL to scrape | | token | string | No | Overrides the MRSCRAPER_API_TOKEN environment variable |

Returns: Promise<unknown> — the API response object.


bulkRerunManualScraper

Reruns a manual scraper on multiple URLs at once.

const result = await bulkRerunManualScraper({
  scraperId: "your-scraper-id",
  urls: [
    "https://example.com/a",
    "https://example.com/b",
  ],
});

Options:

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | scraperId | string | Yes | ID of the manual scraper to rerun | | urls | string[] | Yes | List of URLs to scrape | | token | string | No | Overrides the MRSCRAPER_API_TOKEN environment variable |

Returns: Promise<unknown> — the API response object.


getAllResults

Lists scraping results with sorting, pagination, search, and date range filters. All options are optional.

const results = await getAllResults({
  sortField: "updatedAt",                   // default
  sortOrder: "DESC",                        // default
  pageSize: 10,                             // default
  page: 1,                                  // default
  search: "example.com",                    // optional
  dateRangeColumn: "createdAt",             // optional
  startAt: "2024-01-01T00:00:00Z",          // optional – ISO 8601
  endAt: "2024-12-31T23:59:59Z",            // optional – ISO 8601
});

Options:

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | sortField | SortField | "updatedAt" | Field to sort by | | sortOrder | "ASC" \| "DESC" | "DESC" | Sort direction | | pageSize | number | 10 | Results per page (1–500) | | page | number | 1 | Page number (1-based) | | search | string | — | Full-text search query | | dateRangeColumn | string | — | Column to filter by date range | | startAt | string | — | Start of date range (ISO 8601) | | endAt | string | — | End of date range (ISO 8601) | | token | string | — | Overrides the MRSCRAPER_API_TOKEN environment variable |

SortField values: "createdAt" "updatedAt" "id" "type" "url" "status" "error" "tokenUsage" "runtime"

Returns: Promise<unknown> — paginated list of results.


getResultById

Fetches a single scraping result by its ID.

const result = await getResultById({ resultId: "your-result-id" });
console.log(result);

Options:

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | resultId | string | Yes | ID of the result to fetch | | token | string | No | Overrides the MRSCRAPER_API_TOKEN environment variable |

Returns: Promise<unknown> — the result object.


googleSerp

Calls the synchronous Google SERP endpoint on the sync scraper API. Authenticates with a Bearer token (same token as MRSCRAPER_API_TOKEN).

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

const data = await googleSerp({
  url: "https://www.google.com/search?q=iphone+17", // required – full Google SERP URL
  raw: true,                                         // optional – default: false
  timeoutMs: 300_000,                                // optional – ms, default: 300000 (5 min)
  token: "your_token",                               // optional – overrides MRSCRAPER_API_TOKEN
});

Options:

| Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | url | string | Yes | — | Full Google search URL to scrape | | raw | boolean | No | false | When true, returns a raw payload (for example HTML) from the API | | timeoutMs | number | No | 300000 | Overall request timeout in milliseconds | | token | string | No | — | Overrides the MRSCRAPER_API_TOKEN environment variable |

Returns: Promise<unknown> — the API response (shape depends on raw and server version).


Trying the SDK locally

From a clone of this repository, build and run the Google SERP smoke script (requires MRSCRAPER_API_TOKEN):

export MRSCRAPER_API_TOKEN=your_token_here
npm install
npm run test:serp

The script prints a truncated response so long HTML does not flood the terminal.


TypeScript

All option interfaces and shared types are exported for use in your own code:

import type {
  FetchHtmlOptions,
  CreateAiScraperOptions,
  RerunAiScraperOptions,
  BulkRerunAiScraperOptions,
  RerunManualScraperOptions,
  BulkRerunManualScraperOptions,
  GetAllResultsOptions,
  GetResultByIdOptions,
  GoogleSerpOptions,
  ScraperAgent,
  SortField,
  SortOrder,
} from "@mrscraper/sdk";

Compliance & Legal Risk

WARNING Scraping login-protected pages carries serious legal and compliance risks. Many websites explicitly prohibit automated access in their Terms of Service, and bypassing authentication to scrape content may expose you to legal action including lawsuits, account termination, and financial penalties. By proceeding on scraping login-protected pages, you confirm that you have read and understood the target website's Terms of Service, and you fully accept all legal, financial, and ethical responsibility for your actions.


License

MIT — see LICENSE