screenshotone-api-sdk 1.1.20 → 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.
- package/dist/@types/main.d.ts +130 -1
- package/dist/main.js +224 -2
- package/package.json +2 -2
- package/src/main.ts +292 -2
- package/tests/main.test.ts +103 -14
package/dist/@types/main.d.ts
CHANGED
|
@@ -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
|
*/
|
|
@@ -156,6 +193,26 @@ export declare class TakeOptions {
|
|
|
156
193
|
* Set `true` to scroll the page to the bottom.
|
|
157
194
|
*/
|
|
158
195
|
fullPageScroll(scroll: boolean): TakeOptions;
|
|
196
|
+
/**
|
|
197
|
+
* Sets the delay between scroll steps.
|
|
198
|
+
*/
|
|
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;
|
|
159
216
|
/**
|
|
160
217
|
* Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
|
|
161
218
|
*/
|
|
@@ -186,6 +243,10 @@ export declare class TakeOptions {
|
|
|
186
243
|
* Sets IP country code.
|
|
187
244
|
*/
|
|
188
245
|
ipCountryCode(countryCode: string): TakeOptions;
|
|
246
|
+
/**
|
|
247
|
+
* Sets the ScreenshotOne server region used for the request.
|
|
248
|
+
*/
|
|
249
|
+
serversRegion(region: string): TakeOptions;
|
|
189
250
|
/**
|
|
190
251
|
* Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
|
|
191
252
|
*/
|
|
@@ -271,6 +332,10 @@ export declare class TakeOptions {
|
|
|
271
332
|
* Blocks chats.
|
|
272
333
|
*/
|
|
273
334
|
blockChats(block: boolean): TakeOptions;
|
|
335
|
+
/**
|
|
336
|
+
* Blocks social widgets.
|
|
337
|
+
*/
|
|
338
|
+
blockSocials(block: boolean): TakeOptions;
|
|
274
339
|
/**
|
|
275
340
|
* Blocks trackers.
|
|
276
341
|
*/
|
|
@@ -321,6 +386,10 @@ export declare class TakeOptions {
|
|
|
321
386
|
* The https, http, socks4 and socks5 proxies are supported.
|
|
322
387
|
*/
|
|
323
388
|
proxy(proxy: string): TakeOptions;
|
|
389
|
+
/**
|
|
390
|
+
* Bypasses the proxy for requests to matching hostname patterns.
|
|
391
|
+
*/
|
|
392
|
+
proxyBypassHosts(...hosts: string[]): TakeOptions;
|
|
324
393
|
/**
|
|
325
394
|
* Set cookies for the request.
|
|
326
395
|
*/
|
|
@@ -403,6 +472,34 @@ export declare class TakeOptions {
|
|
|
403
472
|
* Sets whether to fit PDF to one page.
|
|
404
473
|
*/
|
|
405
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;
|
|
406
503
|
/**
|
|
407
504
|
* Sets the OpenAI API key for vision integration.
|
|
408
505
|
*/
|
|
@@ -423,6 +520,11 @@ export declare class TakeOptions {
|
|
|
423
520
|
* Sets whether to wait for a specific selector.
|
|
424
521
|
*/
|
|
425
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;
|
|
426
528
|
/**
|
|
427
529
|
* Sets whether to return the storage location.
|
|
428
530
|
*/
|
|
@@ -435,6 +537,10 @@ export declare class TakeOptions {
|
|
|
435
537
|
* Sets whether to include fonts metadata.
|
|
436
538
|
*/
|
|
437
539
|
metadataFonts(include: boolean): TakeOptions;
|
|
540
|
+
/**
|
|
541
|
+
* Sets whether to include favicon metadata.
|
|
542
|
+
*/
|
|
543
|
+
metadataIcon(include: boolean): TakeOptions;
|
|
438
544
|
/**
|
|
439
545
|
* Sets whether to include Open Graph metadata.
|
|
440
546
|
*/
|
|
@@ -447,6 +553,10 @@ export declare class TakeOptions {
|
|
|
447
553
|
* Sets whether to include content metadata.
|
|
448
554
|
*/
|
|
449
555
|
metadataContent(include: boolean): TakeOptions;
|
|
556
|
+
/**
|
|
557
|
+
* Sets the extracted page content format to `html` or `markdown`.
|
|
558
|
+
*/
|
|
559
|
+
metadataContentFormat(format: string): TakeOptions;
|
|
450
560
|
/**
|
|
451
561
|
* Sets whether to include HTTP response status code metadata.
|
|
452
562
|
*/
|
|
@@ -467,10 +577,25 @@ export declare class TakeOptions {
|
|
|
467
577
|
* Sets whether to sign the webhook request.
|
|
468
578
|
*/
|
|
469
579
|
webhookSign(sign: boolean): TakeOptions;
|
|
580
|
+
/**
|
|
581
|
+
* Sets whether webhook responses include rendering error details.
|
|
582
|
+
*/
|
|
583
|
+
webhookErrors(include: boolean): TakeOptions;
|
|
470
584
|
/**
|
|
471
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.
|
|
472
592
|
*/
|
|
473
|
-
|
|
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;
|
|
474
599
|
/**
|
|
475
600
|
* Sets whether to fail if GPU rendering fails.
|
|
476
601
|
*/
|
|
@@ -549,6 +674,10 @@ export declare class AnimateOptions {
|
|
|
549
674
|
* The https, http, socks4 and socks5 proxies are supported.
|
|
550
675
|
*/
|
|
551
676
|
proxy(proxy: string): AnimateOptions;
|
|
677
|
+
/**
|
|
678
|
+
* Bypasses the proxy for requests to matching hostname patterns.
|
|
679
|
+
*/
|
|
680
|
+
proxyBypassHosts(...hosts: string[]): AnimateOptions;
|
|
552
681
|
/**
|
|
553
682
|
* Scripts specifies custom scripts for the page.
|
|
554
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
|
*/
|
|
@@ -318,6 +382,41 @@ class TakeOptions {
|
|
|
318
382
|
this.put("full_page_scroll", scroll ? "true" : "false");
|
|
319
383
|
return this;
|
|
320
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Sets the delay between scroll steps.
|
|
387
|
+
*/
|
|
388
|
+
fullPageScrollDelay(delay) {
|
|
389
|
+
this.put("full_page_scroll_delay", delay.toString());
|
|
390
|
+
return this;
|
|
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
|
+
}
|
|
321
420
|
/**
|
|
322
421
|
* Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
|
|
323
422
|
*/
|
|
@@ -360,6 +459,13 @@ class TakeOptions {
|
|
|
360
459
|
this.put("ip_country_code", countryCode);
|
|
361
460
|
return this;
|
|
362
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
|
+
}
|
|
363
469
|
/**
|
|
364
470
|
* Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
|
|
365
471
|
*/
|
|
@@ -505,6 +611,13 @@ class TakeOptions {
|
|
|
505
611
|
this.put("block_chats", block ? "true" : "false");
|
|
506
612
|
return this;
|
|
507
613
|
}
|
|
614
|
+
/**
|
|
615
|
+
* Blocks social widgets.
|
|
616
|
+
*/
|
|
617
|
+
blockSocials(block) {
|
|
618
|
+
this.put("block_socials", block ? "true" : "false");
|
|
619
|
+
return this;
|
|
620
|
+
}
|
|
508
621
|
/**
|
|
509
622
|
* Blocks trackers.
|
|
510
623
|
*/
|
|
@@ -588,6 +701,13 @@ class TakeOptions {
|
|
|
588
701
|
this.put("proxy", proxy);
|
|
589
702
|
return this;
|
|
590
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
|
+
}
|
|
591
711
|
/**
|
|
592
712
|
* Set cookies for the request.
|
|
593
713
|
*/
|
|
@@ -727,6 +847,55 @@ class TakeOptions {
|
|
|
727
847
|
this.put("pdf_fit_one_page", fit ? "true" : "false");
|
|
728
848
|
return this;
|
|
729
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
|
+
}
|
|
730
899
|
/**
|
|
731
900
|
* Sets the OpenAI API key for vision integration.
|
|
732
901
|
*/
|
|
@@ -762,6 +931,14 @@ class TakeOptions {
|
|
|
762
931
|
this.put("wait_for_selector", selector);
|
|
763
932
|
return this;
|
|
764
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
|
+
}
|
|
765
942
|
/**
|
|
766
943
|
* Sets whether to return the storage location.
|
|
767
944
|
*/
|
|
@@ -783,6 +960,13 @@ class TakeOptions {
|
|
|
783
960
|
this.put("metadata_fonts", include ? "true" : "false");
|
|
784
961
|
return this;
|
|
785
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
|
+
}
|
|
786
970
|
/**
|
|
787
971
|
* Sets whether to include Open Graph metadata.
|
|
788
972
|
*/
|
|
@@ -804,6 +988,13 @@ class TakeOptions {
|
|
|
804
988
|
this.put("metadata_content", include ? "true" : "false");
|
|
805
989
|
return this;
|
|
806
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
|
+
}
|
|
807
998
|
/**
|
|
808
999
|
* Sets whether to include HTTP response status code metadata.
|
|
809
1000
|
*/
|
|
@@ -839,11 +1030,35 @@ class TakeOptions {
|
|
|
839
1030
|
this.put("webhook_sign", sign ? "true" : "false");
|
|
840
1031
|
return this;
|
|
841
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
|
+
}
|
|
842
1040
|
/**
|
|
843
1041
|
* Sets the text to check for in the content to force request failure.
|
|
1042
|
+
* The option can be specified multiple times.
|
|
844
1043
|
*/
|
|
845
|
-
failIfContentContains(
|
|
846
|
-
this.put("fail_if_content_contains",
|
|
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);
|
|
847
1062
|
return this;
|
|
848
1063
|
}
|
|
849
1064
|
/**
|
|
@@ -977,6 +1192,13 @@ class AnimateOptions {
|
|
|
977
1192
|
this.put("proxy", proxy);
|
|
978
1193
|
return this;
|
|
979
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
|
+
}
|
|
980
1202
|
/**
|
|
981
1203
|
* Scripts specifies custom scripts for the page.
|
|
982
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.
|
|
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
|
*/
|
|
@@ -413,6 +501,51 @@ export class TakeOptions {
|
|
|
413
501
|
return this;
|
|
414
502
|
}
|
|
415
503
|
|
|
504
|
+
/**
|
|
505
|
+
* Sets the delay between scroll steps.
|
|
506
|
+
*/
|
|
507
|
+
fullPageScrollDelay(delay: number): TakeOptions {
|
|
508
|
+
this.put("full_page_scroll_delay", delay.toString());
|
|
509
|
+
|
|
510
|
+
return this;
|
|
511
|
+
}
|
|
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
|
+
|
|
416
549
|
/**
|
|
417
550
|
* Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
|
|
418
551
|
*/
|
|
@@ -463,6 +596,15 @@ export class TakeOptions {
|
|
|
463
596
|
return this;
|
|
464
597
|
}
|
|
465
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
|
+
|
|
466
608
|
/**
|
|
467
609
|
* Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
|
|
468
610
|
*/
|
|
@@ -654,6 +796,15 @@ export class TakeOptions {
|
|
|
654
796
|
return this;
|
|
655
797
|
}
|
|
656
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
|
+
|
|
657
808
|
/**
|
|
658
809
|
* Blocks trackers.
|
|
659
810
|
*/
|
|
@@ -759,6 +910,15 @@ export class TakeOptions {
|
|
|
759
910
|
return this;
|
|
760
911
|
}
|
|
761
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
|
+
|
|
762
922
|
/**
|
|
763
923
|
* Set cookies for the request.
|
|
764
924
|
*/
|
|
@@ -936,6 +1096,69 @@ export class TakeOptions {
|
|
|
936
1096
|
return this;
|
|
937
1097
|
}
|
|
938
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
|
+
|
|
939
1162
|
/**
|
|
940
1163
|
* Sets the OpenAI API key for vision integration.
|
|
941
1164
|
*/
|
|
@@ -981,6 +1204,16 @@ export class TakeOptions {
|
|
|
981
1204
|
return this;
|
|
982
1205
|
}
|
|
983
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
|
+
|
|
984
1217
|
/**
|
|
985
1218
|
* Sets whether to return the storage location.
|
|
986
1219
|
*/
|
|
@@ -1008,6 +1241,15 @@ export class TakeOptions {
|
|
|
1008
1241
|
return this;
|
|
1009
1242
|
}
|
|
1010
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
|
+
|
|
1011
1253
|
/**
|
|
1012
1254
|
* Sets whether to include Open Graph metadata.
|
|
1013
1255
|
*/
|
|
@@ -1035,6 +1277,15 @@ export class TakeOptions {
|
|
|
1035
1277
|
return this;
|
|
1036
1278
|
}
|
|
1037
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
|
+
|
|
1038
1289
|
/**
|
|
1039
1290
|
* Sets whether to include HTTP response status code metadata.
|
|
1040
1291
|
*/
|
|
@@ -1083,11 +1334,41 @@ export class TakeOptions {
|
|
|
1083
1334
|
return this;
|
|
1084
1335
|
}
|
|
1085
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
|
+
|
|
1086
1346
|
/**
|
|
1087
1347
|
* Sets the text to check for in the content to force request failure.
|
|
1348
|
+
* The option can be specified multiple times.
|
|
1088
1349
|
*/
|
|
1089
|
-
failIfContentContains(
|
|
1090
|
-
this.put("fail_if_content_contains",
|
|
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);
|
|
1091
1372
|
|
|
1092
1373
|
return this;
|
|
1093
1374
|
}
|
|
@@ -1251,6 +1532,15 @@ export class AnimateOptions {
|
|
|
1251
1532
|
return this;
|
|
1252
1533
|
}
|
|
1253
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
|
+
|
|
1254
1544
|
/**
|
|
1255
1545
|
* Scripts specifies custom scripts for the page.
|
|
1256
1546
|
*/
|
package/tests/main.test.ts
CHANGED
|
@@ -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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
149
|
+
mockedFetch.mockResolvedValueOnce({
|
|
150
|
+
ok: false,
|
|
151
|
+
status: 400,
|
|
152
|
+
statusText: "Bad Request",
|
|
153
|
+
json: () =>
|
|
61
154
|
Promise.resolve({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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);
|