@mrscraper/sdk 4.0.1 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,307 +1,606 @@
1
- # @mrscraper/sdk
1
+ # MrScraper Node SDK
2
2
 
3
- ![](./mrscraper.jpeg)
3
+ ![MrScraper](./mrscraper.jpeg)
4
4
 
5
- Node.js SDK for [MrScraper](https://mrscraper.com) HTML, Markdown, screenshots, structured extraction, sitemap discovery, brand scraping, Web Search, and account status. Requires Node.js 18 or newer and ES modules.
5
+ An async JavaScript and TypeScript SDK for the seven MrScraper services.
6
6
 
7
- ## Install and authenticate
7
+ ## Overview
8
+
9
+ Seven services share the same descriptions, parameter meanings, and defaults across the CLI, SDKs, and integrations. Names, types, authentication, and code examples follow each surface's conventions. See the [API Reference](https://docs.mrscraper.com/docs/api/overview).
10
+
11
+ | Service | Public name | Description |
12
+ | ----------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------- |
13
+ | [Status](#status) | `status` | Return the raw account status API response without summarizing, redacting body fields, or adding calculated fields. |
14
+ | [Scrape HTML](#scrape-html) | `scrapeHtml` | Retrieve the raw HTML of a page. Browser rendering is optional. |
15
+ | [Scrape Markdown](#scrape-markdown) | `scrapeMarkdown` | Retrieve a page as Markdown. Including HTML also enables browser rendering and returns both outputs as JSON. |
16
+ | [Get screenshot](#get-screenshot) | `getScreenshot` | Capture a base64 screenshot of the full page or top viewport. Browser rendering is always enabled. |
17
+ | [Scrape brand](#scrape-brand) | `scrapeBrand` | Extract a website's colors, typography, logos, and social links as JSON. |
18
+ | [Scrape JSON](#scrape-json) | `scrapeJson` | Extract structured JSON from a page using a natural-language prompt. Append Json Schema: and a JSON schema to shape the output. |
19
+ | [Web search](#web-search) | `webSearch` | Search the web and return ranked results with titles, URLs, descriptions, and sources. |
20
+
21
+ ## Installation
22
+
23
+ Requires Node.js 18 or newer. Examples use ES modules; save executable examples as `.mjs` files or set `"type": "module"` in your package.
8
24
 
9
25
  ```bash
10
26
  npm install @mrscraper/sdk
27
+ ```
28
+
29
+ ## Authentication
30
+
31
+ Obtain an API key from [the MrScraper app](https://app.mrscraper.com/api-tokens). API key used to authenticate the request.
32
+
33
+ ```bash
11
34
  export MRSCRAPER_API_TOKEN="YOUR_TOKEN"
12
35
  ```
13
36
 
14
- The SDK reads `MRSCRAPER_API_TOKEN` automatically. You can instead pass `token` in any call's options object. All functions are async and return `{ status_code, data, headers }`. JSON responses are parsed, HTML and other text remain strings, and images and ZIP files are returned as Node.js `Buffer` values in `data`.
37
+ Each function accepts an optional `token: string` in its options. Precedence is a nonempty explicit token, `MRSCRAPER_API_TOKEN`, then `MRSCRAPER_API_KEY`. Credentials are sent in headers, never in the request URL.
15
38
 
16
- ## Service functions
39
+ ## Quickstart
17
40
 
18
- These functions match the Python SDK's format-specific services. Each function selects its own output and agent; public options do not include `html`, `markdown`, or `screenshot` flags.
41
+ ```js
42
+ import { scrapeHtml } from "@mrscraper/sdk";
19
43
 
20
- | Function | Purpose and parameters |
21
- |----------|----------------------|
22
- | `scraper_html(url, options)` | Retrieve HTML from `url` |
23
- | `scraper_markdown(url, options)` | Retrieve Markdown from `url` |
24
- | `get_screenshot(url, options)` | Capture a screenshot; `full_page=true`, `wait_until="domcontentloaded"`, `timeout=300` |
25
- | `scraper_json(url, options)` | Extract structured data using `prompt` |
26
- | `scraper_multiple_page(url, options)` | Extract listing entries using `prompt`; `max_pages=3` |
27
- | `scraper_sitemap(url, options)` | Discover site URLs; `max_depth=2`, `max_pages=3`, `limit=1000` |
28
- | `scrape_brand(url, options)` | Start a brand scraping job; `bundle="clean"` |
29
- | `get_brand(job_id, options)` | Read a job by `job_id`; optional `output` downloads a file |
30
- | `web_search(url, options)` | Retrieve real-time web search results |
31
- | `account(options)` | Read account identity, subscription, quota, and rate limits |
44
+ const result = await scrapeHtml("https://example.com", {
45
+ browserRendering: true,
46
+ warmStart: true,
47
+ waitForSelector: "body",
48
+ timeout: 120,
49
+ maxRetries: 0,
50
+ });
51
+ console.log(result.data);
52
+ ```
32
53
 
33
- ### Migrating from v3 to v4
54
+ Examples use `example.com` as the sample target. Replace it for your use case. Live scraping and search calls consume account quota.
34
55
 
35
- Version 4 removes the public `scraper_api` function and `ScraperApiOptions` type. Replace calls with the appropriate service:
56
+ Response examples show selected keys and types observed in live API responses. Values are placeholders; page content, base64 images, and arrays are abbreviated. Actual responses may contain additional fields.
36
57
 
37
- ```typescript
38
- import { scraper_html, scraper_markdown, get_screenshot } from "@mrscraper/sdk";
58
+ ## Shared parameters
39
59
 
40
- const url = "https://example.com";
41
- // Previously: scraper_api(url, { html: true })
42
- const html = await scraper_html(url);
43
- // Previously: scraper_api(url, { html: false, markdown: true })
44
- const markdown = await scraper_markdown(url);
45
- // Previously: scraper_api(url, { screenshot: true })
46
- const screenshot = await get_screenshot(url);
47
- ```
60
+ ### Page controls
48
61
 
49
- Import these functions from `@mrscraper/sdk`. Use `ScraperOptions` for shared page controls and the service option types below for specialized controls. To retrieve more than one format, call its service separately. Screenshots default to full-page capture; set `full_page: false` for a viewport screenshot. Binary data is preserved as a `Buffer`.
62
+ HTML, Markdown, screenshots, and JSON extraction share `url`, `timeout`, `geoCode`, `proxyCountry`, `super`, `waitUntil`, `proxy`, `maxRetries`, and `saveResult` (using the naming style shown below). Page defaults are 300 seconds, US geolocation/proxy country, real-device routing off, and dashboard saving off. Omitted retry limits mean no limit. Exact types, defaults, and standard descriptions appear in each service table.
50
63
 
51
- For older versions, `fetch_content` maps to `scraper_html`. Use the current function names listed above when upgrading. The response wrapper remains `{ status_code, data, headers }`.
64
+ ### Loading controls
52
65
 
53
- ## HTML and Markdown
66
+ HTML, Markdown, and screenshots additionally accept `blockResources`, `waitForSelector`, and `returnCookie`. JSON extraction does not accept these controls. Browser rendering is optional for HTML, Markdown, and JSON; screenshots always enable it. Markdown with HTML also enables browser rendering.
54
67
 
55
- ```typescript
56
- import { scraper_html, scraper_markdown } from "@mrscraper/sdk";
68
+ ## Service reference
57
69
 
58
- const html = await scraper_html("https://example.com", { super: true });
59
- const markdown = await scraper_markdown("https://example.com", { home_page: true });
60
- console.log(html.data, markdown.data);
61
- ```
70
+ ### Status
62
71
 
63
- Use `scraper_html` or `scraper_markdown` for the desired page format. Both accept the shared scraping options below.
72
+ #### Description
64
73
 
65
- ### Shared scraping options
74
+ Return the raw account status API response without summarizing, redacting body fields, or adding calculated fields.
66
75
 
67
- | Option | Default | Description |
68
- |--------|---------|-------------|
69
- | `token` | Environment variable | API token override |
70
- | `timeout` | `120` (`300` for screenshots) | Page timeout in seconds, from 1 to 300; HTTP timeout is 30 seconds longer |
71
- | `geo_code`, `proxy_country` | `"US"`, unset | Geolocation and optional proxy country |
72
- | `browser_rendering` | unset | `true` to force a browser, `false` to disable it, unset for automatic fallback; unavailable for screenshots, which always enable rendering |
73
- | `super` | `false` | Enable real device routing |
74
- | `use_proxy`, `proxy` | `true`, unset | Allow a proxy or supply `username:password@host:port` |
75
- | `home_page` | `false` | Visit the site's root before the target page |
76
- | `wait_for_selector` | unset | Wait for a CSS selector |
77
- | `wait_until` | unset (`"domcontentloaded"` for screenshots) | Browser navigation wait condition; `null` omits it |
78
- | `block_resources`, `bypass_proxy` | `false`, `false` | Block resources or enable proxy bypass behavior |
79
- | `cookie_jar`, `headers` | unset | Cookie configuration and target request headers; `headers` accepts an object or JSON string |
80
- | `max_retries`, `token_cap` | `3`, unset | Nonnegative integer retry count and optional token budget |
81
- | `stream` | unset | Request a streamed response, buffered into the normal return value |
82
- | `discard_token_secret` | `""` | Value for the `x-discard-token-secret` API header |
76
+ #### Parameters
83
77
 
84
- Unset options use the service defaults. Explicit `false`, `0`, and empty strings are preserved where supported.
78
+ This service takes no service parameters. Authentication is configured separately.
85
79
 
86
- ## Screenshots
80
+ The HTTP deadline is fixed at 600 seconds. It is not a service parameter.
87
81
 
88
- ```typescript
89
- import { writeFile } from "node:fs/promises";
90
- import { get_screenshot } from "@mrscraper/sdk";
82
+ #### Example
83
+
84
+ ```js
85
+ import { status } from "@mrscraper/sdk";
86
+
87
+ const result = await status();
88
+ console.log(result.data);
89
+ ```
90
+
91
+ #### Response
92
+
93
+ The API body contains message and data. Account details remain nested in data, including subscriptionItem and scraperAllowance. The response envelope therefore exposes account details at data.data. Sensitive response headers are removed.
94
+
95
+ **Success response**
96
+
97
+ ```json
98
+ {
99
+ "status_code": 200,
100
+ "data": {
101
+ "message": "Example response",
102
+ "data": {
103
+ "id": "ACCOUNT_ID",
104
+ "tokenLimit": 100000,
105
+ "tokenUsage": 2500,
106
+ "stripeStatus": "active",
107
+ "user": {
108
+ "name": "Example user",
109
+ "email": "user@example.com",
110
+ "isVerified": true
111
+ },
112
+ "subscriptionItem": {
113
+ "name": "Example plan",
114
+ "tokenLimit": 100000
115
+ },
116
+ "scraperAllowance": {
117
+ "remaining": 97500,
118
+ "plans": [
119
+ {
120
+ "remaining": 97500
121
+ }
122
+ ]
123
+ }
124
+ }
125
+ },
126
+ "headers": {
127
+ "content-type": "application/json; charset=utf-8"
128
+ }
129
+ }
130
+ ```
91
131
 
92
- const result = await get_screenshot("https://example.com", {
93
- full_page: true, // Default; false captures the viewport.
94
- token_cap: 30,
132
+ ### Scrape HTML
133
+
134
+ #### Description
135
+
136
+ Retrieve the raw HTML of a page. Browser rendering is optional.
137
+
138
+ #### Parameters
139
+
140
+ | Parameter | HTTP field | Type | Default | Description |
141
+ | ------------------ | ------------------ | ------------------------------------------------------------------ | -------------------- | ----------------------------------------------------------------------------------------------- |
142
+ | `url` | `url` | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
143
+ | `timeout` | `timeout` | number (integer) | `300` | Page load timeout in seconds, from 1 to 300. The HTTP request allows 30 additional seconds. |
144
+ | `geoCode` | `geoCode` | string | `"us"` | Two-letter country code to load the page from, sent in lowercase. |
145
+ | `proxyCountry` | `proxyCountry` | string | `"us"` | Two-letter country code of the proxy server, sent in lowercase. |
146
+ | `super` | `super` | boolean | `false` | Whether to route the request through real devices. |
147
+ | `waitUntil` | `waitUntil` | string: `domcontentloaded`, `load`, `networkidle0`, `networkidle2` | `"domcontentloaded"` | Navigation completion event to wait for: domcontentloaded, load, networkidle0, or networkidle2. |
148
+ | `proxy` | `proxy` | string | Omitted | Custom proxy URL used to load the page. |
149
+ | `maxRetries` | `maxRetries` | number (integer) | Omitted | Maximum number of retries, as a nonnegative integer. Omit this parameter for no limit. |
150
+ | `saveResult` | `saveResult` | boolean | `false` | Whether to save the result to the dashboard Result tab. |
151
+ | `blockResources` | `blockResources` | boolean | `false` | Whether to block images, fonts, and stylesheets while loading the page. |
152
+ | `waitForSelector` | `waitForSelector` | string | Omitted | Wait for the page to contain the specified CSS selector before returning the result. |
153
+ | `returnCookie` | `returnCookie` | boolean | `false` | Whether to include browser session cookies in the response. |
154
+ | `browserRendering` | `browserRendering` | boolean | `false` | Whether to render the page in a browser before returning the result. |
155
+ | `warmStart` | `warmStart` | boolean | `false` | Whether to enable warm start for more reliable scraping, at the cost of additional latency. |
156
+
157
+ #### Example
158
+
159
+ ```js
160
+ import { scrapeHtml } from "@mrscraper/sdk";
161
+
162
+ const result = await scrapeHtml("https://example.com", {
163
+ browserRendering: true,
164
+ warmStart: true,
165
+ waitForSelector: "body",
166
+ timeout: 120,
167
+ maxRetries: 0,
95
168
  });
96
- if (Buffer.isBuffer(result.data)) await writeFile("page.png", result.data);
97
- else console.log(result.data); // The API may also return JSON metadata.
169
+ console.log(result.data);
98
170
  ```
99
171
 
100
- ## JSON and multiple-page extraction
172
+ #### Response
101
173
 
102
- ```typescript
103
- import { scraper_json, scraper_multiple_page } from "@mrscraper/sdk";
174
+ The default response body is HTML text. Additional controls can cause the API to return JSON; the returned structure is preserved.
104
175
 
105
- const page = await scraper_json("https://mrscraper.com/pricing", {
106
- prompt: "Extract all plan names and prices.",
107
- super: true,
108
- });
109
- const listings = await scraper_multiple_page("https://books.toscrape.com", {
110
- prompt: "Extract each book title and price.",
111
- max_pages: 3,
176
+ **Success response**
177
+
178
+ ```json
179
+ {
180
+ "status_code": 200,
181
+ "data": "<html><body>Example page content...</body></html>",
182
+ "headers": {
183
+ "content-type": "text/html; charset=utf-8"
184
+ }
185
+ }
186
+ ```
187
+
188
+ ### Scrape Markdown
189
+
190
+ #### Description
191
+
192
+ Retrieve a page as Markdown. Including HTML also enables browser rendering and returns both outputs as JSON.
193
+
194
+ #### Parameters
195
+
196
+ | Parameter | HTTP field | Type | Default | Description |
197
+ | ------------------ | ------------------ | ------------------------------------------------------------------ | -------------------- | ----------------------------------------------------------------------------------------------- |
198
+ | `url` | `url` | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
199
+ | `timeout` | `timeout` | number (integer) | `300` | Page load timeout in seconds, from 1 to 300. The HTTP request allows 30 additional seconds. |
200
+ | `geoCode` | `geoCode` | string | `"us"` | Two-letter country code to load the page from, sent in lowercase. |
201
+ | `proxyCountry` | `proxyCountry` | string | `"us"` | Two-letter country code of the proxy server, sent in lowercase. |
202
+ | `super` | `super` | boolean | `false` | Whether to route the request through real devices. |
203
+ | `waitUntil` | `waitUntil` | string: `domcontentloaded`, `load`, `networkidle0`, `networkidle2` | `"domcontentloaded"` | Navigation completion event to wait for: domcontentloaded, load, networkidle0, or networkidle2. |
204
+ | `proxy` | `proxy` | string | Omitted | Custom proxy URL used to load the page. |
205
+ | `maxRetries` | `maxRetries` | number (integer) | Omitted | Maximum number of retries, as a nonnegative integer. Omit this parameter for no limit. |
206
+ | `saveResult` | `saveResult` | boolean | `false` | Whether to save the result to the dashboard Result tab. |
207
+ | `blockResources` | `blockResources` | boolean | `false` | Whether to block images, fonts, and stylesheets while loading the page. |
208
+ | `waitForSelector` | `waitForSelector` | string | Omitted | Wait for the page to contain the specified CSS selector before returning the result. |
209
+ | `returnCookie` | `returnCookie` | boolean | `false` | Whether to include browser session cookies in the response. |
210
+ | `browserRendering` | `browserRendering` | boolean | `false` | Whether to render the page in a browser before returning the result. |
211
+ | `warmStart` | `warmStart` | boolean | `false` | Whether to enable warm start for more reliable scraping, at the cost of additional latency. |
212
+ | `html` | `html` | boolean | `false` | Whether to include the page HTML in the response. |
213
+
214
+ #### Example
215
+
216
+ ```js
217
+ import { scrapeMarkdown } from "@mrscraper/sdk";
218
+
219
+ const result = await scrapeMarkdown("https://example.com", {
220
+ html: true,
221
+ warmStart: true,
112
222
  });
113
- console.log(page.data, listings.data);
223
+ console.log(result.data);
114
224
  ```
115
225
 
116
- `ScraperJsonOptions.prompt` defaults to `"Extract all data as complete as possible."`. `ScraperMultiplePageOptions.prompt` defaults to `"Extract all entry data as complete as possible."`, and `max_pages` must be a positive integer. Set `prompt` to describe the data to extract and `max_pages` to limit pagination.
226
+ #### Response
227
+
228
+ The default response body is Markdown text. Enabling HTML returns JSON containing both HTML and Markdown.
117
229
 
118
- ## Sitemap discovery
230
+ **With html enabled**
119
231
 
120
- ```typescript
121
- import { scraper_sitemap } from "@mrscraper/sdk";
232
+ ```json
233
+ {
234
+ "status_code": 200,
235
+ "data": {
236
+ "html": "<html>...</html>",
237
+ "markdown": "# Example page\n\n..."
238
+ },
239
+ "headers": {
240
+ "content-type": "application/json"
241
+ }
242
+ }
243
+ ```
122
244
 
123
- const result = await scraper_sitemap("https://docs.mrscraper.com", {
124
- max_depth: 2,
125
- max_pages: 3,
126
- limit: 1000,
127
- include_patterns: String.raw`/products/.*`,
128
- exclude_patterns: String.raw`/blog/.*`,
245
+ **Default Markdown text**
246
+
247
+ ```json
248
+ {
249
+ "status_code": 200,
250
+ "data": "# Example page\n\nExample Markdown content...",
251
+ "headers": {
252
+ "content-type": "text/markdown; charset=utf-8"
253
+ }
254
+ }
255
+ ```
256
+
257
+ ### Get screenshot
258
+
259
+ #### Description
260
+
261
+ Capture a base64 screenshot of the full page or top viewport. Browser rendering is always enabled.
262
+
263
+ #### Parameters
264
+
265
+ | Parameter | HTTP field | Type | Default | Description |
266
+ | ----------------- | ----------------- | ------------------------------------------------------------------ | -------------------- | ----------------------------------------------------------------------------------------------- |
267
+ | `url` | `url` | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
268
+ | `timeout` | `timeout` | number (integer) | `300` | Page load timeout in seconds, from 1 to 300. The HTTP request allows 30 additional seconds. |
269
+ | `geoCode` | `geoCode` | string | `"us"` | Two-letter country code to load the page from, sent in lowercase. |
270
+ | `proxyCountry` | `proxyCountry` | string | `"us"` | Two-letter country code of the proxy server, sent in lowercase. |
271
+ | `super` | `super` | boolean | `false` | Whether to route the request through real devices. |
272
+ | `waitUntil` | `waitUntil` | string: `domcontentloaded`, `load`, `networkidle0`, `networkidle2` | `"domcontentloaded"` | Navigation completion event to wait for: domcontentloaded, load, networkidle0, or networkidle2. |
273
+ | `proxy` | `proxy` | string | Omitted | Custom proxy URL used to load the page. |
274
+ | `maxRetries` | `maxRetries` | number (integer) | Omitted | Maximum number of retries, as a nonnegative integer. Omit this parameter for no limit. |
275
+ | `saveResult` | `saveResult` | boolean | `false` | Whether to save the result to the dashboard Result tab. |
276
+ | `blockResources` | `blockResources` | boolean | `false` | Whether to block images, fonts, and stylesheets while loading the page. |
277
+ | `waitForSelector` | `waitForSelector` | string | Omitted | Wait for the page to contain the specified CSS selector before returning the result. |
278
+ | `returnCookie` | `returnCookie` | boolean | `false` | Whether to include browser session cookies in the response. |
279
+ | `screenshot` | `screenshot` | string: `full`, `top` | `"full"` | Screenshot area to capture: full for the entire page or top for the top viewport. |
280
+ | `html` | `html` | boolean | `true` | Whether to include the page HTML in the response. |
281
+ | `markdown` | `markdown` | boolean | `false` | Whether to include the page Markdown in the response. |
282
+
283
+ #### Example
284
+
285
+ ```js
286
+ import { getScreenshot } from "@mrscraper/sdk";
287
+
288
+ const result = await getScreenshot("https://example.com", {
289
+ screenshot: "top",
290
+ html: false,
291
+ markdown: true,
129
292
  });
130
293
  console.log(result.data);
131
294
  ```
132
295
 
133
- `ScraperSitemapOptions` supports `max_depth`, `max_pages`, `limit`, `include_patterns`, and `exclude_patterns`. Pattern strings are forwarded unchanged; unset or `null` patterns are omitted. `max_depth` must be a nonnegative integer; `max_pages` and `limit` must be positive integers.
296
+ #### Response
134
297
 
135
- ## Brand scraping and downloads
298
+ The response body contains a base64 screenshot and requested page outputs. The API can still include HTML when HTML output is disabled.
136
299
 
137
- ```typescript
138
- import { writeFile } from "node:fs/promises";
139
- import { scrape_brand, get_brand } from "@mrscraper/sdk";
300
+ **Success response**
301
+
302
+ ```json
303
+ {
304
+ "status_code": 200,
305
+ "data": {
306
+ "html": "<html>...</html>",
307
+ "screenshot": "BASE64_PNG_DATA",
308
+ "markdown": "# Example page\n\n..."
309
+ },
310
+ "headers": {
311
+ "content-type": "application/json; charset=utf-8"
312
+ }
313
+ }
314
+ ```
315
+
316
+ ### Scrape brand
317
+
318
+ #### Description
319
+
320
+ Extract a website's colors, typography, logos, and social links as JSON.
140
321
 
141
- const created = await scrape_brand("https://www.brooksrunning.com", { bundle: "clean" });
142
- console.log(created.data); // Read the job ID from the API response.
322
+ #### Parameters
143
323
 
144
- const jobId = "JOB_ID_FROM_RESPONSE";
145
- const job = await get_brand(jobId);
146
- console.log(job.data); // Check job status before downloading.
324
+ | Parameter | HTTP field | Type | Default | Description |
325
+ | --------- | ---------- | ------ | -------- | -------------------------------------------------- |
326
+ | `url` | `url` | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
147
327
 
148
- const download = await get_brand(jobId, { output: "bundle" });
149
- if (Buffer.isBuffer(download.data)) await writeFile("brand.zip", download.data);
328
+ The HTTP deadline is fixed at 120 seconds. It is not a service parameter.
329
+
330
+ The request uses `action=brand-scraping` and `bundle=none`; page controls are not accepted.
331
+
332
+ #### Example
333
+
334
+ ```js
335
+ import { scrapeBrand } from "@mrscraper/sdk";
336
+
337
+ const result = await scrapeBrand("https://example.com");
338
+ console.log(result.data);
339
+ ```
340
+
341
+ #### Response
342
+
343
+ The API body contains message and a data object with job_id, status, url, final_url, brand, and error. Brand details are available at data.data.brand in the response envelope.
344
+
345
+ **Success response**
346
+
347
+ ```json
348
+ {
349
+ "status_code": 200,
350
+ "data": {
351
+ "data": {
352
+ "job_id": "JOB_ID",
353
+ "status": "succeeded",
354
+ "url": "https://example.com",
355
+ "final_url": "https://example.com",
356
+ "brand": {
357
+ "name": "Example brand",
358
+ "colors": {
359
+ "background": "#ffffff",
360
+ "text": "#222222"
361
+ },
362
+ "typography": {
363
+ "body": {
364
+ "font_family": "Example font"
365
+ }
366
+ }
367
+ },
368
+ "error": null,
369
+ "bundle_url": null
370
+ },
371
+ "message": "Example response"
372
+ },
373
+ "headers": {
374
+ "content-type": "application/json"
375
+ }
376
+ }
150
377
  ```
151
378
 
152
- `ScrapeBrandOptions.bundle` accepts `"clean"` (default), `"full"`, or `"none"`. `GetBrandOptions` accepts `token`, `timeout` (default `600` seconds), and optional `output`: `"html"`, `"bundle"`, `"screenshot"`, or `"screenshot_full"`. Omit `output` to read the job. HTML is text; ZIP and image downloads are `Buffer` values. The SDK makes one request per call and does not poll for completion.
379
+ ### Scrape JSON
380
+
381
+ #### Description
382
+
383
+ Extract structured JSON from a page using a natural-language prompt. Append Json Schema: and a JSON schema to shape the output.
153
384
 
154
- ## Web Search
385
+ #### Parameters
155
386
 
156
- Search the web to retrieve real-time search results, including relevant website URLs, titles, descriptions, and related questions based on a given query.
387
+ | Parameter | HTTP field | Type | Default | Description |
388
+ | ------------------ | ------------------ | ------------------------------------------------------------------ | --------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
389
+ | `url` | `url` | string | Required | Absolute HTTP or HTTPS URL of the page to process. |
390
+ | `timeout` | `timeout` | number (integer) | `300` | Page load timeout in seconds, from 1 to 300. The HTTP request allows 30 additional seconds. |
391
+ | `geoCode` | `geoCode` | string | `"us"` | Two-letter country code to load the page from, sent in lowercase. |
392
+ | `proxyCountry` | `proxyCountry` | string | `"us"` | Two-letter country code of the proxy server, sent in lowercase. |
393
+ | `super` | `super` | boolean | `false` | Whether to route the request through real devices. |
394
+ | `waitUntil` | `waitUntil` | string: `domcontentloaded`, `load`, `networkidle0`, `networkidle2` | `"domcontentloaded"` | Navigation completion event to wait for: domcontentloaded, load, networkidle0, or networkidle2. |
395
+ | `proxy` | `proxy` | string | Omitted | Custom proxy URL used to load the page. |
396
+ | `maxRetries` | `maxRetries` | number (integer) | Omitted | Maximum number of retries, as a nonnegative integer. Omit this parameter for no limit. |
397
+ | `saveResult` | `saveResult` | boolean | `false` | Whether to save the result to the dashboard Result tab. |
398
+ | `prompt` | `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. |
399
+ | `browserRendering` | `browserRendering` | boolean | `false` | Whether to render the page in a browser before returning the result. |
400
+ | `html` | `html` | boolean | `false` | Whether to include the page HTML in the response. |
401
+ | `screenshot` | `screenshot` | boolean | `false` | Whether to include a base64 screenshot in the response. |
157
402
 
158
- ```typescript
159
- import { web_search } from "@mrscraper/sdk";
403
+ The request uses `agent=general` and 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.
160
404
 
161
- const result = await web_search("python web scraping", {
162
- raw: false,
163
- region: "us",
164
- language: "en",
165
- page: 1,
166
- format: "json",
405
+ #### Example
406
+
407
+ ```js
408
+ import { scrapeJson } from "@mrscraper/sdk";
409
+
410
+ const result = await scrapeJson("https://example.com", {
411
+ prompt:
412
+ '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"]}}',
413
+ browserRendering: true,
167
414
  });
168
415
  console.log(result.data);
169
416
  ```
170
417
 
171
- `web_search` accepts a search query as its first argument. `raw: true` is the default and requests HTML regardless of `format`. Set `raw: false` to use `format`.
418
+ #### Response
419
+
420
+ 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, markdown, and screenshot can be empty strings when not requested.
421
+
422
+ **Success response**
423
+
424
+ ```json
425
+ {
426
+ "status_code": 200,
427
+ "data": {
428
+ "success": true,
429
+ "data": [
430
+ {
431
+ "title": "Example item",
432
+ "price": "10.00"
433
+ }
434
+ ],
435
+ "thread_id": "THREAD_ID",
436
+ "token_usage": 1,
437
+ "html": "",
438
+ "markdown": "",
439
+ "screenshot": "",
440
+ "status": "Results ready",
441
+ "error": "",
442
+ "runtime": 1.23,
443
+ "cookies": []
444
+ },
445
+ "headers": {
446
+ "content-type": "application/json"
447
+ }
448
+ }
449
+ ```
172
450
 
173
- | Option | Default | Description |
174
- |--------|---------|-------------|
175
- | `url` | Required first argument | The search query |
176
- | `token` | Environment variable | API token override |
177
- | `raw` | `true` | Request HTML when true |
178
- | `format` | `"json"` | `"json"` or `"html"` when `raw` is false |
179
- | `region`, `language` | unset | Country and language |
180
- | `page` | unset | Results page number, starting at `1` |
181
- | `render_js` | `false` | Render JavaScript features |
182
- | `timeout` | `600` | HTTP request timeout in seconds |
451
+ ### Web search
183
452
 
184
- ## Account status
453
+ #### Description
185
454
 
186
- ```typescript
187
- import { account } from "@mrscraper/sdk";
455
+ Search the web and return ranked results with titles, URLs, descriptions, and sources.
188
456
 
189
- const result = await account(); // Optional: { token: "YOUR_TOKEN", timeout: 30 }
190
- console.log(result.data.subscription_status);
191
- console.log(result.data.token_remaining);
192
- console.log(result.data.user.email);
193
- ```
457
+ #### Parameters
194
458
 
195
- `account` checks the account associated with the configured API token. The timeout defaults to 30 seconds
196
- and must be positive. `data` is an `AccountSummary` with `subscription_status`,
197
- `enterprise`, `token_usage`, `token_limit`, `token_remaining`, `usage_percent`,
198
- `rate_limit`, `rate_ttl`, `auto_renew`, `ends_at`, and `user` (`name`, `email`,
199
- `verified`). Remaining tokens are clamped to zero when usage exceeds the limit.
200
- API keys, billing identifiers, and sensitive response headers are excluded.
459
+ | Parameter | HTTP field | Type | Default | Description |
460
+ | ------------ | ------------ | ---------------- | -------- | ------------------------------------------------------------------------------------------------- |
461
+ | `query` | `query` | string | Required | Search query text, trimmed before sending, containing 1 to 1000 characters. |
462
+ | `country` | `country` | string | `"us"` | Two-letter country code to search from, sent in lowercase. |
463
+ | `numResults` | `numResults` | number (integer) | `10` | Number of search results to request, as an integer from 10 to 100. Fewer results may be returned. |
201
464
 
202
- ## Errors and types
465
+ The HTTP deadline is fixed at 120 seconds. It is not a service parameter.
203
466
 
204
- All functions reject with `MrScraperError` for API, authentication, network, and timeout errors. `status` contains the HTTP status for API errors and is `undefined` for network errors. Invalid options throw `TypeError` or `RangeError`.
467
+ #### Example
205
468
 
206
- ```typescript
207
- import { scraper_html, MrScraperError } from "@mrscraper/sdk";
208
- import type { ScraperOptions, ScraperSitemapOptions, MrScraperResponse } from "@mrscraper/sdk";
469
+ ```js
470
+ import { webSearch } from "@mrscraper/sdk";
209
471
 
210
- try {
211
- const result: MrScraperResponse = await scraper_html("https://example.com");
212
- console.log(result.data);
213
- } catch (error) {
214
- if (error instanceof MrScraperError) {
215
- console.error(error.status, error.message);
216
- } else {
217
- throw error;
472
+ const result = await webSearch("site:example.com documentation", {
473
+ country: "id",
474
+ numResults: 20,
475
+ });
476
+ console.log(result.data);
477
+ ```
478
+
479
+ #### Response
480
+
481
+ The API body contains success, message, a data array, and tokenUsage. Each result includes rank, title, url, description, and source.
482
+
483
+ **Success response**
484
+
485
+ ```json
486
+ {
487
+ "status_code": 200,
488
+ "data": {
489
+ "success": true,
490
+ "message": "Example response",
491
+ "data": [
492
+ {
493
+ "rank": 1,
494
+ "title": "Example result",
495
+ "url": "https://example.com",
496
+ "description": "Example result description.",
497
+ "source": "example.com"
498
+ }
499
+ ],
500
+ "tokenUsage": 1
501
+ },
502
+ "headers": {
503
+ "content-type": "application/json; charset=utf-8"
218
504
  }
219
505
  }
220
506
  ```
221
507
 
222
- ## Develop
508
+ ## Response format
223
509
 
224
- ```bash
225
- npm ci
226
- npm test
227
- npm run build
510
+ Successful services use an envelope containing `status_code`, `data`, and `headers`. The `data` field contains the API response body; its field names are not converted to the SDK's naming style. Status preserves the complete body without adding summary fields.
511
+
512
+ ```json
513
+ {
514
+ "status_code": 200,
515
+ "data": "<html><body>Example page content...</body></html>",
516
+ "headers": {
517
+ "content-type": "text/html; charset=utf-8"
518
+ }
519
+ }
228
520
  ```
229
521
 
230
- `npm test` builds the SDK, checks TypeScript usage (including rejected output flags), and runs response-mock and local HTTP contract tests. It does not call the live API or require a token.
522
+ Responses are `MrScraperResponse<T>` objects. JSON becomes JavaScript values, text remains `string`, and binary remains `Buffer`. Sensitive response headers are removed for status.
231
523
 
232
- ## Manual tests with a real token
524
+ ## Error handling
233
525
 
234
- Run these commands from a source checkout. Build the SDK and configure your API token:
526
+ Authentication, HTTP, network, and timeout failures throw `MrScraperError`. Its `status` property is the HTTP status when available. Invalid arguments throw `TypeError` or `RangeError` before the request.
235
527
 
236
- ```bash
237
- npm run build
238
- export MRSCRAPER_API_TOKEN="YOUR_TOKEN"
528
+ ```js
529
+ import { scrapeHtml, MrScraperError } from "@mrscraper/sdk";
530
+
531
+ try {
532
+ await scrapeHtml("https://example.com");
533
+ } catch (error) {
534
+ if (error instanceof MrScraperError)
535
+ console.error(error.status, error.message);
536
+ else throw error;
537
+ }
239
538
  ```
240
539
 
241
- Check account status directly through the built SDK:
540
+ ## Integration features
242
541
 
243
- ```bash
244
- node --input-type=module <<'NODE'
245
- import { account } from "./dist/index.js";
542
+ ### Configuration
246
543
 
247
- const result = await account();
248
- console.log(result.status_code, result.data);
249
- NODE
250
- ```
544
+ Functions return promises and use camelCase options. Omit optional controls or use `undefined`; explicit `false` and `0` are preserved. TypeScript exports include `PageOptions`, `HtmlOptions`, `MarkdownOptions`, `ScreenshotOptions`, `JsonOptions`, `WebSearchOptions`, `StatusOptions`, and `MrScraperResponse<T>`.
251
545
 
252
- Retrieve Markdown:
546
+ ### Advanced usage
253
547
 
254
- ```bash
255
- node --input-type=module <<'NODE'
256
- import { scraper_markdown } from "./dist/index.js";
548
+ Supply a generic response body type when you know the returned API shape:
257
549
 
258
- const result = await scraper_markdown("https://example.com");
259
- console.log(result.status_code, result.data);
260
- NODE
550
+ ```ts
551
+ import { scrapeJson } from "@mrscraper/sdk";
552
+ const result = await scrapeJson<{ data: { title: string } }>(
553
+ "https://example.com",
554
+ { prompt: "Extract the page title" },
555
+ );
556
+ console.log(result.data.data.title);
261
557
  ```
262
558
 
263
- Start a brand-scraping job:
264
-
265
- ```bash
266
- node --input-type=module <<'NODE'
267
- import { scrape_brand } from "./dist/index.js";
559
+ Save screenshot JSON as an image when the API returns a base64 screenshot:
268
560
 
269
- const result = await scrape_brand("https://example.com");
270
- console.log(result.status_code, result.data);
271
- NODE
561
+ ```js
562
+ import { getScreenshot } from "@mrscraper/sdk";
563
+ import { writeFile } from "node:fs/promises";
564
+ const result = await getScreenshot("https://example.com");
565
+ if (
566
+ typeof result.data === "object" &&
567
+ typeof result.data?.screenshot === "string"
568
+ ) {
569
+ await writeFile("page.png", Buffer.from(result.data.screenshot, "base64"));
570
+ }
272
571
  ```
273
572
 
274
- Use the job ID from the response with `get_brand` as shown in [Brand scraping and downloads](#brand-scraping-and-downloads). These commands make live API requests, print the HTTP status and response data, and exit with a nonzero status on unhandled errors. They do not depend on the local `file.js` helper. To run the other service examples from a checkout, replace imports from `@mrscraper/sdk` with `./dist/index.js`.
573
+ ### Troubleshooting
574
+
575
+ Check environment credentials when authentication fails. Use camelCase option names and `super`, rather than old snake_case options or `superMode`. Page timeouts are integers from 1 to 300; status and search do not expose timeout options.
576
+
577
+ ## Migration
275
578
 
276
- ## Publish manually to npm
579
+ Replace `account()` with `status()` and read the raw API body. Remove status/search timeout options and rename `superMode` to `super`. Replace combined scraper calls with `scrapeHtml`, `scrapeMarkdown`, or `getScreenshot`; use camelCase options. Replace `full_page` with `screenshot: "full"` or `"top"`. Search uses `query`, `country`, and `numResults`.
277
580
 
278
- This checkout prepares documentation patch **4.0.1**. Version **4.0.0** is
279
- already published. Publishing remains manual. Validate and preview the package:
581
+ ## Development and testing
582
+
583
+ ### Automated checks
584
+
585
+ The automated suite checks service behavior without production API calls.
280
586
 
281
587
  ```bash
282
588
  npm ci
283
589
  npm test
284
- npm pack --dry-run
285
- npm publish --dry-run --access public
590
+ npm run build
286
591
  ```
287
592
 
288
- The package includes `dist/`, `README.md`, `LICENSE`, `mrscraper.jpeg`, and
289
- `package.json`. The `files` list excludes the local `file.js` helper. Commit
290
- and push the release files, then publish with your npm account:
593
+ ### Manual checks
594
+
595
+ The following commands call the live API using your credentials and consume quota.
291
596
 
292
597
  ```bash
293
- npm login
294
- npm whoami
295
- npm publish --access public
296
- npm view @mrscraper/sdk version
297
- npm view @mrscraper/sdk dist-tags --json
598
+ npm run build
599
+ node file.js status
600
+ node file.js scrapeHtml https://example.com
601
+ node file.js webSearch "site:example.com documentation"
298
602
  ```
299
603
 
300
- Complete npm's browser login and two-factor authentication prompts. The
301
- `prepublishOnly` script rebuilds `dist` before publishing. Each version can be
302
- published only once. For later releases, update `package.json` and
303
- `package-lock.json` together with a new version before validating and publishing.
304
-
305
604
  ## License
306
605
 
307
- MIT — see [LICENSE](./LICENSE).
606
+ MIT. See [LICENSE](./LICENSE).