screenshotone-api-sdk 1.1.21 → 1.1.23

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;
@@ -98,9 +107,27 @@ export declare class TakeOptions {
98
107
  */
99
108
  captureBeyondViewport(beyond: boolean): TakeOptions;
100
109
  /**
101
- * When reduced_motion set to `true`,
102
- * the API will request the site to minimize the amount of non-essential motion it uses.
103
- * When the site supports it, it should use animations as least as possible.
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;
121
+ /**
122
+ * Actively reduces supported motion by finishing animations and pausing media and sliders.
123
+ * Also enables the reduced-motion preference. The API default is false.
124
+ * Unlike reducedMotion(), this does not rely only on the website honoring that preference.
125
+ */
126
+ reduceMotion(reduceMotion: boolean): TakeOptions;
127
+ /**
128
+ * Requests reduced motion through the prefers-reduced-motion preference.
129
+ * Websites may ignore this preference; it does not actively freeze motion.
130
+ * Use reduceMotion(true) to actively reduce motion and enable this preference.
104
131
  */
105
132
  reducedMotion(reducedMotion: boolean): TakeOptions;
106
133
  /**
@@ -140,6 +167,22 @@ export declare class TakeOptions {
140
167
  * Scripts specifies custom scripts for the page.
141
168
  */
142
169
  scripts(scripts: string): TakeOptions;
170
+ /**
171
+ * Sets a selector for an element to click before taking the screenshot.
172
+ */
173
+ click(selector: string): TakeOptions;
174
+ /**
175
+ * Sets a selector for an element to hover over before taking the screenshot.
176
+ */
177
+ hover(selector: string): TakeOptions;
178
+ /**
179
+ * Controls whether a missing click selector causes an error.
180
+ */
181
+ errorOnClickSelectorNotFound(errorOn: boolean): TakeOptions;
182
+ /**
183
+ * Controls whether a missing hover selector causes an error.
184
+ */
185
+ errorOnHoverSelectorNotFound(errorOn: boolean): TakeOptions;
143
186
  /**
144
187
  * Renders the full page.
145
188
  */
@@ -160,6 +203,22 @@ export declare class TakeOptions {
160
203
  * Sets the delay between scroll steps.
161
204
  */
162
205
  fullPageScrollDelay(delay: number): TakeOptions;
206
+ /**
207
+ * Sets the number of pixels used for each full-page scroll step.
208
+ */
209
+ fullPageScrollBy(pixels: number): TakeOptions;
210
+ /**
211
+ * Splits a full-page screenshot into smaller vertical image slices.
212
+ */
213
+ fullPageSlices(enabled: boolean): TakeOptions;
214
+ /**
215
+ * Sets the maximum height in pixels of each full-page slice.
216
+ */
217
+ fullPageSliceHeight(height: number): TakeOptions;
218
+ /**
219
+ * Sets the vertical overlap in pixels between adjacent full-page slices.
220
+ */
221
+ fullPageSliceOverlapHeight(height: number): TakeOptions;
163
222
  /**
164
223
  * Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
165
224
  */
@@ -190,6 +249,10 @@ export declare class TakeOptions {
190
249
  * Sets IP country code.
191
250
  */
192
251
  ipCountryCode(countryCode: string): TakeOptions;
252
+ /**
253
+ * Sets the ScreenshotOne server region used for the request.
254
+ */
255
+ serversRegion(region: string): TakeOptions;
193
256
  /**
194
257
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
195
258
  */
@@ -275,6 +338,10 @@ export declare class TakeOptions {
275
338
  * Blocks chats.
276
339
  */
277
340
  blockChats(block: boolean): TakeOptions;
341
+ /**
342
+ * Blocks social widgets.
343
+ */
344
+ blockSocials(block: boolean): TakeOptions;
278
345
  /**
279
346
  * Blocks trackers.
280
347
  */
@@ -325,6 +392,10 @@ export declare class TakeOptions {
325
392
  * The https, http, socks4 and socks5 proxies are supported.
326
393
  */
327
394
  proxy(proxy: string): TakeOptions;
395
+ /**
396
+ * Bypasses the proxy for requests to matching hostname patterns.
397
+ */
398
+ proxyBypassHosts(...hosts: string[]): TakeOptions;
328
399
  /**
329
400
  * Set cookies for the request.
330
401
  */
@@ -407,6 +478,34 @@ export declare class TakeOptions {
407
478
  * Sets whether to fit PDF to one page.
408
479
  */
409
480
  pdfFitOnePage(fit: boolean): TakeOptions;
481
+ /**
482
+ * Sets whether to render a PDF in landscape orientation.
483
+ */
484
+ pdfLandscape(landscape: boolean): TakeOptions;
485
+ /**
486
+ * Sets the paper format for a PDF.
487
+ */
488
+ pdfPaperFormat(format: string): TakeOptions;
489
+ /**
490
+ * Sets the margin for all sides of a PDF.
491
+ */
492
+ pdfMargin(margin: string): TakeOptions;
493
+ /**
494
+ * Sets the top margin of a PDF.
495
+ */
496
+ pdfMarginTop(margin: string): TakeOptions;
497
+ /**
498
+ * Sets the right margin of a PDF.
499
+ */
500
+ pdfMarginRight(margin: string): TakeOptions;
501
+ /**
502
+ * Sets the bottom margin of a PDF.
503
+ */
504
+ pdfMarginBottom(margin: string): TakeOptions;
505
+ /**
506
+ * Sets the left margin of a PDF.
507
+ */
508
+ pdfMarginLeft(margin: string): TakeOptions;
410
509
  /**
411
510
  * Sets the OpenAI API key for vision integration.
412
511
  */
@@ -427,6 +526,11 @@ export declare class TakeOptions {
427
526
  * Sets whether to wait for a specific selector.
428
527
  */
429
528
  waitForSelector(selector: string): TakeOptions;
529
+ /**
530
+ * Sets how matching selectors are counted while waiting for a selector.
531
+ * Available values are `at_least_one` and `at_least_by_count`.
532
+ */
533
+ waitForSelectorAlgorithm(algorithm: string): TakeOptions;
430
534
  /**
431
535
  * Sets whether to return the storage location.
432
536
  */
@@ -439,6 +543,10 @@ export declare class TakeOptions {
439
543
  * Sets whether to include fonts metadata.
440
544
  */
441
545
  metadataFonts(include: boolean): TakeOptions;
546
+ /**
547
+ * Sets whether to include favicon metadata.
548
+ */
549
+ metadataIcon(include: boolean): TakeOptions;
442
550
  /**
443
551
  * Sets whether to include Open Graph metadata.
444
552
  */
@@ -451,6 +559,10 @@ export declare class TakeOptions {
451
559
  * Sets whether to include content metadata.
452
560
  */
453
561
  metadataContent(include: boolean): TakeOptions;
562
+ /**
563
+ * Sets the extracted page content format to `html` or `markdown`.
564
+ */
565
+ metadataContentFormat(format: string): TakeOptions;
454
566
  /**
455
567
  * Sets whether to include HTTP response status code metadata.
456
568
  */
@@ -471,10 +583,25 @@ export declare class TakeOptions {
471
583
  * Sets whether to sign the webhook request.
472
584
  */
473
585
  webhookSign(sign: boolean): TakeOptions;
586
+ /**
587
+ * Sets whether webhook responses include rendering error details.
588
+ */
589
+ webhookErrors(include: boolean): TakeOptions;
474
590
  /**
475
591
  * Sets the text to check for in the content to force request failure.
592
+ * The option can be specified multiple times.
476
593
  */
477
- failIfContentContains(text: string): TakeOptions;
594
+ failIfContentContains(...texts: string[]): TakeOptions;
595
+ /**
596
+ * Sets text that must be present in the page content.
597
+ * The option can be specified multiple times.
598
+ */
599
+ failIfContentMissing(...texts: string[]): TakeOptions;
600
+ /**
601
+ * Sets request URL patterns whose failure should fail the rendering request.
602
+ * The option can be specified multiple times.
603
+ */
604
+ failIfRequestFailed(...patterns: string[]): TakeOptions;
478
605
  /**
479
606
  * Sets whether to fail if GPU rendering fails.
480
607
  */
@@ -508,11 +635,17 @@ export declare class AnimateOptions {
508
635
  */
509
636
  responseType(responseType: string): this;
510
637
  /**
511
- * When reduced_motion set to `true`,
512
- * the API will request the site to minimize the amount of non-essential motion it uses.
513
- * When the site supports it, it should use animations as least as possible.
638
+ * Actively reduces supported page motion during recording by finishing animations
639
+ * and pausing media and sliders. Also enables the reduced-motion preference.
640
+ * The API default is false. Unlike reducedMotion(), this actively freezes motion.
514
641
  */
515
- reducedMotion(darkMode: boolean): AnimateOptions;
642
+ reduceMotion(reduceMotion: boolean): AnimateOptions;
643
+ /**
644
+ * Requests reduced motion through the prefers-reduced-motion preference.
645
+ * Websites may ignore this preference; it does not actively freeze motion.
646
+ * Use reduceMotion(true) to actively reduce motion and enable this preference.
647
+ */
648
+ reducedMotion(reducedMotion: boolean): AnimateOptions;
516
649
  /**
517
650
  * If you want to request the page and it is supported to be rendered for printers, specify `print`.
518
651
  * If the page is by default rendered for printers and you want it to be rendered for screens,
@@ -553,6 +686,10 @@ export declare class AnimateOptions {
553
686
  * The https, http, socks4 and socks5 proxies are supported.
554
687
  */
555
688
  proxy(proxy: string): AnimateOptions;
689
+ /**
690
+ * Bypasses the proxy for requests to matching hostname patterns.
691
+ */
692
+ proxyBypassHosts(...hosts: string[]): AnimateOptions;
556
693
  /**
557
694
  * Scripts specifies custom scripts for the page.
558
695
  */
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;
@@ -227,9 +242,39 @@ class TakeOptions {
227
242
  return this;
228
243
  }
229
244
  /**
230
- * When reduced_motion set to `true`,
231
- * the API will request the site to minimize the amount of non-essential motion it uses.
232
- * When the site supports it, it should use animations as least as possible.
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
+ }
265
+ /**
266
+ * Actively reduces supported motion by finishing animations and pausing media and sliders.
267
+ * Also enables the reduced-motion preference. The API default is false.
268
+ * Unlike reducedMotion(), this does not rely only on the website honoring that preference.
269
+ */
270
+ reduceMotion(reduceMotion) {
271
+ this.put("reduce_motion", reduceMotion ? "true" : "false");
272
+ return this;
273
+ }
274
+ /**
275
+ * Requests reduced motion through the prefers-reduced-motion preference.
276
+ * Websites may ignore this preference; it does not actively freeze motion.
277
+ * Use reduceMotion(true) to actively reduce motion and enable this preference.
233
278
  */
234
279
  reducedMotion(reducedMotion) {
235
280
  this.put("reduced_motion", reducedMotion ? "true" : "false");
@@ -290,6 +335,34 @@ class TakeOptions {
290
335
  this.put("scripts", scripts);
291
336
  return this;
292
337
  }
338
+ /**
339
+ * Sets a selector for an element to click before taking the screenshot.
340
+ */
341
+ click(selector) {
342
+ this.put("click", selector);
343
+ return this;
344
+ }
345
+ /**
346
+ * Sets a selector for an element to hover over before taking the screenshot.
347
+ */
348
+ hover(selector) {
349
+ this.put("hover", selector);
350
+ return this;
351
+ }
352
+ /**
353
+ * Controls whether a missing click selector causes an error.
354
+ */
355
+ errorOnClickSelectorNotFound(errorOn) {
356
+ this.put("error_on_click_selector_not_found", errorOn ? "true" : "false");
357
+ return this;
358
+ }
359
+ /**
360
+ * Controls whether a missing hover selector causes an error.
361
+ */
362
+ errorOnHoverSelectorNotFound(errorOn) {
363
+ this.put("error_on_hover_selector_not_found", errorOn ? "true" : "false");
364
+ return this;
365
+ }
293
366
  /**
294
367
  * Renders the full page.
295
368
  */
@@ -325,6 +398,34 @@ class TakeOptions {
325
398
  this.put("full_page_scroll_delay", delay.toString());
326
399
  return this;
327
400
  }
401
+ /**
402
+ * Sets the number of pixels used for each full-page scroll step.
403
+ */
404
+ fullPageScrollBy(pixels) {
405
+ this.put("full_page_scroll_by", pixels.toString());
406
+ return this;
407
+ }
408
+ /**
409
+ * Splits a full-page screenshot into smaller vertical image slices.
410
+ */
411
+ fullPageSlices(enabled) {
412
+ this.put("full_page_slices", enabled ? "true" : "false");
413
+ return this;
414
+ }
415
+ /**
416
+ * Sets the maximum height in pixels of each full-page slice.
417
+ */
418
+ fullPageSliceHeight(height) {
419
+ this.put("full_page_slice_height", height.toString());
420
+ return this;
421
+ }
422
+ /**
423
+ * Sets the vertical overlap in pixels between adjacent full-page slices.
424
+ */
425
+ fullPageSliceOverlapHeight(height) {
426
+ this.put("full_page_slice_overlap_height", height.toString());
427
+ return this;
428
+ }
328
429
  /**
329
430
  * Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
330
431
  */
@@ -367,6 +468,13 @@ class TakeOptions {
367
468
  this.put("ip_country_code", countryCode);
368
469
  return this;
369
470
  }
471
+ /**
472
+ * Sets the ScreenshotOne server region used for the request.
473
+ */
474
+ serversRegion(region) {
475
+ this.put("servers_region", region);
476
+ return this;
477
+ }
370
478
  /**
371
479
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
372
480
  */
@@ -512,6 +620,13 @@ class TakeOptions {
512
620
  this.put("block_chats", block ? "true" : "false");
513
621
  return this;
514
622
  }
623
+ /**
624
+ * Blocks social widgets.
625
+ */
626
+ blockSocials(block) {
627
+ this.put("block_socials", block ? "true" : "false");
628
+ return this;
629
+ }
515
630
  /**
516
631
  * Blocks trackers.
517
632
  */
@@ -595,6 +710,13 @@ class TakeOptions {
595
710
  this.put("proxy", proxy);
596
711
  return this;
597
712
  }
713
+ /**
714
+ * Bypasses the proxy for requests to matching hostname patterns.
715
+ */
716
+ proxyBypassHosts(...hosts) {
717
+ this.put("proxy_bypass_hosts", ...hosts);
718
+ return this;
719
+ }
598
720
  /**
599
721
  * Set cookies for the request.
600
722
  */
@@ -734,6 +856,55 @@ class TakeOptions {
734
856
  this.put("pdf_fit_one_page", fit ? "true" : "false");
735
857
  return this;
736
858
  }
859
+ /**
860
+ * Sets whether to render a PDF in landscape orientation.
861
+ */
862
+ pdfLandscape(landscape) {
863
+ this.put("pdf_landscape", landscape ? "true" : "false");
864
+ return this;
865
+ }
866
+ /**
867
+ * Sets the paper format for a PDF.
868
+ */
869
+ pdfPaperFormat(format) {
870
+ this.put("pdf_paper_format", format);
871
+ return this;
872
+ }
873
+ /**
874
+ * Sets the margin for all sides of a PDF.
875
+ */
876
+ pdfMargin(margin) {
877
+ this.put("pdf_margin", margin);
878
+ return this;
879
+ }
880
+ /**
881
+ * Sets the top margin of a PDF.
882
+ */
883
+ pdfMarginTop(margin) {
884
+ this.put("pdf_margin_top", margin);
885
+ return this;
886
+ }
887
+ /**
888
+ * Sets the right margin of a PDF.
889
+ */
890
+ pdfMarginRight(margin) {
891
+ this.put("pdf_margin_right", margin);
892
+ return this;
893
+ }
894
+ /**
895
+ * Sets the bottom margin of a PDF.
896
+ */
897
+ pdfMarginBottom(margin) {
898
+ this.put("pdf_margin_bottom", margin);
899
+ return this;
900
+ }
901
+ /**
902
+ * Sets the left margin of a PDF.
903
+ */
904
+ pdfMarginLeft(margin) {
905
+ this.put("pdf_margin_left", margin);
906
+ return this;
907
+ }
737
908
  /**
738
909
  * Sets the OpenAI API key for vision integration.
739
910
  */
@@ -769,6 +940,14 @@ class TakeOptions {
769
940
  this.put("wait_for_selector", selector);
770
941
  return this;
771
942
  }
943
+ /**
944
+ * Sets how matching selectors are counted while waiting for a selector.
945
+ * Available values are `at_least_one` and `at_least_by_count`.
946
+ */
947
+ waitForSelectorAlgorithm(algorithm) {
948
+ this.put("wait_for_selector_algorithm", algorithm);
949
+ return this;
950
+ }
772
951
  /**
773
952
  * Sets whether to return the storage location.
774
953
  */
@@ -790,6 +969,13 @@ class TakeOptions {
790
969
  this.put("metadata_fonts", include ? "true" : "false");
791
970
  return this;
792
971
  }
972
+ /**
973
+ * Sets whether to include favicon metadata.
974
+ */
975
+ metadataIcon(include) {
976
+ this.put("metadata_icon", include ? "true" : "false");
977
+ return this;
978
+ }
793
979
  /**
794
980
  * Sets whether to include Open Graph metadata.
795
981
  */
@@ -811,6 +997,13 @@ class TakeOptions {
811
997
  this.put("metadata_content", include ? "true" : "false");
812
998
  return this;
813
999
  }
1000
+ /**
1001
+ * Sets the extracted page content format to `html` or `markdown`.
1002
+ */
1003
+ metadataContentFormat(format) {
1004
+ this.put("metadata_content_format", format);
1005
+ return this;
1006
+ }
814
1007
  /**
815
1008
  * Sets whether to include HTTP response status code metadata.
816
1009
  */
@@ -846,11 +1039,35 @@ class TakeOptions {
846
1039
  this.put("webhook_sign", sign ? "true" : "false");
847
1040
  return this;
848
1041
  }
1042
+ /**
1043
+ * Sets whether webhook responses include rendering error details.
1044
+ */
1045
+ webhookErrors(include) {
1046
+ this.put("webhook_errors", include ? "true" : "false");
1047
+ return this;
1048
+ }
849
1049
  /**
850
1050
  * Sets the text to check for in the content to force request failure.
1051
+ * The option can be specified multiple times.
851
1052
  */
852
- failIfContentContains(text) {
853
- this.put("fail_if_content_contains", text);
1053
+ failIfContentContains(...texts) {
1054
+ this.put("fail_if_content_contains", ...texts);
1055
+ return this;
1056
+ }
1057
+ /**
1058
+ * Sets text that must be present in the page content.
1059
+ * The option can be specified multiple times.
1060
+ */
1061
+ failIfContentMissing(...texts) {
1062
+ this.put("fail_if_content_missing", ...texts);
1063
+ return this;
1064
+ }
1065
+ /**
1066
+ * Sets request URL patterns whose failure should fail the rendering request.
1067
+ * The option can be specified multiple times.
1068
+ */
1069
+ failIfRequestFailed(...patterns) {
1070
+ this.put("fail_if_request_failed", ...patterns);
854
1071
  return this;
855
1072
  }
856
1073
  /**
@@ -918,12 +1135,21 @@ class AnimateOptions {
918
1135
  return this;
919
1136
  }
920
1137
  /**
921
- * When reduced_motion set to `true`,
922
- * the API will request the site to minimize the amount of non-essential motion it uses.
923
- * When the site supports it, it should use animations as least as possible.
1138
+ * Actively reduces supported page motion during recording by finishing animations
1139
+ * and pausing media and sliders. Also enables the reduced-motion preference.
1140
+ * The API default is false. Unlike reducedMotion(), this actively freezes motion.
1141
+ */
1142
+ reduceMotion(reduceMotion) {
1143
+ this.put("reduce_motion", reduceMotion ? "true" : "false");
1144
+ return this;
1145
+ }
1146
+ /**
1147
+ * Requests reduced motion through the prefers-reduced-motion preference.
1148
+ * Websites may ignore this preference; it does not actively freeze motion.
1149
+ * Use reduceMotion(true) to actively reduce motion and enable this preference.
924
1150
  */
925
- reducedMotion(darkMode) {
926
- this.put("reduced_motion", darkMode ? "true" : "false");
1151
+ reducedMotion(reducedMotion) {
1152
+ this.put("reduced_motion", reducedMotion ? "true" : "false");
927
1153
  return this;
928
1154
  }
929
1155
  /**
@@ -984,6 +1210,13 @@ class AnimateOptions {
984
1210
  this.put("proxy", proxy);
985
1211
  return this;
986
1212
  }
1213
+ /**
1214
+ * Bypasses the proxy for requests to matching hostname patterns.
1215
+ */
1216
+ proxyBypassHosts(...hosts) {
1217
+ this.put("proxy_bypass_hosts", ...hosts);
1218
+ return this;
1219
+ }
987
1220
  /**
988
1221
  * Scripts specifies custom scripts for the page.
989
1222
  */
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.23",
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;
@@ -300,9 +319,47 @@ export class TakeOptions {
300
319
  }
301
320
 
302
321
  /**
303
- * When reduced_motion set to `true`,
304
- * the API will request the site to minimize the amount of non-essential motion it uses.
305
- * When the site supports it, it should use animations as least as possible.
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
+
348
+ /**
349
+ * Actively reduces supported motion by finishing animations and pausing media and sliders.
350
+ * Also enables the reduced-motion preference. The API default is false.
351
+ * Unlike reducedMotion(), this does not rely only on the website honoring that preference.
352
+ */
353
+ reduceMotion(reduceMotion: boolean): TakeOptions {
354
+ this.put("reduce_motion", reduceMotion ? "true" : "false");
355
+
356
+ return this;
357
+ }
358
+
359
+ /**
360
+ * Requests reduced motion through the prefers-reduced-motion preference.
361
+ * Websites may ignore this preference; it does not actively freeze motion.
362
+ * Use reduceMotion(true) to actively reduce motion and enable this preference.
306
363
  */
307
364
  reducedMotion(reducedMotion: boolean): TakeOptions {
308
365
  this.put("reduced_motion", reducedMotion ? "true" : "false");
@@ -377,6 +434,48 @@ export class TakeOptions {
377
434
  return this;
378
435
  }
379
436
 
437
+ /**
438
+ * Sets a selector for an element to click before taking the screenshot.
439
+ */
440
+ click(selector: string): TakeOptions {
441
+ this.put("click", selector);
442
+
443
+ return this;
444
+ }
445
+
446
+ /**
447
+ * Sets a selector for an element to hover over before taking the screenshot.
448
+ */
449
+ hover(selector: string): TakeOptions {
450
+ this.put("hover", selector);
451
+
452
+ return this;
453
+ }
454
+
455
+ /**
456
+ * Controls whether a missing click selector causes an error.
457
+ */
458
+ errorOnClickSelectorNotFound(errorOn: boolean): TakeOptions {
459
+ this.put(
460
+ "error_on_click_selector_not_found",
461
+ errorOn ? "true" : "false"
462
+ );
463
+
464
+ return this;
465
+ }
466
+
467
+ /**
468
+ * Controls whether a missing hover selector causes an error.
469
+ */
470
+ errorOnHoverSelectorNotFound(errorOn: boolean): TakeOptions {
471
+ this.put(
472
+ "error_on_hover_selector_not_found",
473
+ errorOn ? "true" : "false"
474
+ );
475
+
476
+ return this;
477
+ }
478
+
380
479
  /**
381
480
  * Renders the full page.
382
481
  */
@@ -422,6 +521,42 @@ export class TakeOptions {
422
521
  return this;
423
522
  }
424
523
 
524
+ /**
525
+ * Sets the number of pixels used for each full-page scroll step.
526
+ */
527
+ fullPageScrollBy(pixels: number): TakeOptions {
528
+ this.put("full_page_scroll_by", pixels.toString());
529
+
530
+ return this;
531
+ }
532
+
533
+ /**
534
+ * Splits a full-page screenshot into smaller vertical image slices.
535
+ */
536
+ fullPageSlices(enabled: boolean): TakeOptions {
537
+ this.put("full_page_slices", enabled ? "true" : "false");
538
+
539
+ return this;
540
+ }
541
+
542
+ /**
543
+ * Sets the maximum height in pixels of each full-page slice.
544
+ */
545
+ fullPageSliceHeight(height: number): TakeOptions {
546
+ this.put("full_page_slice_height", height.toString());
547
+
548
+ return this;
549
+ }
550
+
551
+ /**
552
+ * Sets the vertical overlap in pixels between adjacent full-page slices.
553
+ */
554
+ fullPageSliceOverlapHeight(height: number): TakeOptions {
555
+ this.put("full_page_slice_overlap_height", height.toString());
556
+
557
+ return this;
558
+ }
559
+
425
560
  /**
426
561
  * Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
427
562
  */
@@ -472,6 +607,15 @@ export class TakeOptions {
472
607
  return this;
473
608
  }
474
609
 
610
+ /**
611
+ * Sets the ScreenshotOne server region used for the request.
612
+ */
613
+ serversRegion(region: string): TakeOptions {
614
+ this.put("servers_region", region);
615
+
616
+ return this;
617
+ }
618
+
475
619
  /**
476
620
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
477
621
  */
@@ -663,6 +807,15 @@ export class TakeOptions {
663
807
  return this;
664
808
  }
665
809
 
810
+ /**
811
+ * Blocks social widgets.
812
+ */
813
+ blockSocials(block: boolean): TakeOptions {
814
+ this.put("block_socials", block ? "true" : "false");
815
+
816
+ return this;
817
+ }
818
+
666
819
  /**
667
820
  * Blocks trackers.
668
821
  */
@@ -768,6 +921,15 @@ export class TakeOptions {
768
921
  return this;
769
922
  }
770
923
 
924
+ /**
925
+ * Bypasses the proxy for requests to matching hostname patterns.
926
+ */
927
+ proxyBypassHosts(...hosts: string[]): TakeOptions {
928
+ this.put("proxy_bypass_hosts", ...hosts);
929
+
930
+ return this;
931
+ }
932
+
771
933
  /**
772
934
  * Set cookies for the request.
773
935
  */
@@ -945,6 +1107,69 @@ export class TakeOptions {
945
1107
  return this;
946
1108
  }
947
1109
 
1110
+ /**
1111
+ * Sets whether to render a PDF in landscape orientation.
1112
+ */
1113
+ pdfLandscape(landscape: boolean): TakeOptions {
1114
+ this.put("pdf_landscape", landscape ? "true" : "false");
1115
+
1116
+ return this;
1117
+ }
1118
+
1119
+ /**
1120
+ * Sets the paper format for a PDF.
1121
+ */
1122
+ pdfPaperFormat(format: string): TakeOptions {
1123
+ this.put("pdf_paper_format", format);
1124
+
1125
+ return this;
1126
+ }
1127
+
1128
+ /**
1129
+ * Sets the margin for all sides of a PDF.
1130
+ */
1131
+ pdfMargin(margin: string): TakeOptions {
1132
+ this.put("pdf_margin", margin);
1133
+
1134
+ return this;
1135
+ }
1136
+
1137
+ /**
1138
+ * Sets the top margin of a PDF.
1139
+ */
1140
+ pdfMarginTop(margin: string): TakeOptions {
1141
+ this.put("pdf_margin_top", margin);
1142
+
1143
+ return this;
1144
+ }
1145
+
1146
+ /**
1147
+ * Sets the right margin of a PDF.
1148
+ */
1149
+ pdfMarginRight(margin: string): TakeOptions {
1150
+ this.put("pdf_margin_right", margin);
1151
+
1152
+ return this;
1153
+ }
1154
+
1155
+ /**
1156
+ * Sets the bottom margin of a PDF.
1157
+ */
1158
+ pdfMarginBottom(margin: string): TakeOptions {
1159
+ this.put("pdf_margin_bottom", margin);
1160
+
1161
+ return this;
1162
+ }
1163
+
1164
+ /**
1165
+ * Sets the left margin of a PDF.
1166
+ */
1167
+ pdfMarginLeft(margin: string): TakeOptions {
1168
+ this.put("pdf_margin_left", margin);
1169
+
1170
+ return this;
1171
+ }
1172
+
948
1173
  /**
949
1174
  * Sets the OpenAI API key for vision integration.
950
1175
  */
@@ -990,6 +1215,16 @@ export class TakeOptions {
990
1215
  return this;
991
1216
  }
992
1217
 
1218
+ /**
1219
+ * Sets how matching selectors are counted while waiting for a selector.
1220
+ * Available values are `at_least_one` and `at_least_by_count`.
1221
+ */
1222
+ waitForSelectorAlgorithm(algorithm: string): TakeOptions {
1223
+ this.put("wait_for_selector_algorithm", algorithm);
1224
+
1225
+ return this;
1226
+ }
1227
+
993
1228
  /**
994
1229
  * Sets whether to return the storage location.
995
1230
  */
@@ -1017,6 +1252,15 @@ export class TakeOptions {
1017
1252
  return this;
1018
1253
  }
1019
1254
 
1255
+ /**
1256
+ * Sets whether to include favicon metadata.
1257
+ */
1258
+ metadataIcon(include: boolean): TakeOptions {
1259
+ this.put("metadata_icon", include ? "true" : "false");
1260
+
1261
+ return this;
1262
+ }
1263
+
1020
1264
  /**
1021
1265
  * Sets whether to include Open Graph metadata.
1022
1266
  */
@@ -1044,6 +1288,15 @@ export class TakeOptions {
1044
1288
  return this;
1045
1289
  }
1046
1290
 
1291
+ /**
1292
+ * Sets the extracted page content format to `html` or `markdown`.
1293
+ */
1294
+ metadataContentFormat(format: string): TakeOptions {
1295
+ this.put("metadata_content_format", format);
1296
+
1297
+ return this;
1298
+ }
1299
+
1047
1300
  /**
1048
1301
  * Sets whether to include HTTP response status code metadata.
1049
1302
  */
@@ -1092,11 +1345,41 @@ export class TakeOptions {
1092
1345
  return this;
1093
1346
  }
1094
1347
 
1348
+ /**
1349
+ * Sets whether webhook responses include rendering error details.
1350
+ */
1351
+ webhookErrors(include: boolean): TakeOptions {
1352
+ this.put("webhook_errors", include ? "true" : "false");
1353
+
1354
+ return this;
1355
+ }
1356
+
1095
1357
  /**
1096
1358
  * Sets the text to check for in the content to force request failure.
1359
+ * The option can be specified multiple times.
1097
1360
  */
1098
- failIfContentContains(text: string): TakeOptions {
1099
- this.put("fail_if_content_contains", text);
1361
+ failIfContentContains(...texts: string[]): TakeOptions {
1362
+ this.put("fail_if_content_contains", ...texts);
1363
+
1364
+ return this;
1365
+ }
1366
+
1367
+ /**
1368
+ * Sets text that must be present in the page content.
1369
+ * The option can be specified multiple times.
1370
+ */
1371
+ failIfContentMissing(...texts: string[]): TakeOptions {
1372
+ this.put("fail_if_content_missing", ...texts);
1373
+
1374
+ return this;
1375
+ }
1376
+
1377
+ /**
1378
+ * Sets request URL patterns whose failure should fail the rendering request.
1379
+ * The option can be specified multiple times.
1380
+ */
1381
+ failIfRequestFailed(...patterns: string[]): TakeOptions {
1382
+ this.put("fail_if_request_failed", ...patterns);
1100
1383
 
1101
1384
  return this;
1102
1385
  }
@@ -1180,12 +1463,23 @@ export class AnimateOptions {
1180
1463
  }
1181
1464
 
1182
1465
  /**
1183
- * When reduced_motion set to `true`,
1184
- * the API will request the site to minimize the amount of non-essential motion it uses.
1185
- * When the site supports it, it should use animations as least as possible.
1466
+ * Actively reduces supported page motion during recording by finishing animations
1467
+ * and pausing media and sliders. Also enables the reduced-motion preference.
1468
+ * The API default is false. Unlike reducedMotion(), this actively freezes motion.
1469
+ */
1470
+ reduceMotion(reduceMotion: boolean): AnimateOptions {
1471
+ this.put("reduce_motion", reduceMotion ? "true" : "false");
1472
+
1473
+ return this;
1474
+ }
1475
+
1476
+ /**
1477
+ * Requests reduced motion through the prefers-reduced-motion preference.
1478
+ * Websites may ignore this preference; it does not actively freeze motion.
1479
+ * Use reduceMotion(true) to actively reduce motion and enable this preference.
1186
1480
  */
1187
- reducedMotion(darkMode: boolean): AnimateOptions {
1188
- this.put("reduced_motion", darkMode ? "true" : "false");
1481
+ reducedMotion(reducedMotion: boolean): AnimateOptions {
1482
+ this.put("reduced_motion", reducedMotion ? "true" : "false");
1189
1483
 
1190
1484
  return this;
1191
1485
  }
@@ -1260,6 +1554,15 @@ export class AnimateOptions {
1260
1554
  return this;
1261
1555
  }
1262
1556
 
1557
+ /**
1558
+ * Bypasses the proxy for requests to matching hostname patterns.
1559
+ */
1560
+ proxyBypassHosts(...hosts: string[]): AnimateOptions {
1561
+ this.put("proxy_bypass_hosts", ...hosts);
1562
+
1563
+ return this;
1564
+ }
1565
+
1263
1566
  /**
1264
1567
  * Scripts specifies custom scripts for the page.
1265
1568
  */
@@ -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);