screenshotone-api-sdk 1.1.21 → 1.1.22

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.
@@ -81,6 +81,15 @@ export declare class TakeOptions {
81
81
  * Selector is a CSS-like selector of the element to take a screenshot of.
82
82
  */
83
83
  selector(selector: string): TakeOptions;
84
+ /**
85
+ * Sets the algorithm used to capture an element selected with `selector`.
86
+ * Available values are `default` and `clip`.
87
+ */
88
+ selectorAlgorithm(algorithm: string): TakeOptions;
89
+ /**
90
+ * Controls whether the selected element is scrolled into view before capture.
91
+ */
92
+ selectorScrollIntoView(scroll: boolean): TakeOptions;
84
93
  /**
85
94
  * Available response types:
86
95
  * by_format — return exactly the response defined in the format option. If format=png, the response will be the binary representation of the png with the content type header image/png;
@@ -97,6 +106,18 @@ export declare class TakeOptions {
97
106
  * Capture beyond the viewport.
98
107
  */
99
108
  captureBeyondViewport(beyond: boolean): TakeOptions;
109
+ /**
110
+ * Includes open and closed shadow DOM roots when extracting page content.
111
+ */
112
+ includeShadowDom(include: boolean): TakeOptions;
113
+ /**
114
+ * Sets the attachment name. The response format is added as the suffix.
115
+ */
116
+ attachmentName(name: string): TakeOptions;
117
+ /**
118
+ * Sets an alphanumeric identifier returned with webhook requests.
119
+ */
120
+ externalIdentifier(identifier: string): TakeOptions;
100
121
  /**
101
122
  * When reduced_motion set to `true`,
102
123
  * the API will request the site to minimize the amount of non-essential motion it uses.
@@ -140,6 +161,22 @@ export declare class TakeOptions {
140
161
  * Scripts specifies custom scripts for the page.
141
162
  */
142
163
  scripts(scripts: string): TakeOptions;
164
+ /**
165
+ * Sets a selector for an element to click before taking the screenshot.
166
+ */
167
+ click(selector: string): TakeOptions;
168
+ /**
169
+ * Sets a selector for an element to hover over before taking the screenshot.
170
+ */
171
+ hover(selector: string): TakeOptions;
172
+ /**
173
+ * Controls whether a missing click selector causes an error.
174
+ */
175
+ errorOnClickSelectorNotFound(errorOn: boolean): TakeOptions;
176
+ /**
177
+ * Controls whether a missing hover selector causes an error.
178
+ */
179
+ errorOnHoverSelectorNotFound(errorOn: boolean): TakeOptions;
143
180
  /**
144
181
  * Renders the full page.
145
182
  */
@@ -160,6 +197,22 @@ export declare class TakeOptions {
160
197
  * Sets the delay between scroll steps.
161
198
  */
162
199
  fullPageScrollDelay(delay: number): TakeOptions;
200
+ /**
201
+ * Sets the number of pixels used for each full-page scroll step.
202
+ */
203
+ fullPageScrollBy(pixels: number): TakeOptions;
204
+ /**
205
+ * Splits a full-page screenshot into smaller vertical image slices.
206
+ */
207
+ fullPageSlices(enabled: boolean): TakeOptions;
208
+ /**
209
+ * Sets the maximum height in pixels of each full-page slice.
210
+ */
211
+ fullPageSliceHeight(height: number): TakeOptions;
212
+ /**
213
+ * Sets the vertical overlap in pixels between adjacent full-page slices.
214
+ */
215
+ fullPageSliceOverlapHeight(height: number): TakeOptions;
163
216
  /**
164
217
  * Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
165
218
  */
@@ -190,6 +243,10 @@ export declare class TakeOptions {
190
243
  * Sets IP country code.
191
244
  */
192
245
  ipCountryCode(countryCode: string): TakeOptions;
246
+ /**
247
+ * Sets the ScreenshotOne server region used for the request.
248
+ */
249
+ serversRegion(region: string): TakeOptions;
193
250
  /**
194
251
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
195
252
  */
@@ -275,6 +332,10 @@ export declare class TakeOptions {
275
332
  * Blocks chats.
276
333
  */
277
334
  blockChats(block: boolean): TakeOptions;
335
+ /**
336
+ * Blocks social widgets.
337
+ */
338
+ blockSocials(block: boolean): TakeOptions;
278
339
  /**
279
340
  * Blocks trackers.
280
341
  */
@@ -325,6 +386,10 @@ export declare class TakeOptions {
325
386
  * The https, http, socks4 and socks5 proxies are supported.
326
387
  */
327
388
  proxy(proxy: string): TakeOptions;
389
+ /**
390
+ * Bypasses the proxy for requests to matching hostname patterns.
391
+ */
392
+ proxyBypassHosts(...hosts: string[]): TakeOptions;
328
393
  /**
329
394
  * Set cookies for the request.
330
395
  */
@@ -407,6 +472,34 @@ export declare class TakeOptions {
407
472
  * Sets whether to fit PDF to one page.
408
473
  */
409
474
  pdfFitOnePage(fit: boolean): TakeOptions;
475
+ /**
476
+ * Sets whether to render a PDF in landscape orientation.
477
+ */
478
+ pdfLandscape(landscape: boolean): TakeOptions;
479
+ /**
480
+ * Sets the paper format for a PDF.
481
+ */
482
+ pdfPaperFormat(format: string): TakeOptions;
483
+ /**
484
+ * Sets the margin for all sides of a PDF.
485
+ */
486
+ pdfMargin(margin: string): TakeOptions;
487
+ /**
488
+ * Sets the top margin of a PDF.
489
+ */
490
+ pdfMarginTop(margin: string): TakeOptions;
491
+ /**
492
+ * Sets the right margin of a PDF.
493
+ */
494
+ pdfMarginRight(margin: string): TakeOptions;
495
+ /**
496
+ * Sets the bottom margin of a PDF.
497
+ */
498
+ pdfMarginBottom(margin: string): TakeOptions;
499
+ /**
500
+ * Sets the left margin of a PDF.
501
+ */
502
+ pdfMarginLeft(margin: string): TakeOptions;
410
503
  /**
411
504
  * Sets the OpenAI API key for vision integration.
412
505
  */
@@ -427,6 +520,11 @@ export declare class TakeOptions {
427
520
  * Sets whether to wait for a specific selector.
428
521
  */
429
522
  waitForSelector(selector: string): TakeOptions;
523
+ /**
524
+ * Sets how matching selectors are counted while waiting for a selector.
525
+ * Available values are `at_least_one` and `at_least_by_count`.
526
+ */
527
+ waitForSelectorAlgorithm(algorithm: string): TakeOptions;
430
528
  /**
431
529
  * Sets whether to return the storage location.
432
530
  */
@@ -439,6 +537,10 @@ export declare class TakeOptions {
439
537
  * Sets whether to include fonts metadata.
440
538
  */
441
539
  metadataFonts(include: boolean): TakeOptions;
540
+ /**
541
+ * Sets whether to include favicon metadata.
542
+ */
543
+ metadataIcon(include: boolean): TakeOptions;
442
544
  /**
443
545
  * Sets whether to include Open Graph metadata.
444
546
  */
@@ -451,6 +553,10 @@ export declare class TakeOptions {
451
553
  * Sets whether to include content metadata.
452
554
  */
453
555
  metadataContent(include: boolean): TakeOptions;
556
+ /**
557
+ * Sets the extracted page content format to `html` or `markdown`.
558
+ */
559
+ metadataContentFormat(format: string): TakeOptions;
454
560
  /**
455
561
  * Sets whether to include HTTP response status code metadata.
456
562
  */
@@ -471,10 +577,25 @@ export declare class TakeOptions {
471
577
  * Sets whether to sign the webhook request.
472
578
  */
473
579
  webhookSign(sign: boolean): TakeOptions;
580
+ /**
581
+ * Sets whether webhook responses include rendering error details.
582
+ */
583
+ webhookErrors(include: boolean): TakeOptions;
474
584
  /**
475
585
  * Sets the text to check for in the content to force request failure.
586
+ * The option can be specified multiple times.
587
+ */
588
+ failIfContentContains(...texts: string[]): TakeOptions;
589
+ /**
590
+ * Sets text that must be present in the page content.
591
+ * The option can be specified multiple times.
476
592
  */
477
- failIfContentContains(text: string): TakeOptions;
593
+ failIfContentMissing(...texts: string[]): TakeOptions;
594
+ /**
595
+ * Sets request URL patterns whose failure should fail the rendering request.
596
+ * The option can be specified multiple times.
597
+ */
598
+ failIfRequestFailed(...patterns: string[]): TakeOptions;
478
599
  /**
479
600
  * Sets whether to fail if GPU rendering fails.
480
601
  */
@@ -553,6 +674,10 @@ export declare class AnimateOptions {
553
674
  * The https, http, socks4 and socks5 proxies are supported.
554
675
  */
555
676
  proxy(proxy: string): AnimateOptions;
677
+ /**
678
+ * Bypasses the proxy for requests to matching hostname patterns.
679
+ */
680
+ proxyBypassHosts(...hosts: string[]): AnimateOptions;
556
681
  /**
557
682
  * Scripts specifies custom scripts for the page.
558
683
  */
package/dist/main.js CHANGED
@@ -201,6 +201,21 @@ class TakeOptions {
201
201
  this.put("selector", selector);
202
202
  return this;
203
203
  }
204
+ /**
205
+ * Sets the algorithm used to capture an element selected with `selector`.
206
+ * Available values are `default` and `clip`.
207
+ */
208
+ selectorAlgorithm(algorithm) {
209
+ this.put("selector_algorithm", algorithm);
210
+ return this;
211
+ }
212
+ /**
213
+ * Controls whether the selected element is scrolled into view before capture.
214
+ */
215
+ selectorScrollIntoView(scroll) {
216
+ this.put("selector_scroll_into_view", scroll ? "true" : "false");
217
+ return this;
218
+ }
204
219
  /**
205
220
  * Available response types:
206
221
  * by_format — return exactly the response defined in the format option. If format=png, the response will be the binary representation of the png with the content type header image/png;
@@ -226,6 +241,27 @@ class TakeOptions {
226
241
  this.put("capture_beyond_viewport", beyond ? "true" : "false");
227
242
  return this;
228
243
  }
244
+ /**
245
+ * Includes open and closed shadow DOM roots when extracting page content.
246
+ */
247
+ includeShadowDom(include) {
248
+ this.put("include_shadow_dom", include ? "true" : "false");
249
+ return this;
250
+ }
251
+ /**
252
+ * Sets the attachment name. The response format is added as the suffix.
253
+ */
254
+ attachmentName(name) {
255
+ this.put("attachment_name", name);
256
+ return this;
257
+ }
258
+ /**
259
+ * Sets an alphanumeric identifier returned with webhook requests.
260
+ */
261
+ externalIdentifier(identifier) {
262
+ this.put("external_identifier", identifier);
263
+ return this;
264
+ }
229
265
  /**
230
266
  * When reduced_motion set to `true`,
231
267
  * the API will request the site to minimize the amount of non-essential motion it uses.
@@ -290,6 +326,34 @@ class TakeOptions {
290
326
  this.put("scripts", scripts);
291
327
  return this;
292
328
  }
329
+ /**
330
+ * Sets a selector for an element to click before taking the screenshot.
331
+ */
332
+ click(selector) {
333
+ this.put("click", selector);
334
+ return this;
335
+ }
336
+ /**
337
+ * Sets a selector for an element to hover over before taking the screenshot.
338
+ */
339
+ hover(selector) {
340
+ this.put("hover", selector);
341
+ return this;
342
+ }
343
+ /**
344
+ * Controls whether a missing click selector causes an error.
345
+ */
346
+ errorOnClickSelectorNotFound(errorOn) {
347
+ this.put("error_on_click_selector_not_found", errorOn ? "true" : "false");
348
+ return this;
349
+ }
350
+ /**
351
+ * Controls whether a missing hover selector causes an error.
352
+ */
353
+ errorOnHoverSelectorNotFound(errorOn) {
354
+ this.put("error_on_hover_selector_not_found", errorOn ? "true" : "false");
355
+ return this;
356
+ }
293
357
  /**
294
358
  * Renders the full page.
295
359
  */
@@ -325,6 +389,34 @@ class TakeOptions {
325
389
  this.put("full_page_scroll_delay", delay.toString());
326
390
  return this;
327
391
  }
392
+ /**
393
+ * Sets the number of pixels used for each full-page scroll step.
394
+ */
395
+ fullPageScrollBy(pixels) {
396
+ this.put("full_page_scroll_by", pixels.toString());
397
+ return this;
398
+ }
399
+ /**
400
+ * Splits a full-page screenshot into smaller vertical image slices.
401
+ */
402
+ fullPageSlices(enabled) {
403
+ this.put("full_page_slices", enabled ? "true" : "false");
404
+ return this;
405
+ }
406
+ /**
407
+ * Sets the maximum height in pixels of each full-page slice.
408
+ */
409
+ fullPageSliceHeight(height) {
410
+ this.put("full_page_slice_height", height.toString());
411
+ return this;
412
+ }
413
+ /**
414
+ * Sets the vertical overlap in pixels between adjacent full-page slices.
415
+ */
416
+ fullPageSliceOverlapHeight(height) {
417
+ this.put("full_page_slice_overlap_height", height.toString());
418
+ return this;
419
+ }
328
420
  /**
329
421
  * Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
330
422
  */
@@ -367,6 +459,13 @@ class TakeOptions {
367
459
  this.put("ip_country_code", countryCode);
368
460
  return this;
369
461
  }
462
+ /**
463
+ * Sets the ScreenshotOne server region used for the request.
464
+ */
465
+ serversRegion(region) {
466
+ this.put("servers_region", region);
467
+ return this;
468
+ }
370
469
  /**
371
470
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
372
471
  */
@@ -512,6 +611,13 @@ class TakeOptions {
512
611
  this.put("block_chats", block ? "true" : "false");
513
612
  return this;
514
613
  }
614
+ /**
615
+ * Blocks social widgets.
616
+ */
617
+ blockSocials(block) {
618
+ this.put("block_socials", block ? "true" : "false");
619
+ return this;
620
+ }
515
621
  /**
516
622
  * Blocks trackers.
517
623
  */
@@ -595,6 +701,13 @@ class TakeOptions {
595
701
  this.put("proxy", proxy);
596
702
  return this;
597
703
  }
704
+ /**
705
+ * Bypasses the proxy for requests to matching hostname patterns.
706
+ */
707
+ proxyBypassHosts(...hosts) {
708
+ this.put("proxy_bypass_hosts", ...hosts);
709
+ return this;
710
+ }
598
711
  /**
599
712
  * Set cookies for the request.
600
713
  */
@@ -734,6 +847,55 @@ class TakeOptions {
734
847
  this.put("pdf_fit_one_page", fit ? "true" : "false");
735
848
  return this;
736
849
  }
850
+ /**
851
+ * Sets whether to render a PDF in landscape orientation.
852
+ */
853
+ pdfLandscape(landscape) {
854
+ this.put("pdf_landscape", landscape ? "true" : "false");
855
+ return this;
856
+ }
857
+ /**
858
+ * Sets the paper format for a PDF.
859
+ */
860
+ pdfPaperFormat(format) {
861
+ this.put("pdf_paper_format", format);
862
+ return this;
863
+ }
864
+ /**
865
+ * Sets the margin for all sides of a PDF.
866
+ */
867
+ pdfMargin(margin) {
868
+ this.put("pdf_margin", margin);
869
+ return this;
870
+ }
871
+ /**
872
+ * Sets the top margin of a PDF.
873
+ */
874
+ pdfMarginTop(margin) {
875
+ this.put("pdf_margin_top", margin);
876
+ return this;
877
+ }
878
+ /**
879
+ * Sets the right margin of a PDF.
880
+ */
881
+ pdfMarginRight(margin) {
882
+ this.put("pdf_margin_right", margin);
883
+ return this;
884
+ }
885
+ /**
886
+ * Sets the bottom margin of a PDF.
887
+ */
888
+ pdfMarginBottom(margin) {
889
+ this.put("pdf_margin_bottom", margin);
890
+ return this;
891
+ }
892
+ /**
893
+ * Sets the left margin of a PDF.
894
+ */
895
+ pdfMarginLeft(margin) {
896
+ this.put("pdf_margin_left", margin);
897
+ return this;
898
+ }
737
899
  /**
738
900
  * Sets the OpenAI API key for vision integration.
739
901
  */
@@ -769,6 +931,14 @@ class TakeOptions {
769
931
  this.put("wait_for_selector", selector);
770
932
  return this;
771
933
  }
934
+ /**
935
+ * Sets how matching selectors are counted while waiting for a selector.
936
+ * Available values are `at_least_one` and `at_least_by_count`.
937
+ */
938
+ waitForSelectorAlgorithm(algorithm) {
939
+ this.put("wait_for_selector_algorithm", algorithm);
940
+ return this;
941
+ }
772
942
  /**
773
943
  * Sets whether to return the storage location.
774
944
  */
@@ -790,6 +960,13 @@ class TakeOptions {
790
960
  this.put("metadata_fonts", include ? "true" : "false");
791
961
  return this;
792
962
  }
963
+ /**
964
+ * Sets whether to include favicon metadata.
965
+ */
966
+ metadataIcon(include) {
967
+ this.put("metadata_icon", include ? "true" : "false");
968
+ return this;
969
+ }
793
970
  /**
794
971
  * Sets whether to include Open Graph metadata.
795
972
  */
@@ -811,6 +988,13 @@ class TakeOptions {
811
988
  this.put("metadata_content", include ? "true" : "false");
812
989
  return this;
813
990
  }
991
+ /**
992
+ * Sets the extracted page content format to `html` or `markdown`.
993
+ */
994
+ metadataContentFormat(format) {
995
+ this.put("metadata_content_format", format);
996
+ return this;
997
+ }
814
998
  /**
815
999
  * Sets whether to include HTTP response status code metadata.
816
1000
  */
@@ -846,11 +1030,35 @@ class TakeOptions {
846
1030
  this.put("webhook_sign", sign ? "true" : "false");
847
1031
  return this;
848
1032
  }
1033
+ /**
1034
+ * Sets whether webhook responses include rendering error details.
1035
+ */
1036
+ webhookErrors(include) {
1037
+ this.put("webhook_errors", include ? "true" : "false");
1038
+ return this;
1039
+ }
849
1040
  /**
850
1041
  * Sets the text to check for in the content to force request failure.
1042
+ * The option can be specified multiple times.
851
1043
  */
852
- failIfContentContains(text) {
853
- this.put("fail_if_content_contains", text);
1044
+ failIfContentContains(...texts) {
1045
+ this.put("fail_if_content_contains", ...texts);
1046
+ return this;
1047
+ }
1048
+ /**
1049
+ * Sets text that must be present in the page content.
1050
+ * The option can be specified multiple times.
1051
+ */
1052
+ failIfContentMissing(...texts) {
1053
+ this.put("fail_if_content_missing", ...texts);
1054
+ return this;
1055
+ }
1056
+ /**
1057
+ * Sets request URL patterns whose failure should fail the rendering request.
1058
+ * The option can be specified multiple times.
1059
+ */
1060
+ failIfRequestFailed(...patterns) {
1061
+ this.put("fail_if_request_failed", ...patterns);
854
1062
  return this;
855
1063
  }
856
1064
  /**
@@ -984,6 +1192,13 @@ class AnimateOptions {
984
1192
  this.put("proxy", proxy);
985
1193
  return this;
986
1194
  }
1195
+ /**
1196
+ * Bypasses the proxy for requests to matching hostname patterns.
1197
+ */
1198
+ proxyBypassHosts(...hosts) {
1199
+ this.put("proxy_bypass_hosts", ...hosts);
1200
+ return this;
1201
+ }
987
1202
  /**
988
1203
  * Scripts specifies custom scripts for the page.
989
1204
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "screenshotone-api-sdk",
3
3
  "homepage": "https://screenshotone.com",
4
- "version": "1.1.21",
4
+ "version": "1.1.22",
5
5
  "description": "Use ScreenshotOne.com API to generate screenshots of any website.",
6
6
  "repository": {
7
7
  "type": "git",
@@ -47,4 +47,4 @@
47
47
  "build": "tsc",
48
48
  "prepare": "npm run build"
49
49
  }
50
- }
50
+ }
package/src/main.ts CHANGED
@@ -268,6 +268,25 @@ export class TakeOptions {
268
268
  return this;
269
269
  }
270
270
 
271
+ /**
272
+ * Sets the algorithm used to capture an element selected with `selector`.
273
+ * Available values are `default` and `clip`.
274
+ */
275
+ selectorAlgorithm(algorithm: string): TakeOptions {
276
+ this.put("selector_algorithm", algorithm);
277
+
278
+ return this;
279
+ }
280
+
281
+ /**
282
+ * Controls whether the selected element is scrolled into view before capture.
283
+ */
284
+ selectorScrollIntoView(scroll: boolean): TakeOptions {
285
+ this.put("selector_scroll_into_view", scroll ? "true" : "false");
286
+
287
+ return this;
288
+ }
289
+
271
290
  /**
272
291
  * Available response types:
273
292
  * by_format — return exactly the response defined in the format option. If format=png, the response will be the binary representation of the png with the content type header image/png;
@@ -299,6 +318,33 @@ export class TakeOptions {
299
318
  return this;
300
319
  }
301
320
 
321
+ /**
322
+ * Includes open and closed shadow DOM roots when extracting page content.
323
+ */
324
+ includeShadowDom(include: boolean): TakeOptions {
325
+ this.put("include_shadow_dom", include ? "true" : "false");
326
+
327
+ return this;
328
+ }
329
+
330
+ /**
331
+ * Sets the attachment name. The response format is added as the suffix.
332
+ */
333
+ attachmentName(name: string): TakeOptions {
334
+ this.put("attachment_name", name);
335
+
336
+ return this;
337
+ }
338
+
339
+ /**
340
+ * Sets an alphanumeric identifier returned with webhook requests.
341
+ */
342
+ externalIdentifier(identifier: string): TakeOptions {
343
+ this.put("external_identifier", identifier);
344
+
345
+ return this;
346
+ }
347
+
302
348
  /**
303
349
  * When reduced_motion set to `true`,
304
350
  * the API will request the site to minimize the amount of non-essential motion it uses.
@@ -377,6 +423,48 @@ export class TakeOptions {
377
423
  return this;
378
424
  }
379
425
 
426
+ /**
427
+ * Sets a selector for an element to click before taking the screenshot.
428
+ */
429
+ click(selector: string): TakeOptions {
430
+ this.put("click", selector);
431
+
432
+ return this;
433
+ }
434
+
435
+ /**
436
+ * Sets a selector for an element to hover over before taking the screenshot.
437
+ */
438
+ hover(selector: string): TakeOptions {
439
+ this.put("hover", selector);
440
+
441
+ return this;
442
+ }
443
+
444
+ /**
445
+ * Controls whether a missing click selector causes an error.
446
+ */
447
+ errorOnClickSelectorNotFound(errorOn: boolean): TakeOptions {
448
+ this.put(
449
+ "error_on_click_selector_not_found",
450
+ errorOn ? "true" : "false"
451
+ );
452
+
453
+ return this;
454
+ }
455
+
456
+ /**
457
+ * Controls whether a missing hover selector causes an error.
458
+ */
459
+ errorOnHoverSelectorNotFound(errorOn: boolean): TakeOptions {
460
+ this.put(
461
+ "error_on_hover_selector_not_found",
462
+ errorOn ? "true" : "false"
463
+ );
464
+
465
+ return this;
466
+ }
467
+
380
468
  /**
381
469
  * Renders the full page.
382
470
  */
@@ -422,6 +510,42 @@ export class TakeOptions {
422
510
  return this;
423
511
  }
424
512
 
513
+ /**
514
+ * Sets the number of pixels used for each full-page scroll step.
515
+ */
516
+ fullPageScrollBy(pixels: number): TakeOptions {
517
+ this.put("full_page_scroll_by", pixels.toString());
518
+
519
+ return this;
520
+ }
521
+
522
+ /**
523
+ * Splits a full-page screenshot into smaller vertical image slices.
524
+ */
525
+ fullPageSlices(enabled: boolean): TakeOptions {
526
+ this.put("full_page_slices", enabled ? "true" : "false");
527
+
528
+ return this;
529
+ }
530
+
531
+ /**
532
+ * Sets the maximum height in pixels of each full-page slice.
533
+ */
534
+ fullPageSliceHeight(height: number): TakeOptions {
535
+ this.put("full_page_slice_height", height.toString());
536
+
537
+ return this;
538
+ }
539
+
540
+ /**
541
+ * Sets the vertical overlap in pixels between adjacent full-page slices.
542
+ */
543
+ fullPageSliceOverlapHeight(height: number): TakeOptions {
544
+ this.put("full_page_slice_overlap_height", height.toString());
545
+
546
+ return this;
547
+ }
548
+
425
549
  /**
426
550
  * Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
427
551
  */
@@ -472,6 +596,15 @@ export class TakeOptions {
472
596
  return this;
473
597
  }
474
598
 
599
+ /**
600
+ * Sets the ScreenshotOne server region used for the request.
601
+ */
602
+ serversRegion(region: string): TakeOptions {
603
+ this.put("servers_region", region);
604
+
605
+ return this;
606
+ }
607
+
475
608
  /**
476
609
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
477
610
  */
@@ -663,6 +796,15 @@ export class TakeOptions {
663
796
  return this;
664
797
  }
665
798
 
799
+ /**
800
+ * Blocks social widgets.
801
+ */
802
+ blockSocials(block: boolean): TakeOptions {
803
+ this.put("block_socials", block ? "true" : "false");
804
+
805
+ return this;
806
+ }
807
+
666
808
  /**
667
809
  * Blocks trackers.
668
810
  */
@@ -768,6 +910,15 @@ export class TakeOptions {
768
910
  return this;
769
911
  }
770
912
 
913
+ /**
914
+ * Bypasses the proxy for requests to matching hostname patterns.
915
+ */
916
+ proxyBypassHosts(...hosts: string[]): TakeOptions {
917
+ this.put("proxy_bypass_hosts", ...hosts);
918
+
919
+ return this;
920
+ }
921
+
771
922
  /**
772
923
  * Set cookies for the request.
773
924
  */
@@ -945,6 +1096,69 @@ export class TakeOptions {
945
1096
  return this;
946
1097
  }
947
1098
 
1099
+ /**
1100
+ * Sets whether to render a PDF in landscape orientation.
1101
+ */
1102
+ pdfLandscape(landscape: boolean): TakeOptions {
1103
+ this.put("pdf_landscape", landscape ? "true" : "false");
1104
+
1105
+ return this;
1106
+ }
1107
+
1108
+ /**
1109
+ * Sets the paper format for a PDF.
1110
+ */
1111
+ pdfPaperFormat(format: string): TakeOptions {
1112
+ this.put("pdf_paper_format", format);
1113
+
1114
+ return this;
1115
+ }
1116
+
1117
+ /**
1118
+ * Sets the margin for all sides of a PDF.
1119
+ */
1120
+ pdfMargin(margin: string): TakeOptions {
1121
+ this.put("pdf_margin", margin);
1122
+
1123
+ return this;
1124
+ }
1125
+
1126
+ /**
1127
+ * Sets the top margin of a PDF.
1128
+ */
1129
+ pdfMarginTop(margin: string): TakeOptions {
1130
+ this.put("pdf_margin_top", margin);
1131
+
1132
+ return this;
1133
+ }
1134
+
1135
+ /**
1136
+ * Sets the right margin of a PDF.
1137
+ */
1138
+ pdfMarginRight(margin: string): TakeOptions {
1139
+ this.put("pdf_margin_right", margin);
1140
+
1141
+ return this;
1142
+ }
1143
+
1144
+ /**
1145
+ * Sets the bottom margin of a PDF.
1146
+ */
1147
+ pdfMarginBottom(margin: string): TakeOptions {
1148
+ this.put("pdf_margin_bottom", margin);
1149
+
1150
+ return this;
1151
+ }
1152
+
1153
+ /**
1154
+ * Sets the left margin of a PDF.
1155
+ */
1156
+ pdfMarginLeft(margin: string): TakeOptions {
1157
+ this.put("pdf_margin_left", margin);
1158
+
1159
+ return this;
1160
+ }
1161
+
948
1162
  /**
949
1163
  * Sets the OpenAI API key for vision integration.
950
1164
  */
@@ -990,6 +1204,16 @@ export class TakeOptions {
990
1204
  return this;
991
1205
  }
992
1206
 
1207
+ /**
1208
+ * Sets how matching selectors are counted while waiting for a selector.
1209
+ * Available values are `at_least_one` and `at_least_by_count`.
1210
+ */
1211
+ waitForSelectorAlgorithm(algorithm: string): TakeOptions {
1212
+ this.put("wait_for_selector_algorithm", algorithm);
1213
+
1214
+ return this;
1215
+ }
1216
+
993
1217
  /**
994
1218
  * Sets whether to return the storage location.
995
1219
  */
@@ -1017,6 +1241,15 @@ export class TakeOptions {
1017
1241
  return this;
1018
1242
  }
1019
1243
 
1244
+ /**
1245
+ * Sets whether to include favicon metadata.
1246
+ */
1247
+ metadataIcon(include: boolean): TakeOptions {
1248
+ this.put("metadata_icon", include ? "true" : "false");
1249
+
1250
+ return this;
1251
+ }
1252
+
1020
1253
  /**
1021
1254
  * Sets whether to include Open Graph metadata.
1022
1255
  */
@@ -1044,6 +1277,15 @@ export class TakeOptions {
1044
1277
  return this;
1045
1278
  }
1046
1279
 
1280
+ /**
1281
+ * Sets the extracted page content format to `html` or `markdown`.
1282
+ */
1283
+ metadataContentFormat(format: string): TakeOptions {
1284
+ this.put("metadata_content_format", format);
1285
+
1286
+ return this;
1287
+ }
1288
+
1047
1289
  /**
1048
1290
  * Sets whether to include HTTP response status code metadata.
1049
1291
  */
@@ -1092,11 +1334,41 @@ export class TakeOptions {
1092
1334
  return this;
1093
1335
  }
1094
1336
 
1337
+ /**
1338
+ * Sets whether webhook responses include rendering error details.
1339
+ */
1340
+ webhookErrors(include: boolean): TakeOptions {
1341
+ this.put("webhook_errors", include ? "true" : "false");
1342
+
1343
+ return this;
1344
+ }
1345
+
1095
1346
  /**
1096
1347
  * Sets the text to check for in the content to force request failure.
1348
+ * The option can be specified multiple times.
1097
1349
  */
1098
- failIfContentContains(text: string): TakeOptions {
1099
- this.put("fail_if_content_contains", text);
1350
+ failIfContentContains(...texts: string[]): TakeOptions {
1351
+ this.put("fail_if_content_contains", ...texts);
1352
+
1353
+ return this;
1354
+ }
1355
+
1356
+ /**
1357
+ * Sets text that must be present in the page content.
1358
+ * The option can be specified multiple times.
1359
+ */
1360
+ failIfContentMissing(...texts: string[]): TakeOptions {
1361
+ this.put("fail_if_content_missing", ...texts);
1362
+
1363
+ return this;
1364
+ }
1365
+
1366
+ /**
1367
+ * Sets request URL patterns whose failure should fail the rendering request.
1368
+ * The option can be specified multiple times.
1369
+ */
1370
+ failIfRequestFailed(...patterns: string[]): TakeOptions {
1371
+ this.put("fail_if_request_failed", ...patterns);
1100
1372
 
1101
1373
  return this;
1102
1374
  }
@@ -1260,6 +1532,15 @@ export class AnimateOptions {
1260
1532
  return this;
1261
1533
  }
1262
1534
 
1535
+ /**
1536
+ * Bypasses the proxy for requests to matching hostname patterns.
1537
+ */
1538
+ proxyBypassHosts(...hosts: string[]): AnimateOptions {
1539
+ this.put("proxy_bypass_hosts", ...hosts);
1540
+
1541
+ return this;
1542
+ }
1543
+
1263
1544
  /**
1264
1545
  * Scripts specifies custom scripts for the page.
1265
1546
  */
@@ -1,5 +1,10 @@
1
1
  import APIError from "../src/errors";
2
2
  import { TakeOptions, Client, AnimateOptions } from "../src/main";
3
+ import fetch from "cross-fetch";
4
+
5
+ jest.mock("cross-fetch");
6
+
7
+ const mockedFetch = fetch as jest.MockedFunction<typeof fetch>;
3
8
 
4
9
  describe("testing client", () => {
5
10
  const client = new Client("RcLsdM6uhIN6gw", "MW2vfkkgLTzGGw");
@@ -54,22 +59,106 @@ describe("testing client", () => {
54
59
  expect(options.toQuery().getAll("block_ads").length).toBe(1);
55
60
  });
56
61
 
62
+ test("serializes the latest take options", () => {
63
+ const options = TakeOptions.url("https://example.com")
64
+ .selectorAlgorithm("clip")
65
+ .selectorScrollIntoView(false)
66
+ .includeShadowDom(true)
67
+ .attachmentName("capture")
68
+ .externalIdentifier("capture123")
69
+ .click("#accept")
70
+ .hover(".menu")
71
+ .errorOnClickSelectorNotFound(false)
72
+ .errorOnHoverSelectorNotFound(true)
73
+ .fullPageScrollBy(400)
74
+ .fullPageSlices(true)
75
+ .fullPageSliceHeight(3000)
76
+ .fullPageSliceOverlapHeight(500)
77
+ .serversRegion("us-east")
78
+ .blockSocials(true)
79
+ .proxy("http://proxy.example.com")
80
+ .proxyBypassHosts(
81
+ "cdn.example.com",
82
+ "cdn.*.screenshotone.com"
83
+ )
84
+ .pdfLandscape(true)
85
+ .pdfPaperFormat("a4")
86
+ .pdfMargin("10mm")
87
+ .pdfMarginTop("20mm")
88
+ .pdfMarginRight("15mm")
89
+ .pdfMarginBottom("20mm")
90
+ .pdfMarginLeft("15mm")
91
+ .waitForSelectorAlgorithm("at_least_by_count")
92
+ .metadataIcon(true)
93
+ .metadataContentFormat("markdown")
94
+ .webhookErrors(true)
95
+ .failIfContentContains("Error", "Blocked")
96
+ .failIfContentMissing("Ready", "Loaded")
97
+ .failIfRequestFailed(
98
+ "*api.example.com*",
99
+ "*cdn.example.com*"
100
+ );
101
+
102
+ const expected: Record<string, string[]> = {
103
+ selector_algorithm: ["clip"],
104
+ selector_scroll_into_view: ["false"],
105
+ include_shadow_dom: ["true"],
106
+ attachment_name: ["capture"],
107
+ external_identifier: ["capture123"],
108
+ click: ["#accept"],
109
+ hover: [".menu"],
110
+ error_on_click_selector_not_found: ["false"],
111
+ error_on_hover_selector_not_found: ["true"],
112
+ full_page_scroll_by: ["400"],
113
+ full_page_slices: ["true"],
114
+ full_page_slice_height: ["3000"],
115
+ full_page_slice_overlap_height: ["500"],
116
+ servers_region: ["us-east"],
117
+ block_socials: ["true"],
118
+ proxy: ["http://proxy.example.com"],
119
+ proxy_bypass_hosts: [
120
+ "cdn.example.com",
121
+ "cdn.*.screenshotone.com",
122
+ ],
123
+ pdf_landscape: ["true"],
124
+ pdf_paper_format: ["a4"],
125
+ pdf_margin: ["10mm"],
126
+ pdf_margin_top: ["20mm"],
127
+ pdf_margin_right: ["15mm"],
128
+ pdf_margin_bottom: ["20mm"],
129
+ pdf_margin_left: ["15mm"],
130
+ wait_for_selector_algorithm: ["at_least_by_count"],
131
+ metadata_icon: ["true"],
132
+ metadata_content_format: ["markdown"],
133
+ webhook_errors: ["true"],
134
+ fail_if_content_contains: ["Error", "Blocked"],
135
+ fail_if_content_missing: ["Ready", "Loaded"],
136
+ fail_if_request_failed: [
137
+ "*api.example.com*",
138
+ "*cdn.example.com*",
139
+ ],
140
+ };
141
+ const query = options.toQuery();
142
+
143
+ for (const [key, values] of Object.entries(expected)) {
144
+ expect(query.getAll(key)).toEqual(values);
145
+ }
146
+ });
147
+
57
148
  test("returning an API error when the response is not successful", async () => {
58
- jest.mock('cross-fetch', () => ({
59
- __esModule: true,
60
- default: jest.fn().mockImplementationOnce(() =>
149
+ mockedFetch.mockResolvedValueOnce({
150
+ ok: false,
151
+ status: 400,
152
+ statusText: "Bad Request",
153
+ json: () =>
61
154
  Promise.resolve({
62
- ok: false,
63
- status: 400,
64
- statusText: "Bad Request",
65
- json: () => Promise.resolve({
66
- error_code: "name_not_resolved",
67
- error_message: "Usually, the error happens when the domain name of the requested URL is not resolved. If you are trying to take a screenshot of the new site, please, wait a bit until the DNS records are refreshed.",
68
- documentation_url: "https://screenshotone.com/docs/errors/"
69
- })
70
- })
71
- )
72
- }));
155
+ error_code: "name_not_resolved",
156
+ error_message:
157
+ "Usually, the error happens when the domain name of the requested URL is not resolved. If you are trying to take a screenshot of the new site, please, wait a bit until the DNS records are refreshed.",
158
+ documentation_url:
159
+ "https://screenshotone.com/docs/errors/",
160
+ }),
161
+ } as any);
73
162
 
74
163
  const options = AnimateOptions.url("https://example.com");
75
164
  await expect(client.animate(options)).rejects.toThrow(APIError);