screenshotone-api-sdk 1.0.19 → 1.0.21
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 +7 -0
- package/dist/@types/main.d.ts +211 -0
- package/dist/main.js +112 -6
- package/jest.config.js +6 -0
- package/package.json +4 -1
- package/src/main.ts +138 -6
- package/tests/main.test.ts +21 -0
package/README.md
CHANGED
|
@@ -43,6 +43,13 @@ fs.writeFileSync("example.png", buffer)
|
|
|
43
43
|
// the screenshot is store in the example.png file
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
## Build and publish (a manual for SDK developers)
|
|
47
|
+
|
|
48
|
+
To build and publish the SDK:
|
|
49
|
+
|
|
50
|
+
1. Bump the version property in the `package.json` file.
|
|
51
|
+
2. Run `npm publish`.
|
|
52
|
+
|
|
46
53
|
## License
|
|
47
54
|
|
|
48
55
|
`screenshotone/jssdk` is released under [the MIT license](LICENSE).
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an API client for the ScreenshotOne.com API.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Client {
|
|
5
|
+
private readonly accessKey;
|
|
6
|
+
private readonly secretKey;
|
|
7
|
+
constructor(accessKey: string, secretKey: string);
|
|
8
|
+
generateTakeURL(options: TakeOptions): string;
|
|
9
|
+
take(options: TakeOptions): Promise<Blob>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Represents options for taking screenshots.
|
|
13
|
+
*/
|
|
14
|
+
export declare class TakeOptions {
|
|
15
|
+
private readonly query;
|
|
16
|
+
private constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Initializes take screenshot options with provided website URL.
|
|
19
|
+
*/
|
|
20
|
+
static url(url: string): TakeOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Initializes take screenshot options with provided HTML.
|
|
23
|
+
*/
|
|
24
|
+
static html(html: string): TakeOptions;
|
|
25
|
+
/**
|
|
26
|
+
* Initializes take screenshot options with provided Markdown.
|
|
27
|
+
*/
|
|
28
|
+
static markdown(markdown: string): TakeOptions;
|
|
29
|
+
private put;
|
|
30
|
+
/**
|
|
31
|
+
* Selector is a CSS-like selector of the element to take a screenshot of.
|
|
32
|
+
*/
|
|
33
|
+
selector(selector: string): this;
|
|
34
|
+
/**
|
|
35
|
+
* It determines the behavior of what to do when selector is not found.
|
|
36
|
+
*/
|
|
37
|
+
errorOnSelectorNotFound(errorOn: boolean): this;
|
|
38
|
+
/**
|
|
39
|
+
* When reduced_motion set to `true`,
|
|
40
|
+
* the API will request the site to minimize the amount of non-essential motion it uses.
|
|
41
|
+
* When the site supports it, it should use animations as least as possible.
|
|
42
|
+
*/
|
|
43
|
+
reducedMotion(darkMode: boolean): TakeOptions;
|
|
44
|
+
/**
|
|
45
|
+
* If you want to request the page and it is supported to be rendered for printers, specify `print`.
|
|
46
|
+
* If the page is by default rendered for printers and you want it to be rendered for screens,
|
|
47
|
+
* use `screen`.
|
|
48
|
+
*/
|
|
49
|
+
mediaType(mediaType: string): TakeOptions;
|
|
50
|
+
/**
|
|
51
|
+
* Set `true` to request site rendering, if supported, in the dark mode.
|
|
52
|
+
* Set `false` to request site rendering in the light mode if supported.
|
|
53
|
+
* If you don’t set the parameter. The site is rendered in the default mode.
|
|
54
|
+
*/
|
|
55
|
+
darkMode(darkMode: boolean): TakeOptions;
|
|
56
|
+
/**
|
|
57
|
+
* The `hide_selectors` option allows hiding elements before taking a screenshot.
|
|
58
|
+
* You can specify as many selectors as you wish.
|
|
59
|
+
* All elements that match each selector will be hidden by
|
|
60
|
+
* setting the `display` style property to none `!important`.
|
|
61
|
+
*/
|
|
62
|
+
hideSelectors(...selectors: string[]): TakeOptions;
|
|
63
|
+
/**
|
|
64
|
+
* The scripts_wain_until option allows you to wait until a given
|
|
65
|
+
* set of events after the scripts were executed.
|
|
66
|
+
* It accepts the same values as wait_until and can have multiple values:
|
|
67
|
+
* - `load`: the navigation is successful when the load even is fired;
|
|
68
|
+
* - `domcontentloaded`: the navigation is finished when the DOMContentLoaded even is fired;
|
|
69
|
+
* - `networkidle0`: the navigation is finished when there are no more than 0 network connections for at least 500 ms;
|
|
70
|
+
* _ `networkidle2`: consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
|
|
71
|
+
*/
|
|
72
|
+
scriptsWaitUntil(...until: string[]): TakeOptions;
|
|
73
|
+
/**
|
|
74
|
+
* Styles specifies custom CSS styles for the page.
|
|
75
|
+
*/
|
|
76
|
+
styles(styles: string): this;
|
|
77
|
+
/**
|
|
78
|
+
* Scripts specifies custom scripts for the page.
|
|
79
|
+
*/
|
|
80
|
+
scripts(scripts: string): this;
|
|
81
|
+
/**
|
|
82
|
+
* Renders the full page.
|
|
83
|
+
*/
|
|
84
|
+
fullPage(fullPage: boolean): TakeOptions;
|
|
85
|
+
/**
|
|
86
|
+
* Sets response format, one of: "png", "jpeg", "webp" or "jpg".
|
|
87
|
+
*/
|
|
88
|
+
format(format: string): TakeOptions;
|
|
89
|
+
/**
|
|
90
|
+
* Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
|
|
91
|
+
*/
|
|
92
|
+
imageQuality(imageQuality: number): TakeOptions;
|
|
93
|
+
/**
|
|
94
|
+
* Renders a transparent background for the image. Works only if the site has not defined background color.
|
|
95
|
+
* Available for the following response formats: "png", "webp".
|
|
96
|
+
*/
|
|
97
|
+
omitBackground(omitBackground: boolean): TakeOptions;
|
|
98
|
+
/**
|
|
99
|
+
* Instead of manually specifying viewport parameters like width and height,
|
|
100
|
+
* you can specify a device to use for emulation.
|
|
101
|
+
* In addition, other parameters of the viewport, including the user agent,
|
|
102
|
+
* will be set automatically.
|
|
103
|
+
*/
|
|
104
|
+
viewportDevice(viewportDevice: string): TakeOptions;
|
|
105
|
+
/**
|
|
106
|
+
* Sets the width of the browser viewport (pixels).
|
|
107
|
+
*/
|
|
108
|
+
viewportWidth(viewportWidth: number): TakeOptions;
|
|
109
|
+
/**
|
|
110
|
+
* Sets the height of the browser viewport (pixels).
|
|
111
|
+
*/
|
|
112
|
+
viewportHeight(viewportHeight: number): TakeOptions;
|
|
113
|
+
/**
|
|
114
|
+
* Sets the device scale factor. Acceptable value is one of: 1, 2 or 3.
|
|
115
|
+
*/
|
|
116
|
+
deviceScaleFactor(deviceScaleFactor: number): TakeOptions;
|
|
117
|
+
/**
|
|
118
|
+
* Whether the meta viewport tag is taken into account. Defaults to `false`.
|
|
119
|
+
*/
|
|
120
|
+
viewportMobile(isMobile: boolean): TakeOptions;
|
|
121
|
+
/**
|
|
122
|
+
* The default value is `false`. Set to `true` if the viewport supports touch events.
|
|
123
|
+
*/
|
|
124
|
+
viewportHasTouch(hasTouch: boolean): TakeOptions;
|
|
125
|
+
/**
|
|
126
|
+
* The default value is `false`. Set to `true` if the viewport is in landscape mode.
|
|
127
|
+
*/
|
|
128
|
+
viewportLandscape(landscape: boolean): TakeOptions;
|
|
129
|
+
/**
|
|
130
|
+
* Sets geolocation latitude for the request.
|
|
131
|
+
* Both latitude and longitude are required if one of them is set.
|
|
132
|
+
*/
|
|
133
|
+
geolocationLatitude(latitude: number): TakeOptions;
|
|
134
|
+
/**
|
|
135
|
+
* Sets geolocation longitude for the request. Both latitude and longitude are required if one of them is set.
|
|
136
|
+
*/
|
|
137
|
+
geolocationLongitude(longitude: number): TakeOptions;
|
|
138
|
+
/**
|
|
139
|
+
* Sets the geolocation accuracy in meters.
|
|
140
|
+
*/
|
|
141
|
+
geolocationAccuracy(accuracy: number): TakeOptions;
|
|
142
|
+
/**
|
|
143
|
+
* Blocks ads.
|
|
144
|
+
*/
|
|
145
|
+
blockAds(blockAds: boolean): TakeOptions;
|
|
146
|
+
/**
|
|
147
|
+
* Blocks cookie banners.
|
|
148
|
+
*/
|
|
149
|
+
blockCookieBanners(block: boolean): TakeOptions;
|
|
150
|
+
/**
|
|
151
|
+
* Blocks chats.
|
|
152
|
+
*/
|
|
153
|
+
blockChats(block: boolean): TakeOptions;
|
|
154
|
+
/**
|
|
155
|
+
* Blocks trackers.
|
|
156
|
+
*/
|
|
157
|
+
blockTrackers(blockTrackers: boolean): TakeOptions;
|
|
158
|
+
/**
|
|
159
|
+
* Blocks requests by specifying URL, domain, or even a simple pattern.
|
|
160
|
+
*/
|
|
161
|
+
blockRequests(...blockRequests: string[]): TakeOptions;
|
|
162
|
+
/**
|
|
163
|
+
* Blocks loading resources by type. Available resource types are: "document", "stylesheet", "image", "media",
|
|
164
|
+
* "font", "script", "texttrack", "xhr", "fetch", "eventsource", "websocket", "manifest", "other".
|
|
165
|
+
*/
|
|
166
|
+
blockResources(...blockResources: string[]): TakeOptions;
|
|
167
|
+
/**
|
|
168
|
+
* Enables caching.
|
|
169
|
+
*/
|
|
170
|
+
cache(cache: boolean): TakeOptions;
|
|
171
|
+
/**
|
|
172
|
+
* Sets cache TTL.
|
|
173
|
+
*/
|
|
174
|
+
cacheTtl(cacheTTL: number): TakeOptions;
|
|
175
|
+
/**
|
|
176
|
+
* Sets cache key.
|
|
177
|
+
*/
|
|
178
|
+
cacheKey(cacheKey: string): TakeOptions;
|
|
179
|
+
/**
|
|
180
|
+
* Sets a user agent for the request.
|
|
181
|
+
*/
|
|
182
|
+
userAgent(userAgent: string): TakeOptions;
|
|
183
|
+
/**
|
|
184
|
+
* Sets an authorization header for the request.
|
|
185
|
+
*/
|
|
186
|
+
authorization(authorization: string): TakeOptions;
|
|
187
|
+
/**
|
|
188
|
+
* Set cookies for the request.
|
|
189
|
+
*/
|
|
190
|
+
cookies(...cookies: string[]): TakeOptions;
|
|
191
|
+
/**
|
|
192
|
+
* Sets extra headers for the request.
|
|
193
|
+
*/
|
|
194
|
+
headers(...headers: string[]): this;
|
|
195
|
+
/**
|
|
196
|
+
* TimeZone sets time zone for the request.
|
|
197
|
+
* Available time zones are: "America/Santiago", "Asia/Shanghai", "Europe/Berlin", "America/Guayaquil",
|
|
198
|
+
* "Europe/Madrid", "Pacific/Majuro", "Asia/Kuala_Lumpur", "Pacific/Auckland", "Europe/Lisbon", "Europe/Kiev",
|
|
199
|
+
* "Asia/Tashkent", "Europe/London".
|
|
200
|
+
*/
|
|
201
|
+
timeZone(timeZone: string): TakeOptions;
|
|
202
|
+
/**
|
|
203
|
+
* Sets delay.
|
|
204
|
+
*/
|
|
205
|
+
delay(delay: number): TakeOptions;
|
|
206
|
+
/**
|
|
207
|
+
* Sets timeout.
|
|
208
|
+
*/
|
|
209
|
+
timeout(timeout: number): TakeOptions;
|
|
210
|
+
toQuery(): URLSearchParams;
|
|
211
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -33,7 +33,7 @@ const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
|
33
33
|
const API_BASE_URL = "https://api.screenshotone.com";
|
|
34
34
|
const API_TAKE_PATH = "/take";
|
|
35
35
|
/**
|
|
36
|
-
* Represents an API client for the
|
|
36
|
+
* Represents an API client for the ScreenshotOne.com API.
|
|
37
37
|
*/
|
|
38
38
|
class Client {
|
|
39
39
|
constructor(accessKey, secretKey) {
|
|
@@ -65,22 +65,33 @@ exports.Client = Client;
|
|
|
65
65
|
* Represents options for taking screenshots.
|
|
66
66
|
*/
|
|
67
67
|
class TakeOptions {
|
|
68
|
-
constructor(
|
|
68
|
+
constructor() {
|
|
69
69
|
const query = new URLSearchParams();
|
|
70
|
-
query.append("url", url);
|
|
71
70
|
this.query = query;
|
|
72
71
|
}
|
|
73
72
|
/**
|
|
74
73
|
* Initializes take screenshot options with provided website URL.
|
|
75
74
|
*/
|
|
76
75
|
static url(url) {
|
|
77
|
-
|
|
76
|
+
const options = new TakeOptions();
|
|
77
|
+
options.put("url", url);
|
|
78
|
+
return options;
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
80
81
|
* Initializes take screenshot options with provided HTML.
|
|
81
82
|
*/
|
|
82
|
-
static html(
|
|
83
|
-
|
|
83
|
+
static html(html) {
|
|
84
|
+
const options = new TakeOptions();
|
|
85
|
+
options.put("html", html);
|
|
86
|
+
return options;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Initializes take screenshot options with provided Markdown.
|
|
90
|
+
*/
|
|
91
|
+
static markdown(markdown) {
|
|
92
|
+
const options = new TakeOptions();
|
|
93
|
+
options.put("markdown", markdown);
|
|
94
|
+
return options;
|
|
84
95
|
}
|
|
85
96
|
put(key, ...values) {
|
|
86
97
|
for (const value of values) {
|
|
@@ -102,6 +113,56 @@ class TakeOptions {
|
|
|
102
113
|
this.put("error_on_selector_not_found", errorOn ? "true" : "false");
|
|
103
114
|
return this;
|
|
104
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* When reduced_motion set to `true`,
|
|
118
|
+
* the API will request the site to minimize the amount of non-essential motion it uses.
|
|
119
|
+
* When the site supports it, it should use animations as least as possible.
|
|
120
|
+
*/
|
|
121
|
+
reducedMotion(darkMode) {
|
|
122
|
+
this.put("reduced_motion", darkMode ? "true" : "false");
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* If you want to request the page and it is supported to be rendered for printers, specify `print`.
|
|
127
|
+
* If the page is by default rendered for printers and you want it to be rendered for screens,
|
|
128
|
+
* use `screen`.
|
|
129
|
+
*/
|
|
130
|
+
mediaType(mediaType) {
|
|
131
|
+
this.put("media_type", mediaType);
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Set `true` to request site rendering, if supported, in the dark mode.
|
|
136
|
+
* Set `false` to request site rendering in the light mode if supported.
|
|
137
|
+
* If you don’t set the parameter. The site is rendered in the default mode.
|
|
138
|
+
*/
|
|
139
|
+
darkMode(darkMode) {
|
|
140
|
+
this.put("dark_mode", darkMode ? "true" : "false");
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The `hide_selectors` option allows hiding elements before taking a screenshot.
|
|
145
|
+
* You can specify as many selectors as you wish.
|
|
146
|
+
* All elements that match each selector will be hidden by
|
|
147
|
+
* setting the `display` style property to none `!important`.
|
|
148
|
+
*/
|
|
149
|
+
hideSelectors(...selectors) {
|
|
150
|
+
this.put("hide_selectors", ...selectors);
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The scripts_wain_until option allows you to wait until a given
|
|
155
|
+
* set of events after the scripts were executed.
|
|
156
|
+
* It accepts the same values as wait_until and can have multiple values:
|
|
157
|
+
* - `load`: the navigation is successful when the load even is fired;
|
|
158
|
+
* - `domcontentloaded`: the navigation is finished when the DOMContentLoaded even is fired;
|
|
159
|
+
* - `networkidle0`: the navigation is finished when there are no more than 0 network connections for at least 500 ms;
|
|
160
|
+
* _ `networkidle2`: consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
|
|
161
|
+
*/
|
|
162
|
+
scriptsWaitUntil(...until) {
|
|
163
|
+
this.put("scripts_wait_until", ...until);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
105
166
|
/**
|
|
106
167
|
* Styles specifies custom CSS styles for the page.
|
|
107
168
|
*/
|
|
@@ -145,6 +206,16 @@ class TakeOptions {
|
|
|
145
206
|
this.put("omit_background", omitBackground ? "true" : "false");
|
|
146
207
|
return this;
|
|
147
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Instead of manually specifying viewport parameters like width and height,
|
|
211
|
+
* you can specify a device to use for emulation.
|
|
212
|
+
* In addition, other parameters of the viewport, including the user agent,
|
|
213
|
+
* will be set automatically.
|
|
214
|
+
*/
|
|
215
|
+
viewportDevice(viewportDevice) {
|
|
216
|
+
this.put("viewport_device", viewportDevice);
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
148
219
|
/**
|
|
149
220
|
* Sets the width of the browser viewport (pixels).
|
|
150
221
|
*/
|
|
@@ -166,6 +237,27 @@ class TakeOptions {
|
|
|
166
237
|
this.put("device_scale_factor", deviceScaleFactor.toString());
|
|
167
238
|
return this;
|
|
168
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Whether the meta viewport tag is taken into account. Defaults to `false`.
|
|
242
|
+
*/
|
|
243
|
+
viewportMobile(isMobile) {
|
|
244
|
+
this.put("viewport_mobile", isMobile ? "true" : "false");
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The default value is `false`. Set to `true` if the viewport supports touch events.
|
|
249
|
+
*/
|
|
250
|
+
viewportHasTouch(hasTouch) {
|
|
251
|
+
this.put("viewport_has_touch", hasTouch ? "true" : "false");
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The default value is `false`. Set to `true` if the viewport is in landscape mode.
|
|
256
|
+
*/
|
|
257
|
+
viewportLandscape(landscape) {
|
|
258
|
+
this.put("viewport_landscape", landscape ? "true" : "false");
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
169
261
|
/**
|
|
170
262
|
* Sets geolocation latitude for the request.
|
|
171
263
|
* Both latitude and longitude are required if one of them is set.
|
|
@@ -195,6 +287,20 @@ class TakeOptions {
|
|
|
195
287
|
this.put("block_ads", blockAds ? "true" : "false");
|
|
196
288
|
return this;
|
|
197
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Blocks cookie banners.
|
|
292
|
+
*/
|
|
293
|
+
blockCookieBanners(block) {
|
|
294
|
+
this.put("block_cookie_banners", block ? "true" : "false");
|
|
295
|
+
return this;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Blocks chats.
|
|
299
|
+
*/
|
|
300
|
+
blockChats(block) {
|
|
301
|
+
this.put("block_chats", block ? "true" : "false");
|
|
302
|
+
return this;
|
|
303
|
+
}
|
|
198
304
|
/**
|
|
199
305
|
* Blocks trackers.
|
|
200
306
|
*/
|
package/jest.config.js
ADDED
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.0.
|
|
4
|
+
"version": "1.0.21",
|
|
5
5
|
"description": "Use ScreenshotOne.com API to generate screenshots of any website.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -31,7 +31,10 @@
|
|
|
31
31
|
"types": "dist/@types/main.d.ts",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/big.js": "^6.1.3",
|
|
34
|
+
"@types/jest": "^29.0.1",
|
|
34
35
|
"@types/node": "^17.0.40",
|
|
36
|
+
"jest": "^29.0.3",
|
|
37
|
+
"ts-jest": "^29.0.0",
|
|
35
38
|
"typescript": "^4.7.3"
|
|
36
39
|
},
|
|
37
40
|
"dependencies": {
|
package/src/main.ts
CHANGED
|
@@ -6,7 +6,7 @@ const API_BASE_URL = "https://api.screenshotone.com";
|
|
|
6
6
|
const API_TAKE_PATH = "/take";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Represents an API client for the
|
|
9
|
+
* Represents an API client for the ScreenshotOne.com API.
|
|
10
10
|
*/
|
|
11
11
|
export class Client {
|
|
12
12
|
private readonly accessKey: string;
|
|
@@ -49,9 +49,8 @@ export class Client {
|
|
|
49
49
|
export class TakeOptions {
|
|
50
50
|
private readonly query: URLSearchParams;
|
|
51
51
|
|
|
52
|
-
private constructor(
|
|
52
|
+
private constructor() {
|
|
53
53
|
const query = new URLSearchParams();
|
|
54
|
-
query.append("url", url);
|
|
55
54
|
|
|
56
55
|
this.query = query;
|
|
57
56
|
}
|
|
@@ -60,14 +59,30 @@ export class TakeOptions {
|
|
|
60
59
|
* Initializes take screenshot options with provided website URL.
|
|
61
60
|
*/
|
|
62
61
|
static url(url: string): TakeOptions {
|
|
63
|
-
|
|
62
|
+
const options = new TakeOptions();
|
|
63
|
+
options.put("url", url);
|
|
64
|
+
|
|
65
|
+
return options;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/**
|
|
67
69
|
* Initializes take screenshot options with provided HTML.
|
|
68
70
|
*/
|
|
69
|
-
static html(
|
|
70
|
-
|
|
71
|
+
static html(html: string): TakeOptions {
|
|
72
|
+
const options = new TakeOptions();
|
|
73
|
+
options.put("html", html);
|
|
74
|
+
|
|
75
|
+
return options;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Initializes take screenshot options with provided Markdown.
|
|
80
|
+
*/
|
|
81
|
+
static markdown(markdown: string): TakeOptions {
|
|
82
|
+
const options = new TakeOptions();
|
|
83
|
+
options.put("markdown", markdown);
|
|
84
|
+
|
|
85
|
+
return options;
|
|
71
86
|
}
|
|
72
87
|
|
|
73
88
|
private put(key: string, ...values: string[]) {
|
|
@@ -94,6 +109,66 @@ export class TakeOptions {
|
|
|
94
109
|
return this;
|
|
95
110
|
}
|
|
96
111
|
|
|
112
|
+
/**
|
|
113
|
+
* When reduced_motion set to `true`,
|
|
114
|
+
* the API will request the site to minimize the amount of non-essential motion it uses.
|
|
115
|
+
* When the site supports it, it should use animations as least as possible.
|
|
116
|
+
*/
|
|
117
|
+
reducedMotion(darkMode: boolean): TakeOptions {
|
|
118
|
+
this.put("reduced_motion", darkMode ? "true" : "false");
|
|
119
|
+
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* If you want to request the page and it is supported to be rendered for printers, specify `print`.
|
|
125
|
+
* If the page is by default rendered for printers and you want it to be rendered for screens,
|
|
126
|
+
* use `screen`.
|
|
127
|
+
*/
|
|
128
|
+
mediaType(mediaType: string): TakeOptions {
|
|
129
|
+
this.put("media_type", mediaType);
|
|
130
|
+
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Set `true` to request site rendering, if supported, in the dark mode.
|
|
136
|
+
* Set `false` to request site rendering in the light mode if supported.
|
|
137
|
+
* If you don’t set the parameter. The site is rendered in the default mode.
|
|
138
|
+
*/
|
|
139
|
+
darkMode(darkMode: boolean): TakeOptions {
|
|
140
|
+
this.put("dark_mode", darkMode ? "true" : "false");
|
|
141
|
+
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The `hide_selectors` option allows hiding elements before taking a screenshot.
|
|
147
|
+
* You can specify as many selectors as you wish.
|
|
148
|
+
* All elements that match each selector will be hidden by
|
|
149
|
+
* setting the `display` style property to none `!important`.
|
|
150
|
+
*/
|
|
151
|
+
hideSelectors(...selectors: string[]): TakeOptions {
|
|
152
|
+
this.put("hide_selectors", ...selectors);
|
|
153
|
+
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The scripts_wain_until option allows you to wait until a given
|
|
159
|
+
* set of events after the scripts were executed.
|
|
160
|
+
* It accepts the same values as wait_until and can have multiple values:
|
|
161
|
+
* - `load`: the navigation is successful when the load even is fired;
|
|
162
|
+
* - `domcontentloaded`: the navigation is finished when the DOMContentLoaded even is fired;
|
|
163
|
+
* - `networkidle0`: the navigation is finished when there are no more than 0 network connections for at least 500 ms;
|
|
164
|
+
* _ `networkidle2`: consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
|
|
165
|
+
*/
|
|
166
|
+
scriptsWaitUntil(...until: string[]): TakeOptions {
|
|
167
|
+
this.put("scripts_wait_until", ...until);
|
|
168
|
+
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
|
|
97
172
|
/**
|
|
98
173
|
* Styles specifies custom CSS styles for the page.
|
|
99
174
|
*/
|
|
@@ -150,6 +225,18 @@ export class TakeOptions {
|
|
|
150
225
|
return this;
|
|
151
226
|
}
|
|
152
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Instead of manually specifying viewport parameters like width and height,
|
|
230
|
+
* you can specify a device to use for emulation.
|
|
231
|
+
* In addition, other parameters of the viewport, including the user agent,
|
|
232
|
+
* will be set automatically.
|
|
233
|
+
*/
|
|
234
|
+
viewportDevice(viewportDevice: string): TakeOptions {
|
|
235
|
+
this.put("viewport_device", viewportDevice);
|
|
236
|
+
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
|
|
153
240
|
/**
|
|
154
241
|
* Sets the width of the browser viewport (pixels).
|
|
155
242
|
*/
|
|
@@ -177,6 +264,33 @@ export class TakeOptions {
|
|
|
177
264
|
return this;
|
|
178
265
|
}
|
|
179
266
|
|
|
267
|
+
/**
|
|
268
|
+
* Whether the meta viewport tag is taken into account. Defaults to `false`.
|
|
269
|
+
*/
|
|
270
|
+
viewportMobile(isMobile: boolean): TakeOptions {
|
|
271
|
+
this.put("viewport_mobile", isMobile ? "true" : "false");
|
|
272
|
+
|
|
273
|
+
return this;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The default value is `false`. Set to `true` if the viewport supports touch events.
|
|
278
|
+
*/
|
|
279
|
+
viewportHasTouch(hasTouch: boolean): TakeOptions {
|
|
280
|
+
this.put("viewport_has_touch", hasTouch ? "true" : "false");
|
|
281
|
+
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* The default value is `false`. Set to `true` if the viewport is in landscape mode.
|
|
287
|
+
*/
|
|
288
|
+
viewportLandscape(landscape: boolean): TakeOptions {
|
|
289
|
+
this.put("viewport_landscape", landscape ? "true" : "false");
|
|
290
|
+
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
|
|
180
294
|
/**
|
|
181
295
|
* Sets geolocation latitude for the request.
|
|
182
296
|
* Both latitude and longitude are required if one of them is set.
|
|
@@ -214,6 +328,24 @@ export class TakeOptions {
|
|
|
214
328
|
return this;
|
|
215
329
|
}
|
|
216
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Blocks cookie banners.
|
|
333
|
+
*/
|
|
334
|
+
blockCookieBanners(block: boolean): TakeOptions {
|
|
335
|
+
this.put("block_cookie_banners", block ? "true" : "false");
|
|
336
|
+
|
|
337
|
+
return this;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Blocks chats.
|
|
342
|
+
*/
|
|
343
|
+
blockChats(block: boolean): TakeOptions {
|
|
344
|
+
this.put("block_chats", block ? "true" : "false");
|
|
345
|
+
|
|
346
|
+
return this;
|
|
347
|
+
}
|
|
348
|
+
|
|
217
349
|
/**
|
|
218
350
|
* Blocks trackers.
|
|
219
351
|
*/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TakeOptions, Client } from '../src/main';
|
|
2
|
+
|
|
3
|
+
describe('testing client', () => {
|
|
4
|
+
const client = new Client('RcLsdM6uhIN6gw', 'MW2vfkkgLTzGGw');
|
|
5
|
+
|
|
6
|
+
test('example.com with block ads URL generated and signed correctly', () => {
|
|
7
|
+
const options = TakeOptions.url('https://example.com').blockAds(true);
|
|
8
|
+
|
|
9
|
+
expect(client.generateTakeURL(options)).toBe('https://api.screenshotone.com/take?url=https%3A%2F%2Fexample.com&block_ads=true&access_key=RcLsdM6uhIN6gw&signature=3cf1edeafc139f41191928c1c5b8b04fe1d5722560244ccdd76a55d69120bbac');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('example.com with block ads, full page and user agent URL generated and signed correctly', () => {
|
|
13
|
+
const options = TakeOptions
|
|
14
|
+
.url('https://example.com')
|
|
15
|
+
.blockAds(true)
|
|
16
|
+
.fullPage(true)
|
|
17
|
+
.userAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36');
|
|
18
|
+
|
|
19
|
+
expect(client.generateTakeURL(options)).toBe('https://api.screenshotone.com/take?url=https%3A%2F%2Fexample.com&block_ads=true&full_page=true&user_agent=Mozilla%2F5.0+%28X11%3B+Linux+x86_64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F51.0.2704.103+Safari%2F537.36&access_key=RcLsdM6uhIN6gw&signature=ea217db7d746c8bf9b710257d62ef09670b003137d239ee4c81eae3645b4a901');
|
|
20
|
+
});
|
|
21
|
+
});
|