screenshotone-api-sdk 1.1.14 → 1.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,11 +36,24 @@ const url = client.generateTakeURL(options);
36
36
  console.log(url);
37
37
  // expected output: https://api.screenshotone.com/take?url=https%3A%2F%2Fexample.com&delay=3&block_ads=true&access_key=%3Caccess+key%3E&signature=7f3419ece2c53ed2c7923c7d5deef290d662c3643822bf69ec8259ce10b3ea61
38
38
 
39
- // or download the screenshot
40
- const imageBlob = await client.take(options);
41
- const buffer = Buffer.from(await imageBlob.arrayBuffer());
42
- fs.writeFileSync("example.png", buffer)
43
- // the screenshot is store in the example.png file
39
+ // download the screenshot and handle potential API errors
40
+ try {
41
+ const imageBlob = await client.take(options);
42
+
43
+ const buffer = Buffer.from(await imageBlob.arrayBuffer());
44
+ fs.writeFileSync("example.png", buffer);
45
+ } catch (error) {
46
+ if (error instanceof screenshotone.APIError) {
47
+ // An API error occurred with
48
+ // HTTP Status Code: error.httpStatusCode
49
+ // Error Code: error.errorCode
50
+ // Error Message: error.errorMessage
51
+ // Documentation URL: error.documentationUrl
52
+ } else {
53
+ // An unexpected error occurred
54
+ console.error("An unexpected error occurred:", error.message);
55
+ }
56
+ }
44
57
  ```
45
58
 
46
59
  ## Build and publish (a manual for SDK developers)
@@ -1,8 +1,7 @@
1
- declare class APIError extends Error {
1
+ export default class APIError extends Error {
2
2
  readonly httpStatusCode?: number;
3
3
  readonly errorCode?: string;
4
4
  readonly errorMessage?: string;
5
5
  readonly documentationUrl?: string;
6
6
  constructor(message: string, httpStatusCode?: number, errorCode?: string, errorMessage?: string, documentationUrl?: string);
7
7
  }
8
- export default APIError;
@@ -1,3 +1,5 @@
1
+ import APIError from "./errors";
2
+ export { APIError };
1
3
  /**
2
4
  * Represents an API client for the ScreenshotOne.com API.
3
5
  */
@@ -78,28 +80,29 @@ export declare class TakeOptions {
78
80
  /**
79
81
  * Selector is a CSS-like selector of the element to take a screenshot of.
80
82
  */
81
- selector(selector: string): this;
83
+ selector(selector: string): TakeOptions;
82
84
  /**
83
85
  * Available response types:
84
86
  * 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;
85
87
  * empty — return only status or error. It is suitable when you want to upload the screenshot to storage and don't care about the results. It also speeds up the response since there are no networking costs involved.
88
+ * json — A method returns the response in the JSON format, but it is only suitable if you use options that are effective for JSON. By default, the JSON response will be empty. But for example, when you use caching, the JSON will be populated with additional data.
86
89
  * The default value is by_format.
87
90
  */
88
- responseType(responseType: string): this;
91
+ responseType(responseType: string): TakeOptions;
89
92
  /**
90
93
  * It determines the behavior of what to do when selector is not found.
91
94
  */
92
- errorOnSelectorNotFound(errorOn: boolean): this;
95
+ errorOnSelectorNotFound(errorOn: boolean): TakeOptions;
93
96
  /**
94
97
  * Capture beyond the viewport.
95
98
  */
96
- captureBeyondViewport(beyond: boolean): this;
99
+ captureBeyondViewport(beyond: boolean): TakeOptions;
97
100
  /**
98
101
  * When reduced_motion set to `true`,
99
102
  * the API will request the site to minimize the amount of non-essential motion it uses.
100
103
  * When the site supports it, it should use animations as least as possible.
101
104
  */
102
- reducedMotion(darkMode: boolean): TakeOptions;
105
+ reducedMotion(reducedMotion: boolean): TakeOptions;
103
106
  /**
104
107
  * If you want to request the page and it is supported to be rendered for printers, specify `print`.
105
108
  * If the page is by default rendered for printers and you want it to be rendered for screens,
@@ -120,7 +123,7 @@ export declare class TakeOptions {
120
123
  */
121
124
  hideSelectors(...selectors: string[]): TakeOptions;
122
125
  /**
123
- * The scripts_wain_until option allows you to wait until a given
126
+ * The scripts_wait_until option allows you to wait until a given
124
127
  * set of events after the scripts were executed.
125
128
  * It accepts the same values as wait_until and can have multiple values:
126
129
  * - `load`: the navigation is successful when the load even is fired;
@@ -132,11 +135,11 @@ export declare class TakeOptions {
132
135
  /**
133
136
  * Styles specifies custom CSS styles for the page.
134
137
  */
135
- styles(styles: string): this;
138
+ styles(styles: string): TakeOptions;
136
139
  /**
137
140
  * Scripts specifies custom scripts for the page.
138
141
  */
139
- scripts(scripts: string): this;
142
+ scripts(scripts: string): TakeOptions;
140
143
  /**
141
144
  * Renders the full page.
142
145
  */
@@ -146,7 +149,7 @@ export declare class TakeOptions {
146
149
  */
147
150
  fullPageMaxHeight(maxHeight: number): TakeOptions;
148
151
  /**
149
- * Sets response format, one of: "png", "jpeg", "webp" or "jpg".
152
+ * Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
150
153
  */
151
154
  format(format: string): TakeOptions;
152
155
  /**
@@ -174,7 +177,7 @@ export declare class TakeOptions {
174
177
  /**
175
178
  * Sets IP country code.
176
179
  */
177
- ipCountryCode(format: string): TakeOptions;
180
+ ipCountryCode(countryCode: string): TakeOptions;
178
181
  /**
179
182
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
180
183
  */
@@ -367,6 +370,98 @@ export declare class TakeOptions {
367
370
  * Storage class allows you to specify the object storage class.
368
371
  */
369
372
  storageClass(storageClass: string): TakeOptions;
373
+ /**
374
+ * Sets the image width for thumbnail creation.
375
+ */
376
+ imageWidth(width: number): TakeOptions;
377
+ /**
378
+ * Sets the image height for thumbnail creation.
379
+ */
380
+ imageHeight(height: number): TakeOptions;
381
+ /**
382
+ * Sets whether to request GPU rendering.
383
+ */
384
+ requestGpuRendering(request: boolean): TakeOptions;
385
+ /**
386
+ * Sets whether to print background for PDF.
387
+ */
388
+ pdfPrintBackground(print: boolean): TakeOptions;
389
+ /**
390
+ * Sets whether to fit PDF to one page.
391
+ */
392
+ pdfFitOnePage(fit: boolean): TakeOptions;
393
+ /**
394
+ * Sets the OpenAI API key for vision integration.
395
+ */
396
+ openAiApiKey(key: string): TakeOptions;
397
+ /**
398
+ * Sets the vision prompt for OpenAI integration.
399
+ */
400
+ visionPrompt(prompt: string): TakeOptions;
401
+ /**
402
+ * Sets the maximum tokens for OpenAI vision response.
403
+ */
404
+ visionMaxTokens(tokens: number): TakeOptions;
405
+ /**
406
+ * Sets whether to bypass Content Security Policy.
407
+ */
408
+ bypassCsp(bypass: boolean): TakeOptions;
409
+ /**
410
+ * Sets whether to wait for a specific selector.
411
+ */
412
+ waitForSelector(selector: string): TakeOptions;
413
+ /**
414
+ * Sets whether to return the storage location.
415
+ */
416
+ storageReturnLocation(return_location: boolean): TakeOptions;
417
+ /**
418
+ * Sets whether to include image size metadata.
419
+ */
420
+ metadataImageSize(include: boolean): TakeOptions;
421
+ /**
422
+ * Sets whether to include fonts metadata.
423
+ */
424
+ metadataFonts(include: boolean): TakeOptions;
425
+ /**
426
+ * Sets whether to include Open Graph metadata.
427
+ */
428
+ metadataOpenGraph(include: boolean): TakeOptions;
429
+ /**
430
+ * Sets whether to include page title metadata.
431
+ */
432
+ metadataPageTitle(include: boolean): TakeOptions;
433
+ /**
434
+ * Sets whether to include content metadata.
435
+ */
436
+ metadataContent(include: boolean): TakeOptions;
437
+ /**
438
+ * Sets whether to include HTTP response status code metadata.
439
+ */
440
+ metadataHttpResponseStatusCode(include: boolean): TakeOptions;
441
+ /**
442
+ * Sets whether to include HTTP response headers metadata.
443
+ */
444
+ metadataHttpResponseHeaders(include: boolean): TakeOptions;
445
+ /**
446
+ * Sets whether to execute the request asynchronously.
447
+ */
448
+ async(isAsync: boolean): TakeOptions;
449
+ /**
450
+ * Sets the webhook URL for asynchronous requests.
451
+ */
452
+ webhookUrl(url: string): TakeOptions;
453
+ /**
454
+ * Sets whether to sign the webhook request.
455
+ */
456
+ webhookSign(sign: boolean): TakeOptions;
457
+ /**
458
+ * Sets the text to check for in the content to force request failure.
459
+ */
460
+ failIfContentContains(text: string): TakeOptions;
461
+ /**
462
+ * Sets whether to fail if GPU rendering fails.
463
+ */
464
+ failIfGpuRenderingFails(fail: boolean): TakeOptions;
370
465
  toQuery(): URLSearchParams;
371
466
  }
372
467
  /**
@@ -630,5 +725,81 @@ export declare class AnimateOptions {
630
725
  * for some reason, you need to render error pages.
631
726
  */
632
727
  ignoreHostErrors(ignore: boolean): AnimateOptions;
728
+ /**
729
+ * Sets whether to request GPU rendering.
730
+ */
731
+ requestGpuRendering(request: boolean): AnimateOptions;
732
+ /**
733
+ * Sets whether to bypass Content Security Policy.
734
+ */
735
+ bypassCsp(bypass: boolean): AnimateOptions;
736
+ /**
737
+ * Sets whether to wait for a specific selector.
738
+ */
739
+ waitForSelector(selector: string): AnimateOptions;
740
+ /**
741
+ * Sets whether to return the storage location.
742
+ */
743
+ storageReturnLocation(return_location: boolean): AnimateOptions;
744
+ /**
745
+ * Sets whether to execute the request asynchronously.
746
+ */
747
+ async(isAsync: boolean): AnimateOptions;
748
+ /**
749
+ * Sets the webhook URL for asynchronous requests.
750
+ */
751
+ webhookUrl(url: string): AnimateOptions;
752
+ /**
753
+ * Sets whether to sign the webhook request.
754
+ */
755
+ webhookSign(sign: boolean): AnimateOptions;
756
+ /**
757
+ * Sets the text to check for in the content to force request failure.
758
+ */
759
+ failIfContentContains(text: string): AnimateOptions;
760
+ /**
761
+ * Sets whether to fail if GPU rendering fails.
762
+ */
763
+ failIfGpuRenderingFails(fail: boolean): AnimateOptions;
764
+ /**
765
+ * Sets the width of the animation.
766
+ */
767
+ width(width: number): AnimateOptions;
768
+ /**
769
+ * Sets the height of the animation.
770
+ */
771
+ height(height: number): AnimateOptions;
772
+ /**
773
+ * Sets the aspect ratio of the animation.
774
+ */
775
+ aspectRatio(ratio: string): AnimateOptions;
776
+ /**
777
+ * Sets the scroll easing effect.
778
+ */
779
+ scrollEasing(easing: string): AnimateOptions;
780
+ /**
781
+ * Sets whether to navigate while scrolling and record the new opened page.
782
+ */
783
+ scrollTryNavigate(tryNavigate: boolean): AnimateOptions;
784
+ /**
785
+ * Sets when to navigate after scrolling (in milliseconds).
786
+ */
787
+ scrollNavigateAfter(duration: number): AnimateOptions;
788
+ /**
789
+ * Sets the URL to navigate to while scrolling.
790
+ */
791
+ scrollNavigateToURL(url: string): AnimateOptions;
792
+ /**
793
+ * Sets the link hints for navigation while scrolling.
794
+ */
795
+ scrollNavigateLinkHints(...hints: string[]): AnimateOptions;
796
+ /**
797
+ * Sets the scroll back algorithm.
798
+ */
799
+ scrollBackAlgorithm(algorithm: string): AnimateOptions;
800
+ /**
801
+ * Sets when to stop scrolling after the specified duration in milliseconds.
802
+ */
803
+ scrollStopAfterDuration(duration: number): AnimateOptions;
633
804
  toQuery(): URLSearchParams;
634
805
  }
package/dist/main.js CHANGED
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AnimateOptions = exports.TakeOptions = exports.Client = void 0;
6
+ exports.AnimateOptions = exports.TakeOptions = exports.Client = exports.APIError = void 0;
7
7
  const big_js_1 = __importDefault(require("big.js"));
8
8
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
9
9
  const signature_1 = require("./signature");
10
10
  const errors_1 = __importDefault(require("./errors"));
11
+ exports.APIError = errors_1.default;
11
12
  const API_BASE_URL = "https://api.screenshotone.com";
12
13
  const API_TAKE_PATH = "/take";
13
14
  const API_ANIMATE_PATH = "/animate";
@@ -201,6 +202,7 @@ class TakeOptions {
201
202
  * Available response types:
202
203
  * 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;
203
204
  * empty — return only status or error. It is suitable when you want to upload the screenshot to storage and don't care about the results. It also speeds up the response since there are no networking costs involved.
205
+ * json — A method returns the response in the JSON format, but it is only suitable if you use options that are effective for JSON. By default, the JSON response will be empty. But for example, when you use caching, the JSON will be populated with additional data.
204
206
  * The default value is by_format.
205
207
  */
206
208
  responseType(responseType) {
@@ -226,8 +228,8 @@ class TakeOptions {
226
228
  * the API will request the site to minimize the amount of non-essential motion it uses.
227
229
  * When the site supports it, it should use animations as least as possible.
228
230
  */
229
- reducedMotion(darkMode) {
230
- this.put("reduced_motion", darkMode ? "true" : "false");
231
+ reducedMotion(reducedMotion) {
232
+ this.put("reduced_motion", reducedMotion ? "true" : "false");
231
233
  return this;
232
234
  }
233
235
  /**
@@ -259,7 +261,7 @@ class TakeOptions {
259
261
  return this;
260
262
  }
261
263
  /**
262
- * The scripts_wain_until option allows you to wait until a given
264
+ * The scripts_wait_until option allows you to wait until a given
263
265
  * set of events after the scripts were executed.
264
266
  * It accepts the same values as wait_until and can have multiple values:
265
267
  * - `load`: the navigation is successful when the load even is fired;
@@ -300,7 +302,7 @@ class TakeOptions {
300
302
  return this;
301
303
  }
302
304
  /**
303
- * Sets response format, one of: "png", "jpeg", "webp" or "jpg".
305
+ * Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
304
306
  */
305
307
  format(format) {
306
308
  this.put("format", format);
@@ -337,8 +339,8 @@ class TakeOptions {
337
339
  /**
338
340
  * Sets IP country code.
339
341
  */
340
- ipCountryCode(format) {
341
- this.put("ip_country_code", format);
342
+ ipCountryCode(countryCode) {
343
+ this.put("ip_country_code", countryCode);
342
344
  return this;
343
345
  }
344
346
  /**
@@ -665,6 +667,167 @@ class TakeOptions {
665
667
  this.put("storage_class", storageClass);
666
668
  return this;
667
669
  }
670
+ /**
671
+ * Sets the image width for thumbnail creation.
672
+ */
673
+ imageWidth(width) {
674
+ this.put("image_width", width.toString());
675
+ return this;
676
+ }
677
+ /**
678
+ * Sets the image height for thumbnail creation.
679
+ */
680
+ imageHeight(height) {
681
+ this.put("image_height", height.toString());
682
+ return this;
683
+ }
684
+ /**
685
+ * Sets whether to request GPU rendering.
686
+ */
687
+ requestGpuRendering(request) {
688
+ this.put("request_gpu_rendering", request ? "true" : "false");
689
+ return this;
690
+ }
691
+ /**
692
+ * Sets whether to print background for PDF.
693
+ */
694
+ pdfPrintBackground(print) {
695
+ this.put("pdf_print_background", print ? "true" : "false");
696
+ return this;
697
+ }
698
+ /**
699
+ * Sets whether to fit PDF to one page.
700
+ */
701
+ pdfFitOnePage(fit) {
702
+ this.put("pdf_fit_one_page", fit ? "true" : "false");
703
+ return this;
704
+ }
705
+ /**
706
+ * Sets the OpenAI API key for vision integration.
707
+ */
708
+ openAiApiKey(key) {
709
+ this.put("openai_api_key", key);
710
+ return this;
711
+ }
712
+ /**
713
+ * Sets the vision prompt for OpenAI integration.
714
+ */
715
+ visionPrompt(prompt) {
716
+ this.put("vision_prompt", prompt);
717
+ return this;
718
+ }
719
+ /**
720
+ * Sets the maximum tokens for OpenAI vision response.
721
+ */
722
+ visionMaxTokens(tokens) {
723
+ this.put("vision_max_tokens", tokens.toString());
724
+ return this;
725
+ }
726
+ /**
727
+ * Sets whether to bypass Content Security Policy.
728
+ */
729
+ bypassCsp(bypass) {
730
+ this.put("bypass_csp", bypass ? "true" : "false");
731
+ return this;
732
+ }
733
+ /**
734
+ * Sets whether to wait for a specific selector.
735
+ */
736
+ waitForSelector(selector) {
737
+ this.put("wait_for_selector", selector);
738
+ return this;
739
+ }
740
+ /**
741
+ * Sets whether to return the storage location.
742
+ */
743
+ storageReturnLocation(return_location) {
744
+ this.put("storage_return_location", return_location ? "true" : "false");
745
+ return this;
746
+ }
747
+ /**
748
+ * Sets whether to include image size metadata.
749
+ */
750
+ metadataImageSize(include) {
751
+ this.put("metadata_image_size", include ? "true" : "false");
752
+ return this;
753
+ }
754
+ /**
755
+ * Sets whether to include fonts metadata.
756
+ */
757
+ metadataFonts(include) {
758
+ this.put("metadata_fonts", include ? "true" : "false");
759
+ return this;
760
+ }
761
+ /**
762
+ * Sets whether to include Open Graph metadata.
763
+ */
764
+ metadataOpenGraph(include) {
765
+ this.put("metadata_open_graph", include ? "true" : "false");
766
+ return this;
767
+ }
768
+ /**
769
+ * Sets whether to include page title metadata.
770
+ */
771
+ metadataPageTitle(include) {
772
+ this.put("metadata_page_title", include ? "true" : "false");
773
+ return this;
774
+ }
775
+ /**
776
+ * Sets whether to include content metadata.
777
+ */
778
+ metadataContent(include) {
779
+ this.put("metadata_content", include ? "true" : "false");
780
+ return this;
781
+ }
782
+ /**
783
+ * Sets whether to include HTTP response status code metadata.
784
+ */
785
+ metadataHttpResponseStatusCode(include) {
786
+ this.put("metadata_http_response_status_code", include ? "true" : "false");
787
+ return this;
788
+ }
789
+ /**
790
+ * Sets whether to include HTTP response headers metadata.
791
+ */
792
+ metadataHttpResponseHeaders(include) {
793
+ this.put("metadata_http_response_headers", include ? "true" : "false");
794
+ return this;
795
+ }
796
+ /**
797
+ * Sets whether to execute the request asynchronously.
798
+ */
799
+ async(isAsync) {
800
+ this.put("async", isAsync ? "true" : "false");
801
+ return this;
802
+ }
803
+ /**
804
+ * Sets the webhook URL for asynchronous requests.
805
+ */
806
+ webhookUrl(url) {
807
+ this.put("webhook_url", url);
808
+ return this;
809
+ }
810
+ /**
811
+ * Sets whether to sign the webhook request.
812
+ */
813
+ webhookSign(sign) {
814
+ this.put("webhook_sign", sign ? "true" : "false");
815
+ return this;
816
+ }
817
+ /**
818
+ * Sets the text to check for in the content to force request failure.
819
+ */
820
+ failIfContentContains(text) {
821
+ this.put("fail_if_content_contains", text);
822
+ return this;
823
+ }
824
+ /**
825
+ * Sets whether to fail if GPU rendering fails.
826
+ */
827
+ failIfGpuRenderingFails(fail) {
828
+ this.put("fail_if_gpu_rendering_fails", fail ? "true" : "false");
829
+ return this;
830
+ }
668
831
  toQuery() {
669
832
  return new URLSearchParams(this.query.toString());
670
833
  }
@@ -1125,6 +1288,139 @@ class AnimateOptions {
1125
1288
  this.put("ignore_host_errors", ignore ? "true" : "false");
1126
1289
  return this;
1127
1290
  }
1291
+ /**
1292
+ * Sets whether to request GPU rendering.
1293
+ */
1294
+ requestGpuRendering(request) {
1295
+ this.put("request_gpu_rendering", request ? "true" : "false");
1296
+ return this;
1297
+ }
1298
+ /**
1299
+ * Sets whether to bypass Content Security Policy.
1300
+ */
1301
+ bypassCsp(bypass) {
1302
+ this.put("bypass_csp", bypass ? "true" : "false");
1303
+ return this;
1304
+ }
1305
+ /**
1306
+ * Sets whether to wait for a specific selector.
1307
+ */
1308
+ waitForSelector(selector) {
1309
+ this.put("wait_for_selector", selector);
1310
+ return this;
1311
+ }
1312
+ /**
1313
+ * Sets whether to return the storage location.
1314
+ */
1315
+ storageReturnLocation(return_location) {
1316
+ this.put("storage_return_location", return_location ? "true" : "false");
1317
+ return this;
1318
+ }
1319
+ /**
1320
+ * Sets whether to execute the request asynchronously.
1321
+ */
1322
+ async(isAsync) {
1323
+ this.put("async", isAsync ? "true" : "false");
1324
+ return this;
1325
+ }
1326
+ /**
1327
+ * Sets the webhook URL for asynchronous requests.
1328
+ */
1329
+ webhookUrl(url) {
1330
+ this.put("webhook_url", url);
1331
+ return this;
1332
+ }
1333
+ /**
1334
+ * Sets whether to sign the webhook request.
1335
+ */
1336
+ webhookSign(sign) {
1337
+ this.put("webhook_sign", sign ? "true" : "false");
1338
+ return this;
1339
+ }
1340
+ /**
1341
+ * Sets the text to check for in the content to force request failure.
1342
+ */
1343
+ failIfContentContains(text) {
1344
+ this.put("fail_if_content_contains", text);
1345
+ return this;
1346
+ }
1347
+ /**
1348
+ * Sets whether to fail if GPU rendering fails.
1349
+ */
1350
+ failIfGpuRenderingFails(fail) {
1351
+ this.put("fail_if_gpu_rendering_fails", fail ? "true" : "false");
1352
+ return this;
1353
+ }
1354
+ /**
1355
+ * Sets the width of the animation.
1356
+ */
1357
+ width(width) {
1358
+ this.put("width", width.toString());
1359
+ return this;
1360
+ }
1361
+ /**
1362
+ * Sets the height of the animation.
1363
+ */
1364
+ height(height) {
1365
+ this.put("height", height.toString());
1366
+ return this;
1367
+ }
1368
+ /**
1369
+ * Sets the aspect ratio of the animation.
1370
+ */
1371
+ aspectRatio(ratio) {
1372
+ this.put("aspect_ratio", ratio);
1373
+ return this;
1374
+ }
1375
+ /**
1376
+ * Sets the scroll easing effect.
1377
+ */
1378
+ scrollEasing(easing) {
1379
+ this.put("scroll_easing", easing);
1380
+ return this;
1381
+ }
1382
+ /**
1383
+ * Sets whether to navigate while scrolling and record the new opened page.
1384
+ */
1385
+ scrollTryNavigate(tryNavigate) {
1386
+ this.put("scroll_try_navigate", tryNavigate ? "true" : "false");
1387
+ return this;
1388
+ }
1389
+ /**
1390
+ * Sets when to navigate after scrolling (in milliseconds).
1391
+ */
1392
+ scrollNavigateAfter(duration) {
1393
+ this.put("scroll_navigate_after", duration.toString());
1394
+ return this;
1395
+ }
1396
+ /**
1397
+ * Sets the URL to navigate to while scrolling.
1398
+ */
1399
+ scrollNavigateToURL(url) {
1400
+ this.put("scroll_navigate_to_url", url);
1401
+ return this;
1402
+ }
1403
+ /**
1404
+ * Sets the link hints for navigation while scrolling.
1405
+ */
1406
+ scrollNavigateLinkHints(...hints) {
1407
+ this.put("scroll_navigate_link_hints", ...hints);
1408
+ return this;
1409
+ }
1410
+ /**
1411
+ * Sets the scroll back algorithm.
1412
+ */
1413
+ scrollBackAlgorithm(algorithm) {
1414
+ this.put("scroll_back_algorithm", algorithm);
1415
+ return this;
1416
+ }
1417
+ /**
1418
+ * Sets when to stop scrolling after the specified duration in milliseconds.
1419
+ */
1420
+ scrollStopAfterDuration(duration) {
1421
+ this.put("scroll_stop_after_duration", duration.toString());
1422
+ return this;
1423
+ }
1128
1424
  toQuery() {
1129
1425
  return new URLSearchParams(this.query.toString());
1130
1426
  }
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.14",
4
+ "version": "1.1.16",
5
5
  "description": "Use ScreenshotOne.com API to generate screenshots of any website.",
6
6
  "repository": {
7
7
  "type": "git",
package/src/errors.ts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- class APIError extends Error {
2
+ export default class APIError extends Error {
3
3
  public readonly httpStatusCode?: number;
4
4
  public readonly errorCode?: string;
5
5
  public readonly errorMessage?: string;
@@ -13,6 +13,4 @@ class APIError extends Error {
13
13
  this.errorMessage = errorMessage;
14
14
  this.documentationUrl = documentationUrl;
15
15
  }
16
- }
17
-
18
- export default APIError;
16
+ }
package/src/main.ts CHANGED
@@ -7,6 +7,8 @@ const API_BASE_URL = "https://api.screenshotone.com";
7
7
  const API_TAKE_PATH = "/take";
8
8
  const API_ANIMATE_PATH = "/animate";
9
9
 
10
+ export { APIError };
11
+
10
12
  /**
11
13
  * Represents an API client for the ScreenshotOne.com API.
12
14
  */
@@ -248,7 +250,7 @@ export class TakeOptions {
248
250
  /**
249
251
  * Selector is a CSS-like selector of the element to take a screenshot of.
250
252
  */
251
- selector(selector: string) {
253
+ selector(selector: string): TakeOptions {
252
254
  this.put("selector", selector);
253
255
 
254
256
  return this;
@@ -258,9 +260,10 @@ export class TakeOptions {
258
260
  * Available response types:
259
261
  * 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;
260
262
  * empty — return only status or error. It is suitable when you want to upload the screenshot to storage and don't care about the results. It also speeds up the response since there are no networking costs involved.
263
+ * json — A method returns the response in the JSON format, but it is only suitable if you use options that are effective for JSON. By default, the JSON response will be empty. But for example, when you use caching, the JSON will be populated with additional data.
261
264
  * The default value is by_format.
262
265
  */
263
- responseType(responseType: string) {
266
+ responseType(responseType: string): TakeOptions {
264
267
  this.put("response_type", responseType);
265
268
 
266
269
  return this;
@@ -269,7 +272,7 @@ export class TakeOptions {
269
272
  /**
270
273
  * It determines the behavior of what to do when selector is not found.
271
274
  */
272
- errorOnSelectorNotFound(errorOn: boolean) {
275
+ errorOnSelectorNotFound(errorOn: boolean): TakeOptions {
273
276
  this.put("error_on_selector_not_found", errorOn ? "true" : "false");
274
277
 
275
278
  return this;
@@ -278,7 +281,7 @@ export class TakeOptions {
278
281
  /**
279
282
  * Capture beyond the viewport.
280
283
  */
281
- captureBeyondViewport(beyond: boolean) {
284
+ captureBeyondViewport(beyond: boolean): TakeOptions {
282
285
  this.put("capture_beyond_viewport", beyond ? "true" : "false");
283
286
 
284
287
  return this;
@@ -289,8 +292,8 @@ export class TakeOptions {
289
292
  * the API will request the site to minimize the amount of non-essential motion it uses.
290
293
  * When the site supports it, it should use animations as least as possible.
291
294
  */
292
- reducedMotion(darkMode: boolean): TakeOptions {
293
- this.put("reduced_motion", darkMode ? "true" : "false");
295
+ reducedMotion(reducedMotion: boolean): TakeOptions {
296
+ this.put("reduced_motion", reducedMotion ? "true" : "false");
294
297
 
295
298
  return this;
296
299
  }
@@ -330,7 +333,7 @@ export class TakeOptions {
330
333
  }
331
334
 
332
335
  /**
333
- * The scripts_wain_until option allows you to wait until a given
336
+ * The scripts_wait_until option allows you to wait until a given
334
337
  * set of events after the scripts were executed.
335
338
  * It accepts the same values as wait_until and can have multiple values:
336
339
  * - `load`: the navigation is successful when the load even is fired;
@@ -347,7 +350,7 @@ export class TakeOptions {
347
350
  /**
348
351
  * Styles specifies custom CSS styles for the page.
349
352
  */
350
- styles(styles: string) {
353
+ styles(styles: string): TakeOptions {
351
354
  this.put("styles", styles);
352
355
 
353
356
  return this;
@@ -356,7 +359,7 @@ export class TakeOptions {
356
359
  /**
357
360
  * Scripts specifies custom scripts for the page.
358
361
  */
359
- scripts(scripts: string) {
362
+ scripts(scripts: string): TakeOptions {
360
363
  this.put("scripts", scripts);
361
364
 
362
365
  return this;
@@ -381,7 +384,7 @@ export class TakeOptions {
381
384
  }
382
385
 
383
386
  /**
384
- * Sets response format, one of: "png", "jpeg", "webp" or "jpg".
387
+ * Sets response format, one of: "png", "jpeg", "webp", "jpg", "gif", "jp2", "tiff", "avif", "heif", "pdf", "html".
385
388
  */
386
389
  format(format: string): TakeOptions {
387
390
  this.put("format", format);
@@ -424,8 +427,8 @@ export class TakeOptions {
424
427
  /**
425
428
  * Sets IP country code.
426
429
  */
427
- ipCountryCode(format: string): TakeOptions {
428
- this.put("ip_country_code", format);
430
+ ipCountryCode(countryCode: string): TakeOptions {
431
+ this.put("ip_country_code", countryCode);
429
432
 
430
433
  return this;
431
434
  }
@@ -848,6 +851,213 @@ export class TakeOptions {
848
851
  return this;
849
852
  }
850
853
 
854
+ /**
855
+ * Sets the image width for thumbnail creation.
856
+ */
857
+ imageWidth(width: number): TakeOptions {
858
+ this.put("image_width", width.toString());
859
+
860
+ return this;
861
+ }
862
+
863
+ /**
864
+ * Sets the image height for thumbnail creation.
865
+ */
866
+ imageHeight(height: number): TakeOptions {
867
+ this.put("image_height", height.toString());
868
+
869
+ return this;
870
+ }
871
+
872
+ /**
873
+ * Sets whether to request GPU rendering.
874
+ */
875
+ requestGpuRendering(request: boolean): TakeOptions {
876
+ this.put("request_gpu_rendering", request ? "true" : "false");
877
+
878
+ return this;
879
+ }
880
+
881
+ /**
882
+ * Sets whether to print background for PDF.
883
+ */
884
+ pdfPrintBackground(print: boolean): TakeOptions {
885
+ this.put("pdf_print_background", print ? "true" : "false");
886
+
887
+ return this;
888
+ }
889
+
890
+ /**
891
+ * Sets whether to fit PDF to one page.
892
+ */
893
+ pdfFitOnePage(fit: boolean): TakeOptions {
894
+ this.put("pdf_fit_one_page", fit ? "true" : "false");
895
+
896
+ return this;
897
+ }
898
+
899
+ /**
900
+ * Sets the OpenAI API key for vision integration.
901
+ */
902
+ openAiApiKey(key: string): TakeOptions {
903
+ this.put("openai_api_key", key);
904
+
905
+ return this;
906
+ }
907
+
908
+ /**
909
+ * Sets the vision prompt for OpenAI integration.
910
+ */
911
+ visionPrompt(prompt: string): TakeOptions {
912
+ this.put("vision_prompt", prompt);
913
+
914
+ return this;
915
+ }
916
+
917
+ /**
918
+ * Sets the maximum tokens for OpenAI vision response.
919
+ */
920
+ visionMaxTokens(tokens: number): TakeOptions {
921
+ this.put("vision_max_tokens", tokens.toString());
922
+
923
+ return this;
924
+ }
925
+
926
+ /**
927
+ * Sets whether to bypass Content Security Policy.
928
+ */
929
+ bypassCsp(bypass: boolean): TakeOptions {
930
+ this.put("bypass_csp", bypass ? "true" : "false");
931
+
932
+ return this;
933
+ }
934
+
935
+ /**
936
+ * Sets whether to wait for a specific selector.
937
+ */
938
+ waitForSelector(selector: string): TakeOptions {
939
+ this.put("wait_for_selector", selector);
940
+
941
+ return this;
942
+ }
943
+
944
+ /**
945
+ * Sets whether to return the storage location.
946
+ */
947
+ storageReturnLocation(return_location: boolean): TakeOptions {
948
+ this.put("storage_return_location", return_location ? "true" : "false");
949
+
950
+ return this;
951
+ }
952
+
953
+ /**
954
+ * Sets whether to include image size metadata.
955
+ */
956
+ metadataImageSize(include: boolean): TakeOptions {
957
+ this.put("metadata_image_size", include ? "true" : "false");
958
+
959
+ return this;
960
+ }
961
+
962
+ /**
963
+ * Sets whether to include fonts metadata.
964
+ */
965
+ metadataFonts(include: boolean): TakeOptions {
966
+ this.put("metadata_fonts", include ? "true" : "false");
967
+
968
+ return this;
969
+ }
970
+
971
+ /**
972
+ * Sets whether to include Open Graph metadata.
973
+ */
974
+ metadataOpenGraph(include: boolean): TakeOptions {
975
+ this.put("metadata_open_graph", include ? "true" : "false");
976
+
977
+ return this;
978
+ }
979
+
980
+ /**
981
+ * Sets whether to include page title metadata.
982
+ */
983
+ metadataPageTitle(include: boolean): TakeOptions {
984
+ this.put("metadata_page_title", include ? "true" : "false");
985
+
986
+ return this;
987
+ }
988
+
989
+ /**
990
+ * Sets whether to include content metadata.
991
+ */
992
+ metadataContent(include: boolean): TakeOptions {
993
+ this.put("metadata_content", include ? "true" : "false");
994
+
995
+ return this;
996
+ }
997
+
998
+ /**
999
+ * Sets whether to include HTTP response status code metadata.
1000
+ */
1001
+ metadataHttpResponseStatusCode(include: boolean): TakeOptions {
1002
+ this.put("metadata_http_response_status_code", include ? "true" : "false");
1003
+
1004
+ return this;
1005
+ }
1006
+
1007
+ /**
1008
+ * Sets whether to include HTTP response headers metadata.
1009
+ */
1010
+ metadataHttpResponseHeaders(include: boolean): TakeOptions {
1011
+ this.put("metadata_http_response_headers", include ? "true" : "false");
1012
+
1013
+ return this;
1014
+ }
1015
+
1016
+ /**
1017
+ * Sets whether to execute the request asynchronously.
1018
+ */
1019
+ async(isAsync: boolean): TakeOptions {
1020
+ this.put("async", isAsync ? "true" : "false");
1021
+
1022
+ return this;
1023
+ }
1024
+
1025
+ /**
1026
+ * Sets the webhook URL for asynchronous requests.
1027
+ */
1028
+ webhookUrl(url: string): TakeOptions {
1029
+ this.put("webhook_url", url);
1030
+
1031
+ return this;
1032
+ }
1033
+
1034
+ /**
1035
+ * Sets whether to sign the webhook request.
1036
+ */
1037
+ webhookSign(sign: boolean): TakeOptions {
1038
+ this.put("webhook_sign", sign ? "true" : "false");
1039
+
1040
+ return this;
1041
+ }
1042
+
1043
+ /**
1044
+ * Sets the text to check for in the content to force request failure.
1045
+ */
1046
+ failIfContentContains(text: string): TakeOptions {
1047
+ this.put("fail_if_content_contains", text);
1048
+
1049
+ return this;
1050
+ }
1051
+
1052
+ /**
1053
+ * Sets whether to fail if GPU rendering fails.
1054
+ */
1055
+ failIfGpuRenderingFails(fail: boolean): TakeOptions {
1056
+ this.put("fail_if_gpu_rendering_fails", fail ? "true" : "false");
1057
+
1058
+ return this;
1059
+ }
1060
+
851
1061
  toQuery(): URLSearchParams {
852
1062
  return new URLSearchParams(this.query.toString());
853
1063
  }
@@ -1439,6 +1649,178 @@ export class AnimateOptions {
1439
1649
  return this;
1440
1650
  }
1441
1651
 
1652
+ /**
1653
+ * Sets whether to request GPU rendering.
1654
+ */
1655
+ requestGpuRendering(request: boolean): AnimateOptions {
1656
+ this.put("request_gpu_rendering", request ? "true" : "false");
1657
+
1658
+ return this;
1659
+ }
1660
+
1661
+ /**
1662
+ * Sets whether to bypass Content Security Policy.
1663
+ */
1664
+ bypassCsp(bypass: boolean): AnimateOptions {
1665
+ this.put("bypass_csp", bypass ? "true" : "false");
1666
+
1667
+ return this;
1668
+ }
1669
+
1670
+ /**
1671
+ * Sets whether to wait for a specific selector.
1672
+ */
1673
+ waitForSelector(selector: string): AnimateOptions {
1674
+ this.put("wait_for_selector", selector);
1675
+
1676
+ return this;
1677
+ }
1678
+
1679
+ /**
1680
+ * Sets whether to return the storage location.
1681
+ */
1682
+ storageReturnLocation(return_location: boolean): AnimateOptions {
1683
+ this.put("storage_return_location", return_location ? "true" : "false");
1684
+
1685
+ return this;
1686
+ }
1687
+
1688
+ /**
1689
+ * Sets whether to execute the request asynchronously.
1690
+ */
1691
+ async(isAsync: boolean): AnimateOptions {
1692
+ this.put("async", isAsync ? "true" : "false");
1693
+
1694
+ return this;
1695
+ }
1696
+
1697
+ /**
1698
+ * Sets the webhook URL for asynchronous requests.
1699
+ */
1700
+ webhookUrl(url: string): AnimateOptions {
1701
+ this.put("webhook_url", url);
1702
+
1703
+ return this;
1704
+ }
1705
+
1706
+ /**
1707
+ * Sets whether to sign the webhook request.
1708
+ */
1709
+ webhookSign(sign: boolean): AnimateOptions {
1710
+ this.put("webhook_sign", sign ? "true" : "false");
1711
+
1712
+ return this;
1713
+ }
1714
+
1715
+ /**
1716
+ * Sets the text to check for in the content to force request failure.
1717
+ */
1718
+ failIfContentContains(text: string): AnimateOptions {
1719
+ this.put("fail_if_content_contains", text);
1720
+
1721
+ return this;
1722
+ }
1723
+
1724
+ /**
1725
+ * Sets whether to fail if GPU rendering fails.
1726
+ */
1727
+ failIfGpuRenderingFails(fail: boolean): AnimateOptions {
1728
+ this.put("fail_if_gpu_rendering_fails", fail ? "true" : "false");
1729
+
1730
+ return this;
1731
+ }
1732
+
1733
+
1734
+ /**
1735
+ * Sets the width of the animation.
1736
+ */
1737
+ width(width: number): AnimateOptions {
1738
+ this.put("width", width.toString());
1739
+
1740
+ return this;
1741
+ }
1742
+
1743
+ /**
1744
+ * Sets the height of the animation.
1745
+ */
1746
+ height(height: number): AnimateOptions {
1747
+ this.put("height", height.toString());
1748
+
1749
+ return this;
1750
+ }
1751
+
1752
+ /**
1753
+ * Sets the aspect ratio of the animation.
1754
+ */
1755
+ aspectRatio(ratio: string): AnimateOptions {
1756
+ this.put("aspect_ratio", ratio);
1757
+
1758
+ return this;
1759
+ }
1760
+
1761
+ /**
1762
+ * Sets the scroll easing effect.
1763
+ */
1764
+ scrollEasing(easing: string): AnimateOptions {
1765
+ this.put("scroll_easing", easing);
1766
+
1767
+ return this;
1768
+ }
1769
+
1770
+ /**
1771
+ * Sets whether to navigate while scrolling and record the new opened page.
1772
+ */
1773
+ scrollTryNavigate(tryNavigate: boolean): AnimateOptions {
1774
+ this.put("scroll_try_navigate", tryNavigate ? "true" : "false");
1775
+
1776
+ return this;
1777
+ }
1778
+
1779
+ /**
1780
+ * Sets when to navigate after scrolling (in milliseconds).
1781
+ */
1782
+ scrollNavigateAfter(duration: number): AnimateOptions {
1783
+ this.put("scroll_navigate_after", duration.toString());
1784
+
1785
+ return this;
1786
+ }
1787
+
1788
+ /**
1789
+ * Sets the URL to navigate to while scrolling.
1790
+ */
1791
+ scrollNavigateToURL(url: string): AnimateOptions {
1792
+ this.put("scroll_navigate_to_url", url);
1793
+
1794
+ return this;
1795
+ }
1796
+
1797
+ /**
1798
+ * Sets the link hints for navigation while scrolling.
1799
+ */
1800
+ scrollNavigateLinkHints(...hints: string[]): AnimateOptions {
1801
+ this.put("scroll_navigate_link_hints", ...hints);
1802
+
1803
+ return this;
1804
+ }
1805
+
1806
+ /**
1807
+ * Sets the scroll back algorithm.
1808
+ */
1809
+ scrollBackAlgorithm(algorithm: string): AnimateOptions {
1810
+ this.put("scroll_back_algorithm", algorithm);
1811
+
1812
+ return this;
1813
+ }
1814
+
1815
+ /**
1816
+ * Sets when to stop scrolling after the specified duration in milliseconds.
1817
+ */
1818
+ scrollStopAfterDuration(duration: number): AnimateOptions {
1819
+ this.put("scroll_stop_after_duration", duration.toString());
1820
+ return this;
1821
+ }
1822
+
1823
+
1442
1824
  toQuery(): URLSearchParams {
1443
1825
  return new URLSearchParams(this.query.toString());
1444
1826
  }