scrapfly-sdk 0.7.3 → 0.10.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.
Files changed (75) hide show
  1. package/esm/browserconfig.d.ts +59 -0
  2. package/esm/browserconfig.d.ts.map +1 -0
  3. package/esm/browserconfig.js +207 -0
  4. package/esm/client.d.ts +209 -1
  5. package/esm/client.d.ts.map +1 -1
  6. package/esm/client.js +902 -5
  7. package/esm/crawl.d.ts +118 -0
  8. package/esm/crawl.d.ts.map +1 -0
  9. package/esm/crawl.js +230 -0
  10. package/esm/crawlerconfig.d.ts +119 -0
  11. package/esm/crawlerconfig.d.ts.map +1 -0
  12. package/esm/crawlerconfig.js +398 -0
  13. package/esm/crawlerresult.d.ts +253 -0
  14. package/esm/crawlerresult.d.ts.map +1 -0
  15. package/esm/crawlerresult.js +327 -0
  16. package/esm/errors.d.ts +4 -0
  17. package/esm/errors.d.ts.map +1 -1
  18. package/esm/errors.js +6 -0
  19. package/esm/extractionconfig.d.ts +2 -0
  20. package/esm/extractionconfig.d.ts.map +1 -1
  21. package/esm/extractionconfig.js +10 -0
  22. package/esm/main.d.ts +9 -1
  23. package/esm/main.d.ts.map +1 -1
  24. package/esm/main.js +6 -1
  25. package/esm/monitoringconfig.d.ts +36 -0
  26. package/esm/monitoringconfig.d.ts.map +1 -0
  27. package/esm/monitoringconfig.js +10 -0
  28. package/esm/polyfill.d.ts +2 -0
  29. package/esm/polyfill.d.ts.map +1 -1
  30. package/esm/polyfill.js +12 -0
  31. package/esm/scrapeconfig.d.ts +27 -0
  32. package/esm/scrapeconfig.d.ts.map +1 -1
  33. package/esm/scrapeconfig.js +44 -1
  34. package/esm/screenshotconfig.d.ts +2 -2
  35. package/esm/screenshotconfig.d.ts.map +1 -1
  36. package/esm/utils.d.ts.map +1 -1
  37. package/esm/utils.js +16 -2
  38. package/package.json +1 -1
  39. package/script/browserconfig.d.ts +59 -0
  40. package/script/browserconfig.d.ts.map +1 -0
  41. package/script/browserconfig.js +211 -0
  42. package/script/client.d.ts +209 -1
  43. package/script/client.d.ts.map +1 -1
  44. package/script/client.js +901 -4
  45. package/script/crawl.d.ts +118 -0
  46. package/script/crawl.d.ts.map +1 -0
  47. package/script/crawl.js +257 -0
  48. package/script/crawlerconfig.d.ts +119 -0
  49. package/script/crawlerconfig.d.ts.map +1 -0
  50. package/script/crawlerconfig.js +402 -0
  51. package/script/crawlerresult.d.ts +253 -0
  52. package/script/crawlerresult.d.ts.map +1 -0
  53. package/script/crawlerresult.js +335 -0
  54. package/script/errors.d.ts +4 -0
  55. package/script/errors.d.ts.map +1 -1
  56. package/script/errors.js +9 -1
  57. package/script/extractionconfig.d.ts +2 -0
  58. package/script/extractionconfig.d.ts.map +1 -1
  59. package/script/extractionconfig.js +10 -0
  60. package/script/main.d.ts +9 -1
  61. package/script/main.d.ts.map +1 -1
  62. package/script/main.js +17 -1
  63. package/script/monitoringconfig.d.ts +36 -0
  64. package/script/monitoringconfig.d.ts.map +1 -0
  65. package/script/monitoringconfig.js +13 -0
  66. package/script/polyfill.d.ts +2 -0
  67. package/script/polyfill.d.ts.map +1 -1
  68. package/script/polyfill.js +14 -1
  69. package/script/scrapeconfig.d.ts +27 -0
  70. package/script/scrapeconfig.d.ts.map +1 -1
  71. package/script/scrapeconfig.js +44 -1
  72. package/script/screenshotconfig.d.ts +2 -2
  73. package/script/screenshotconfig.d.ts.map +1 -1
  74. package/script/utils.d.ts.map +1 -1
  75. package/script/utils.js +16 -2
@@ -281,6 +281,30 @@ export class ScrapeConfig {
281
281
  writable: true,
282
282
  value: void 0
283
283
  });
284
+ Object.defineProperty(this, "browser_brand", {
285
+ enumerable: true,
286
+ configurable: true,
287
+ writable: true,
288
+ value: void 0
289
+ });
290
+ Object.defineProperty(this, "proxified_response", {
291
+ enumerable: true,
292
+ configurable: true,
293
+ writable: true,
294
+ value: void 0
295
+ });
296
+ Object.defineProperty(this, "rendering_stage", {
297
+ enumerable: true,
298
+ configurable: true,
299
+ writable: true,
300
+ value: void 0
301
+ });
302
+ Object.defineProperty(this, "geolocation", {
303
+ enumerable: true,
304
+ configurable: true,
305
+ writable: true,
306
+ value: void 0
307
+ });
284
308
  this.validateOptions(options);
285
309
  if (options.format && !Object.values(Format).includes(options.format)) {
286
310
  throw new ScrapeConfigError(`Invalid Format param value: ${options.format}`);
@@ -317,7 +341,7 @@ export class ScrapeConfig {
317
341
  this.cache_ttl = options.cache_ttl ?? this.cache_ttl;
318
342
  this.proxy_pool = options.proxy_pool ?? this.proxy_pool;
319
343
  this.session = options.session ?? this.session;
320
- this.tags = new Set(options.tags) ?? this.tags;
344
+ this.tags = options.tags ? new Set(options.tags) : this.tags;
321
345
  this.format = options.format ?? this.format;
322
346
  this.format_options = options.format_options ?? this.format_options;
323
347
  this.extraction_template = options.extraction_template ?? this.extraction_template;
@@ -341,6 +365,10 @@ export class ScrapeConfig {
341
365
  this.os = options.os ?? this.os;
342
366
  this.lang = options.lang ?? this.lang;
343
367
  this.auto_scroll = options.auto_scroll ?? this.auto_scroll;
368
+ this.browser_brand = options.browser_brand ?? this.browser_brand;
369
+ this.proxified_response = options.proxified_response ?? this.proxified_response;
370
+ this.rendering_stage = options.rendering_stage ?? this.rendering_stage;
371
+ this.geolocation = options.geolocation ?? this.geolocation;
344
372
  this.dns = options.dns ?? this.dns;
345
373
  this.ssl = options.ssl ?? this.ssl;
346
374
  this.debug = options.debug ?? this.debug;
@@ -412,6 +440,12 @@ export class ScrapeConfig {
412
440
  if (this.timeout) {
413
441
  params.timeout = this.timeout;
414
442
  }
443
+ if (this.cost_budget !== undefined) {
444
+ params.cost_budget = this.cost_budget;
445
+ }
446
+ if (this.proxified_response !== undefined) {
447
+ params.proxified_response = this.proxified_response;
448
+ }
415
449
  if (this.render_js === true) {
416
450
  params.render_js = true;
417
451
  if (this.wait_for_selector !== undefined) {
@@ -426,6 +460,12 @@ export class ScrapeConfig {
426
460
  if (this.rendering_wait !== undefined) {
427
461
  params.rendering_wait = this.rendering_wait;
428
462
  }
463
+ if (this.rendering_stage && this.rendering_stage !== 'complete') {
464
+ params.rendering_stage = this.rendering_stage;
465
+ }
466
+ if (this.geolocation) {
467
+ params.geolocation = this.geolocation;
468
+ }
429
469
  if (this.screenshots !== undefined) {
430
470
  Object.keys(this.screenshots).forEach((key) => {
431
471
  params[`screenshots[${key}]`] = (this.screenshots || {})[key];
@@ -539,6 +579,9 @@ export class ScrapeConfig {
539
579
  if (this.os !== undefined) {
540
580
  params.os = this.os;
541
581
  }
582
+ if (this.browser_brand !== undefined) {
583
+ params.browser_brand = this.browser_brand;
584
+ }
542
585
  return params;
543
586
  }
544
587
  }
@@ -59,7 +59,7 @@ type ScreenshotConfigOptions = {
59
59
  cache?: boolean;
60
60
  cache_ttl?: number;
61
61
  cache_clear?: boolean;
62
- vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredvision' | VisionDeficiency;
62
+ vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredVision' | 'reducedContrast' | VisionDeficiency;
63
63
  webhook?: string;
64
64
  };
65
65
  export declare class ScreenshotConfig {
@@ -77,7 +77,7 @@ export declare class ScreenshotConfig {
77
77
  cache?: boolean;
78
78
  cache_ttl?: number;
79
79
  cache_clear?: boolean;
80
- vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredvision' | VisionDeficiency;
80
+ vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredVision' | 'reducedContrast' | VisionDeficiency;
81
81
  webhook?: string;
82
82
  constructor(options: ScreenshotConfigOptions);
83
83
  private validateOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"screenshotconfig.d.ts","sourceRoot":"","sources":["../src/screenshotconfig.ts"],"names":[],"mappings":"AAIA,oBAAY,OAAO;IACjB;;;;;;;QAOI;IACJ,WAAW,gBAAgB;IAC3B,SAAS,cAAc;IACvB,a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AG,CAAC,MAAM,CAAC,GAAG,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAc5E"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQtD;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CAC5B,CAAC;AAEF,wBAAsB,UAAU,CAC9B,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,MAAU,EACnB,UAAU,GAAE,MAAa,GACxB,OAAO,CAAC,QAAQ,CAAC,CA6CnB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAc5E"}
package/esm/utils.js CHANGED
@@ -14,7 +14,18 @@ export async function fetchRetry(config, retries = 3, retryDelay = 1000) {
14
14
  try {
15
15
  // XXX: note that cloudflare workers don't support init options
16
16
  const { url, ...reqInit } = config;
17
- const response = await fetch(new Request(url, reqInit));
17
+ // The `body` field on RequestOptions is typed as string | Uint8Array for
18
+ // historical reasons. The dnt (deno-to-node) build does not expose the
19
+ // DOM `BodyInit` alias in every lib target, so we cast to `any` here to
20
+ // stay portable across Deno, Node, Bun and Cloudflare Workers. The
21
+ // runtime values (string | Uint8Array) are all valid fetch body inputs.
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ const init = {
24
+ method: reqInit.method,
25
+ headers: reqInit.headers,
26
+ body: reqInit.body,
27
+ };
28
+ const response = await fetch(new Request(url, init));
18
29
  // retry 5xx status codes
19
30
  if (response.status >= 500 && response.status < 600) {
20
31
  const _text = await response.text(); // consume response to prevent leak
@@ -30,7 +41,10 @@ export async function fetchRetry(config, retries = 3, retryDelay = 1000) {
30
41
  }
31
42
  catch (error) {
32
43
  lastError = error;
33
- if (attempt === retries || error.name === 'AbortError') {
44
+ // AbortError should never be retried: it means the caller explicitly
45
+ // gave up (cancel token, timeout, etc.) and we shouldn't paper over it.
46
+ const isAbort = error instanceof Error && error.name === 'AbortError';
47
+ if (attempt === retries || isAbort) {
34
48
  throw error;
35
49
  }
36
50
  await new Promise((resolve) => setTimeout(resolve, retryDelay));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scrapfly-sdk",
3
- "version": "0.7.3",
3
+ "version": "0.10.0",
4
4
  "description": "SDK for Scrapfly.io API for web scraping, screenshotting and data extraction",
5
5
  "keywords": [
6
6
  "web scraping",
@@ -0,0 +1,59 @@
1
+ export declare enum ProxyPool {
2
+ DATACENTER = "datacenter",
3
+ RESIDENTIAL = "residential"
4
+ }
5
+ export declare enum OperatingSystem {
6
+ LINUX = "linux",
7
+ WINDOWS = "windows",
8
+ MACOS = "macos"
9
+ }
10
+ export type BrowserConfigOptions = {
11
+ proxy_pool?: ProxyPool | string;
12
+ os?: OperatingSystem | string;
13
+ session?: string;
14
+ country?: string;
15
+ auto_close?: boolean;
16
+ timeout?: number;
17
+ debug?: boolean;
18
+ extensions?: string[];
19
+ block_images?: boolean;
20
+ block_styles?: boolean;
21
+ block_fonts?: boolean;
22
+ block_media?: boolean;
23
+ screenshot?: boolean;
24
+ resolution?: string;
25
+ target_url?: string;
26
+ cache?: boolean;
27
+ blacklist?: boolean;
28
+ unblock?: boolean;
29
+ unblock_timeout?: number;
30
+ browser_brand?: string;
31
+ };
32
+ export declare class BrowserConfig {
33
+ proxy_pool?: string;
34
+ os?: string;
35
+ session?: string;
36
+ country?: string;
37
+ auto_close?: boolean;
38
+ timeout?: number;
39
+ debug?: boolean;
40
+ extensions?: string[];
41
+ block_images?: boolean;
42
+ block_styles?: boolean;
43
+ block_fonts?: boolean;
44
+ block_media?: boolean;
45
+ screenshot?: boolean;
46
+ resolution?: string;
47
+ target_url?: string;
48
+ cache?: boolean;
49
+ blacklist?: boolean;
50
+ unblock?: boolean;
51
+ unblock_timeout?: number;
52
+ browser_brand?: string;
53
+ constructor(options?: BrowserConfigOptions);
54
+ /**
55
+ * Generate the WebSocket URL for a Cloud Browser session.
56
+ */
57
+ websocketUrl(apiKey: string, host?: string): string;
58
+ }
59
+ //# sourceMappingURL=browserconfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserconfig.d.ts","sourceRoot":"","sources":["../src/browserconfig.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,UAAU,eAAe;IACzB,WAAW,gBAAgB;CAC5B;AAED,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAChC,EAAE,CAAC,EAAE,eAAe,GAAG,MAAM,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,qBAAa,aAAa;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;gBAEX,OAAO,GAAE,oBAAyB;IA0B9C;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;CA4BpD"}
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BrowserConfig = exports.OperatingSystem = exports.ProxyPool = void 0;
4
+ var ProxyPool;
5
+ (function (ProxyPool) {
6
+ ProxyPool["DATACENTER"] = "datacenter";
7
+ ProxyPool["RESIDENTIAL"] = "residential";
8
+ })(ProxyPool || (exports.ProxyPool = ProxyPool = {}));
9
+ var OperatingSystem;
10
+ (function (OperatingSystem) {
11
+ OperatingSystem["LINUX"] = "linux";
12
+ OperatingSystem["WINDOWS"] = "windows";
13
+ OperatingSystem["MACOS"] = "macos";
14
+ })(OperatingSystem || (exports.OperatingSystem = OperatingSystem = {}));
15
+ class BrowserConfig {
16
+ constructor(options = {}) {
17
+ Object.defineProperty(this, "proxy_pool", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ Object.defineProperty(this, "os", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ Object.defineProperty(this, "session", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+ Object.defineProperty(this, "country", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ Object.defineProperty(this, "auto_close", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: void 0
46
+ });
47
+ Object.defineProperty(this, "timeout", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: void 0
52
+ });
53
+ Object.defineProperty(this, "debug", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: void 0
58
+ });
59
+ Object.defineProperty(this, "extensions", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: void 0
64
+ });
65
+ Object.defineProperty(this, "block_images", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: void 0
70
+ });
71
+ Object.defineProperty(this, "block_styles", {
72
+ enumerable: true,
73
+ configurable: true,
74
+ writable: true,
75
+ value: void 0
76
+ });
77
+ Object.defineProperty(this, "block_fonts", {
78
+ enumerable: true,
79
+ configurable: true,
80
+ writable: true,
81
+ value: void 0
82
+ });
83
+ Object.defineProperty(this, "block_media", {
84
+ enumerable: true,
85
+ configurable: true,
86
+ writable: true,
87
+ value: void 0
88
+ });
89
+ Object.defineProperty(this, "screenshot", {
90
+ enumerable: true,
91
+ configurable: true,
92
+ writable: true,
93
+ value: void 0
94
+ });
95
+ Object.defineProperty(this, "resolution", {
96
+ enumerable: true,
97
+ configurable: true,
98
+ writable: true,
99
+ value: void 0
100
+ });
101
+ Object.defineProperty(this, "target_url", {
102
+ enumerable: true,
103
+ configurable: true,
104
+ writable: true,
105
+ value: void 0
106
+ });
107
+ Object.defineProperty(this, "cache", {
108
+ enumerable: true,
109
+ configurable: true,
110
+ writable: true,
111
+ value: void 0
112
+ });
113
+ Object.defineProperty(this, "blacklist", {
114
+ enumerable: true,
115
+ configurable: true,
116
+ writable: true,
117
+ value: void 0
118
+ });
119
+ Object.defineProperty(this, "unblock", {
120
+ enumerable: true,
121
+ configurable: true,
122
+ writable: true,
123
+ value: void 0
124
+ });
125
+ Object.defineProperty(this, "unblock_timeout", {
126
+ enumerable: true,
127
+ configurable: true,
128
+ writable: true,
129
+ value: void 0
130
+ });
131
+ Object.defineProperty(this, "browser_brand", {
132
+ enumerable: true,
133
+ configurable: true,
134
+ writable: true,
135
+ value: void 0
136
+ });
137
+ if (options.timeout !== undefined && options.timeout > 1800) {
138
+ throw new Error('timeout cannot exceed 1800 seconds (30 minutes)');
139
+ }
140
+ this.proxy_pool = options.proxy_pool;
141
+ this.os = options.os;
142
+ this.session = options.session;
143
+ this.country = options.country;
144
+ this.auto_close = options.auto_close;
145
+ this.timeout = options.timeout;
146
+ this.debug = options.debug;
147
+ this.extensions = options.extensions;
148
+ this.block_images = options.block_images;
149
+ this.block_styles = options.block_styles;
150
+ this.block_fonts = options.block_fonts;
151
+ this.block_media = options.block_media;
152
+ this.screenshot = options.screenshot;
153
+ this.resolution = options.resolution;
154
+ this.target_url = options.target_url;
155
+ this.cache = options.cache;
156
+ this.blacklist = options.blacklist;
157
+ this.unblock = options.unblock;
158
+ this.unblock_timeout = options.unblock_timeout;
159
+ this.browser_brand = options.browser_brand;
160
+ }
161
+ /**
162
+ * Generate the WebSocket URL for a Cloud Browser session.
163
+ */
164
+ websocketUrl(apiKey, host) {
165
+ const params = new URLSearchParams();
166
+ params.set('api_key', apiKey);
167
+ if (this.proxy_pool !== undefined)
168
+ params.set('proxy_pool', this.proxy_pool);
169
+ if (this.os !== undefined)
170
+ params.set('os', this.os);
171
+ if (this.session !== undefined)
172
+ params.set('session', this.session);
173
+ if (this.country !== undefined)
174
+ params.set('country', this.country);
175
+ if (this.auto_close !== undefined)
176
+ params.set('auto_close', String(this.auto_close));
177
+ if (this.timeout !== undefined)
178
+ params.set('timeout', String(this.timeout));
179
+ if (this.debug !== undefined)
180
+ params.set('debug', String(this.debug));
181
+ if (this.extensions && this.extensions.length > 0)
182
+ params.set('extensions', this.extensions.join(','));
183
+ if (this.block_images !== undefined)
184
+ params.set('block_images', String(this.block_images));
185
+ if (this.block_styles !== undefined)
186
+ params.set('block_styles', String(this.block_styles));
187
+ if (this.block_fonts !== undefined)
188
+ params.set('block_fonts', String(this.block_fonts));
189
+ if (this.block_media !== undefined)
190
+ params.set('block_media', String(this.block_media));
191
+ if (this.screenshot !== undefined)
192
+ params.set('screenshot', String(this.screenshot));
193
+ if (this.resolution !== undefined)
194
+ params.set('resolution', this.resolution);
195
+ if (this.target_url !== undefined)
196
+ params.set('target_url', this.target_url);
197
+ if (this.cache !== undefined)
198
+ params.set('cache', String(this.cache));
199
+ if (this.blacklist !== undefined)
200
+ params.set('blacklist', String(this.blacklist));
201
+ if (this.unblock !== undefined)
202
+ params.set('unblock', String(this.unblock));
203
+ if (this.unblock_timeout !== undefined)
204
+ params.set('unblock_timeout', String(this.unblock_timeout));
205
+ if (this.browser_brand !== undefined)
206
+ params.set('browser_brand', this.browser_brand);
207
+ const baseHost = host || 'wss://browser.scrapfly.io';
208
+ return `${baseHost}?${params.toString()}`;
209
+ }
210
+ }
211
+ exports.BrowserConfig = BrowserConfig;
@@ -3,14 +3,25 @@ import * as errors from './errors.js';
3
3
  import type { ScrapeConfig } from './scrapeconfig.js';
4
4
  import type { ScreenshotConfig } from './screenshotconfig.js';
5
5
  import type { ExtractionConfig } from './extractionconfig.js';
6
+ import { BrowserConfig } from './browserconfig.js';
6
7
  import { type AccountData, ExtractionResult, ScrapeResult, ScreenshotResult } from './result.js';
8
+ import type { Rec } from './types.js';
9
+ import type { CrawlerConfig, CrawlerContentFormat } from './crawlerconfig.js';
10
+ import { CrawlerArtifact, type CrawlerArtifactType, CrawlerContents, CrawlerStatus, CrawlerUrls } from './crawlerresult.js';
11
+ import { type CloudBrowserMonitoringOptions, type MonitoringMetricsOptions, type MonitoringTargetMetricsOptions } from './monitoringconfig.js';
7
12
  export declare class ScrapflyClient {
8
13
  HOST: string;
14
+ CLOUD_BROWSER_HOST: string;
15
+ CLOUD_BROWSER_API_HOST: string;
9
16
  private key;
10
17
  private ua;
18
+ private cloudBrowserHost;
19
+ private cloudBrowserApiHost;
11
20
  fetch: typeof fetchRetry;
12
21
  constructor(options: {
13
22
  key: string;
23
+ host?: string;
24
+ cloudBrowserHost?: string;
14
25
  });
15
26
  /**
16
27
  * Raise appropriate error for given response and scrape result
@@ -28,10 +39,24 @@ export declare class ScrapflyClient {
28
39
  * Retrieve Scrapfly account details
29
40
  */
30
41
  account(): Promise<AccountData>;
42
+ private monitoringRequest;
43
+ private buildMetricsParams;
44
+ private buildTargetParams;
45
+ getMonitoringMetrics(options?: MonitoringMetricsOptions): Promise<Rec<any>>;
46
+ getMonitoringTargetMetrics(options: MonitoringTargetMetricsOptions): Promise<Rec<any>>;
47
+ getScreenshotMonitoringMetrics(options?: MonitoringMetricsOptions): Promise<Rec<any>>;
48
+ getScreenshotMonitoringTargetMetrics(options: MonitoringTargetMetricsOptions): Promise<Rec<any>>;
49
+ getExtractionMonitoringMetrics(options?: MonitoringMetricsOptions): Promise<Rec<any>>;
50
+ getExtractionMonitoringTargetMetrics(options: MonitoringTargetMetricsOptions): Promise<Rec<any>>;
51
+ getCrawlerMonitoringMetrics(options?: MonitoringMetricsOptions): Promise<Rec<any>>;
52
+ getCrawlerMonitoringTargetMetrics(options: MonitoringTargetMetricsOptions): Promise<Rec<any>>;
53
+ getBrowserMonitoringMetrics(options?: CloudBrowserMonitoringOptions): Promise<Rec<any>>;
54
+ getBrowserMonitoringTimeseries(options?: CloudBrowserMonitoringOptions): Promise<Rec<any>>;
55
+ private buildBrowserParams;
31
56
  /**
32
57
  * Issue a single scrape command from a given scrape configuration
33
58
  */
34
- scrape(config: ScrapeConfig): Promise<ScrapeResult>;
59
+ scrape(config: ScrapeConfig): Promise<ScrapeResult | Response>;
35
60
  /**
36
61
  Concurrently scrape multiple configs
37
62
  This is a async generator call it like this:
@@ -69,5 +94,188 @@ export declare class ScrapflyClient {
69
94
  * Extract structured data from a web page
70
95
  */
71
96
  extract(config: ExtractionConfig): Promise<ExtractionResult>;
97
+ /**
98
+ * Throw a typed error for a crawler JSON error envelope.
99
+ *
100
+ * The crawler endpoints (status, urls, contents, artifact, cancel) return either
101
+ * a clean JSON body on success or an error envelope `{error_id, http_code, message, ...}`.
102
+ * Use this to map the envelope to one of `BadApiKeyError` / `ScrapflyCrawlerError` /
103
+ * `ApiHttpClientError`.
104
+ */
105
+ private throwCrawlerError;
106
+ /**
107
+ * Schedule a new crawler job.
108
+ *
109
+ * `POST /crawl` — returns `{crawler_uuid, status}` on success. On failure throws
110
+ * `ScrapflyCrawlerError`, `BadApiKeyError`, or `ApiHttpClientError`.
111
+ */
112
+ crawl(config: CrawlerConfig): Promise<{
113
+ crawler_uuid: string;
114
+ status: string;
115
+ }>;
116
+ /**
117
+ * Get the current status of a crawler job.
118
+ *
119
+ * `GET /crawl/{uuid}/status`
120
+ */
121
+ crawlStatus(uuid: string): Promise<CrawlerStatus>;
122
+ /**
123
+ * List crawled URLs for a job, optionally filtered by status and paginated.
124
+ *
125
+ * `GET /crawl/{uuid}/urls?status=<filter>&page=<n>&per_page=<n>`
126
+ *
127
+ * The server streams the response as `text/plain` — one record per line.
128
+ * JSON is intentionally NOT used here because this endpoint is expected to
129
+ * scale to millions of URLs per job, and materialising that as JSON would
130
+ * be prohibitively expensive on both the server and the client. See
131
+ * {@link CrawlerUrls.fromText} for the exact line format.
132
+ *
133
+ * Pagination: the wire protocol carries no global `total`. Request further
134
+ * pages by incrementing `page` until a response contains no records.
135
+ */
136
+ crawlUrls(uuid: string, opts?: {
137
+ status?: 'visited' | 'pending' | 'failed' | 'skipped';
138
+ page?: number;
139
+ per_page?: number;
140
+ }): Promise<CrawlerUrls>;
141
+ /**
142
+ * Get crawled content from a crawler job.
143
+ *
144
+ * Two modes:
145
+ *
146
+ * 1. **JSON mode** (default, `plain` omitted or false): returns a {@link CrawlerContents}
147
+ * with a `contents` map (URL → format → content) and pagination links. Useful for
148
+ * bulk retrieval. Honors `limit` (max 50, default 10) and `offset`.
149
+ *
150
+ * 2. **Plain mode** (`plain: true`): returns the raw content for a single URL/format
151
+ * as a `string`, with content-type matching the format. Requires `url`. Useful for
152
+ * piping markdown/text directly. **New in this SDK** (not in Python SDK as of 0.8.27).
153
+ *
154
+ * `GET /crawl/{uuid}/contents`
155
+ */
156
+ crawlContents(uuid: string, opts: {
157
+ format: CrawlerContentFormat;
158
+ url?: string;
159
+ plain?: boolean;
160
+ limit?: number;
161
+ offset?: number;
162
+ }): Promise<CrawlerContents | string>;
163
+ /**
164
+ * Batch-retrieve crawled content for up to 100 URLs in one round-trip.
165
+ *
166
+ * `POST /crawl/{uuid}/contents/batch`
167
+ *
168
+ * The request body is a newline-separated list of URLs (`text/plain`). The response
169
+ * is a `multipart/related` (RFC 2387) document with one part per found URL. Each
170
+ * part has `Content-Type` (matching the format) and `Content-Location` (the URL).
171
+ *
172
+ * Returns a map of `url → format → content`. Formats not requested for a given URL
173
+ * are simply absent from its inner map.
174
+ */
175
+ crawlContentsBatch(uuid: string, urls: string[], formats: CrawlerContentFormat[]): Promise<Record<string, Record<string, string>>>;
176
+ /**
177
+ * Download a crawler job's WARC or HAR artifact as raw bytes.
178
+ *
179
+ * `GET /crawl/{uuid}/artifact?type=warc|har`
180
+ *
181
+ * The SDK does NOT bundle WARC/HAR parsers — use a dedicated library (e.g. `warcio`
182
+ * on npm) to walk the records. The returned {@link CrawlerArtifact} provides a
183
+ * `save(path)` helper for the common case of writing the artifact to disk.
184
+ */
185
+ crawlArtifact(uuid: string, type?: CrawlerArtifactType): Promise<CrawlerArtifact>;
186
+ /**
187
+ * Cancel a running crawler job.
188
+ *
189
+ * `POST /crawl/{uuid}/cancel` — returns `true` on success. The endpoint
190
+ * is idempotent: cancelling a crawl that has already finished is a no-op
191
+ * and still returns success.
192
+ *
193
+ * Note: earlier versions of this SDK called `DELETE /crawl/{uuid}`, which
194
+ * is not a valid public route — that path silently 404'd against the
195
+ * public API. Fixed in 0.8.0 to use the correct documented endpoint.
196
+ */
197
+ crawlCancel(uuid: string): Promise<boolean>;
198
+ /**
199
+ * Get the WebSocket URL for a Cloud Browser session.
200
+ */
201
+ cloudBrowser(config?: BrowserConfig): string;
202
+ /**
203
+ * Call the Cloud Browser Unblock API.
204
+ */
205
+ cloudBrowserUnblock(options: {
206
+ url: string;
207
+ proxy_pool?: string;
208
+ country?: string;
209
+ os?: string;
210
+ timeout?: number;
211
+ browser_timeout?: number;
212
+ headers?: Record<string, string>;
213
+ body?: string;
214
+ method?: string;
215
+ }): Promise<{
216
+ ws_url: string;
217
+ session_id: string;
218
+ run_id: string;
219
+ }>;
220
+ /**
221
+ * Stop a Cloud Browser session.
222
+ */
223
+ cloudBrowserSessionStop(sessionId: string): Promise<void>;
224
+ /**
225
+ * List all browser extensions.
226
+ */
227
+ cloudBrowserExtensionList(): Promise<{
228
+ extensions: any[];
229
+ quota: {
230
+ used: number;
231
+ limit: number;
232
+ };
233
+ }>;
234
+ /**
235
+ * Delete a browser extension.
236
+ */
237
+ cloudBrowserExtensionDelete(extensionId: string): Promise<{
238
+ success: boolean;
239
+ message: string;
240
+ }>;
241
+ /**
242
+ * Get details of a specific browser extension.
243
+ */
244
+ cloudBrowserExtensionGet(extensionId: string): Promise<Record<string, any>>;
245
+ /**
246
+ * Upload a browser extension from a local file (.zip or .crx).
247
+ * Pass a file path — the file is read and sent as multipart/form-data.
248
+ */
249
+ cloudBrowserExtensionUpload(filePath: string): Promise<{
250
+ extension: Record<string, any>;
251
+ is_update: boolean;
252
+ }>;
253
+ /**
254
+ * Install a browser extension from a URL (.crx file).
255
+ * URL-based extensions auto-update on each browser session start.
256
+ */
257
+ cloudBrowserExtensionUploadFromUrl(extensionUrl: string): Promise<{
258
+ extension: Record<string, any>;
259
+ is_update: boolean;
260
+ }>;
261
+ /**
262
+ * Download a debug session recording video.
263
+ * Returns the video as an ArrayBuffer (stream from server).
264
+ */
265
+ cloudBrowserVideo(runId: string): Promise<{
266
+ data: ArrayBuffer;
267
+ filename: string;
268
+ }>;
269
+ /**
270
+ * Get playback info for a debug session recording.
271
+ */
272
+ cloudBrowserPlayback(runId: string): Promise<Record<string, any>>;
273
+ /**
274
+ * List all running Cloud Browser sessions.
275
+ */
276
+ cloudBrowserSessions(): Promise<{
277
+ sessions: any[];
278
+ total: number;
279
+ }>;
72
280
  }
73
281
  //# sourceMappingURL=client.d.ts.map