screenshotone-api-sdk 1.0.14 → 1.0.17

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/main.js CHANGED
@@ -1,315 +1,263 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
36
7
  }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
37
24
  };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
27
  };
47
28
  Object.defineProperty(exports, "__esModule", { value: true });
48
29
  exports.TakeOptions = exports.Client = void 0;
49
- var crypto = require("crypto");
50
- var big_js_1 = require("big.js");
51
- var cross_fetch_1 = require("cross-fetch");
30
+ const crypto = __importStar(require("crypto"));
31
+ const big_js_1 = __importDefault(require("big.js"));
32
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
33
+ const API_BASE_URL = "https://api.screenshotone.com";
34
+ const API_TAKE_PATH = "/take";
52
35
  /**
53
36
  * Represents an API client for the screenshotone.com API.
54
37
  */
55
- var Client = /** @class */ (function () {
56
- function Client(accessKey, secretKey) {
57
- this.API_BASE_URL = "https://api.screenshotone.com";
58
- this.API_TAKE_PATH = "/take";
38
+ class Client {
39
+ constructor(accessKey, secretKey) {
59
40
  this.accessKey = accessKey;
60
41
  this.secretKey = secretKey;
61
42
  }
62
- Client.prototype.generateTakeURL = function (options) {
63
- var query = options.toQuery();
43
+ generateTakeURL(options) {
44
+ const query = options.toQuery();
64
45
  query.append("access_key", this.accessKey);
65
- var queryString = query.toString();
66
- var signature = crypto.createHmac("sha256", this.secretKey)
46
+ let queryString = query.toString();
47
+ const signature = crypto.createHmac("sha256", this.secretKey)
67
48
  .update(queryString, 'utf-8')
68
49
  .digest('hex');
69
50
  queryString += '&signature=' + signature;
70
- return "".concat(this.API_BASE_URL).concat(this.API_TAKE_PATH, "?").concat(queryString);
71
- };
72
- Client.prototype.take = function (options) {
73
- return __awaiter(this, void 0, void 0, function () {
74
- var url, response;
75
- return __generator(this, function (_a) {
76
- switch (_a.label) {
77
- case 0:
78
- url = this.generateTakeURL(options);
79
- return [4 /*yield*/, (0, cross_fetch_1.default)(url)];
80
- case 1:
81
- response = _a.sent();
82
- if (!response.ok) return [3 /*break*/, 3];
83
- return [4 /*yield*/, response.blob()];
84
- case 2: return [2 /*return*/, _a.sent()];
85
- case 3: throw new Error("failed to take screenshot, response returned ".concat(response.status, " ").concat(response.statusText));
86
- }
87
- });
88
- });
89
- };
90
- return Client;
91
- }());
51
+ return `${API_BASE_URL}${API_TAKE_PATH}?${queryString}`;
52
+ }
53
+ async take(options) {
54
+ const url = this.generateTakeURL(options);
55
+ const response = await (0, cross_fetch_1.default)(url);
56
+ if (response.ok) {
57
+ return await response.blob();
58
+ }
59
+ const data = await response.json();
60
+ throw new Error(`failed to take screenshot, response returned ${response.status} ${response.statusText}: ${data?.message}`);
61
+ }
62
+ }
92
63
  exports.Client = Client;
93
64
  /**
94
65
  * Represents options for taking screenshots.
95
66
  */
96
- var TakeOptions = /** @class */ (function () {
97
- function TakeOptions(url) {
98
- var query = new URLSearchParams();
67
+ class TakeOptions {
68
+ constructor(url) {
69
+ const query = new URLSearchParams();
99
70
  query.append("url", url);
100
71
  this.query = query;
101
72
  }
102
73
  /**
103
74
  * Initializes take screenshot options with provided website URL.
104
75
  */
105
- TakeOptions.url = function (url) {
76
+ static url(url) {
106
77
  return new TakeOptions(url);
107
- };
108
- TakeOptions.prototype.put = function (key) {
109
- var values = [];
110
- for (var _i = 1; _i < arguments.length; _i++) {
111
- values[_i - 1] = arguments[_i];
112
- }
113
- for (var _a = 0, values_1 = values; _a < values_1.length; _a++) {
114
- var value = values_1[_a];
78
+ }
79
+ put(key, ...values) {
80
+ for (const value of values) {
115
81
  this.query.append(key, value);
116
82
  }
117
- };
83
+ }
118
84
  ;
119
85
  /**
120
86
  * Renders the full page.
121
87
  */
122
- TakeOptions.prototype.fullPage = function (fullPage) {
88
+ fullPage(fullPage) {
123
89
  this.put("full_page", fullPage ? "true" : "false");
124
90
  return this;
125
- };
91
+ }
126
92
  /**
127
93
  * Sets response format, one of: "png", "jpeg", "webp" or "jpg".
128
94
  */
129
- TakeOptions.prototype.format = function (format) {
95
+ format(format) {
130
96
  this.put("format", format);
131
97
  return this;
132
- };
98
+ }
133
99
  /**
134
100
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
135
101
  */
136
- TakeOptions.prototype.imageQuality = function (imageQuality) {
102
+ imageQuality(imageQuality) {
137
103
  this.put("image_quality", imageQuality.toString());
138
104
  return this;
139
- };
105
+ }
140
106
  /**
141
107
  * Renders a transparent background for the image. Works only if the site has not defined background color.
142
108
  * Available for the following response formats: "png", "webp".
143
109
  */
144
- TakeOptions.prototype.omitBackground = function (omitBackground) {
110
+ omitBackground(omitBackground) {
145
111
  this.put("omit_background", omitBackground ? "true" : "false");
146
112
  return this;
147
- };
113
+ }
148
114
  /**
149
115
  * Sets the width of the browser viewport (pixels).
150
116
  */
151
- TakeOptions.prototype.viewportWidth = function (viewportWidth) {
117
+ viewportWidth(viewportWidth) {
152
118
  this.put("viewport_width", viewportWidth.toString());
153
119
  return this;
154
- };
120
+ }
155
121
  /**
156
122
  * Sets the height of the browser viewport (pixels).
157
123
  */
158
- TakeOptions.prototype.viewportHeight = function (viewportHeight) {
124
+ viewportHeight(viewportHeight) {
159
125
  this.put("viewport_height", viewportHeight.toString());
160
126
  return this;
161
- };
127
+ }
162
128
  /**
163
129
  * Sets the device scale factor. Acceptable value is one of: 1, 2 or 3.
164
130
  */
165
- TakeOptions.prototype.deviceScaleFactor = function (deviceScaleFactor) {
131
+ deviceScaleFactor(deviceScaleFactor) {
166
132
  this.put("device_scale_factor", deviceScaleFactor.toString());
167
133
  return this;
168
- };
134
+ }
169
135
  /**
170
136
  * Sets geolocation latitude for the request.
171
137
  * Both latitude and longitude are required if one of them is set.
172
138
  */
173
- TakeOptions.prototype.geolocationLatitude = function (latitude) {
139
+ geolocationLatitude(latitude) {
174
140
  this.put("geolocation_latitude", new big_js_1.default(latitude).toFixed(20).replace(/0+$/, ""));
175
141
  return this;
176
- };
142
+ }
177
143
  /**
178
144
  * Sets geolocation longitude for the request. Both latitude and longitude are required if one of them is set.
179
145
  */
180
- TakeOptions.prototype.geolocationLongitude = function (longitude) {
146
+ geolocationLongitude(longitude) {
181
147
  this.put("geolocation_longitude", new big_js_1.default(longitude).toFixed(20).replace(/0+$/, ""));
182
148
  return this;
183
- };
149
+ }
184
150
  /**
185
151
  * Sets the geolocation accuracy in meters.
186
152
  */
187
- TakeOptions.prototype.geolocationAccuracy = function (accuracy) {
153
+ geolocationAccuracy(accuracy) {
188
154
  this.put("geolocation_accuracy", accuracy.toString());
189
155
  return this;
190
- };
156
+ }
191
157
  /**
192
158
  * Blocks ads.
193
159
  */
194
- TakeOptions.prototype.blockAds = function (blockAds) {
160
+ blockAds(blockAds) {
195
161
  this.put("block_ads", blockAds ? "true" : "false");
196
162
  return this;
197
- };
163
+ }
198
164
  /**
199
165
  * Blocks trackers.
200
166
  */
201
- TakeOptions.prototype.blockTrackers = function (blockTrackers) {
167
+ blockTrackers(blockTrackers) {
202
168
  this.put("block_trackers", blockTrackers ? "true" : "false");
203
169
  return this;
204
- };
170
+ }
205
171
  /**
206
172
  * Blocks requests by specifying URL, domain, or even a simple pattern.
207
173
  */
208
- TakeOptions.prototype.blockRequests = function () {
209
- var blockRequests = [];
210
- for (var _i = 0; _i < arguments.length; _i++) {
211
- blockRequests[_i] = arguments[_i];
212
- }
213
- this.put.apply(this, __spreadArray(["block_requests"], blockRequests, false));
174
+ blockRequests(...blockRequests) {
175
+ this.put("block_requests", ...blockRequests);
214
176
  return this;
215
- };
177
+ }
216
178
  /**
217
179
  * Blocks loading resources by type. Available resource types are: "document", "stylesheet", "image", "media",
218
180
  * "font", "script", "texttrack", "xhr", "fetch", "eventsource", "websocket", "manifest", "other".
219
181
  */
220
- TakeOptions.prototype.blockResources = function () {
221
- var blockResources = [];
222
- for (var _i = 0; _i < arguments.length; _i++) {
223
- blockResources[_i] = arguments[_i];
224
- }
225
- this.put.apply(this, __spreadArray(["block_resources"], blockResources, false));
182
+ blockResources(...blockResources) {
183
+ this.put("block_resources", ...blockResources);
226
184
  return this;
227
- };
185
+ }
228
186
  /**
229
187
  * Enables caching.
230
188
  */
231
- TakeOptions.prototype.cache = function (cache) {
189
+ cache(cache) {
232
190
  this.put("cache", cache ? "true" : "false");
233
191
  return this;
234
- };
192
+ }
235
193
  /**
236
194
  * Sets cache TTL.
237
195
  */
238
- TakeOptions.prototype.cacheTtl = function (cacheTTL) {
196
+ cacheTtl(cacheTTL) {
239
197
  this.put("cache_ttl", cacheTTL.toString());
240
198
  return this;
241
- };
199
+ }
242
200
  /**
243
201
  * Sets cache key.
244
202
  */
245
- TakeOptions.prototype.cacheKey = function (cacheKey) {
203
+ cacheKey(cacheKey) {
246
204
  this.put("cache_key", cacheKey);
247
205
  return this;
248
- };
206
+ }
249
207
  /**
250
208
  * Sets a user agent for the request.
251
209
  */
252
- TakeOptions.prototype.userAgent = function (userAgent) {
210
+ userAgent(userAgent) {
253
211
  this.put("user_agent", userAgent);
254
212
  return this;
255
- };
213
+ }
256
214
  /**
257
215
  * Sets an authorization header for the request.
258
216
  */
259
- TakeOptions.prototype.authorization = function (authorization) {
217
+ authorization(authorization) {
260
218
  this.put("authorization", authorization);
261
219
  return this;
262
- };
220
+ }
263
221
  /**
264
222
  * Set cookies for the request.
265
223
  */
266
- TakeOptions.prototype.cookies = function () {
267
- var cookies = [];
268
- for (var _i = 0; _i < arguments.length; _i++) {
269
- cookies[_i] = arguments[_i];
270
- }
271
- this.put.apply(this, __spreadArray(["cookies"], cookies, false));
224
+ cookies(...cookies) {
225
+ this.put("cookies", ...cookies);
272
226
  return this;
273
- };
227
+ }
274
228
  /**
275
229
  * Sets extra headers for the request.
276
230
  */
277
- TakeOptions.prototype.headers = function () {
278
- var headers = [];
279
- for (var _i = 0; _i < arguments.length; _i++) {
280
- headers[_i] = arguments[_i];
281
- }
282
- this.put.apply(this, __spreadArray(["headers"], headers, false));
231
+ headers(...headers) {
232
+ this.put("headers", ...headers);
283
233
  return this;
284
- };
234
+ }
285
235
  /**
286
236
  * TimeZone sets time zone for the request.
287
237
  * Available time zones are: "America/Santiago", "Asia/Shanghai", "Europe/Berlin", "America/Guayaquil",
288
238
  * "Europe/Madrid", "Pacific/Majuro", "Asia/Kuala_Lumpur", "Pacific/Auckland", "Europe/Lisbon", "Europe/Kiev",
289
239
  * "Asia/Tashkent", "Europe/London".
290
240
  */
291
- TakeOptions.prototype.timeZone = function (timeZone) {
241
+ timeZone(timeZone) {
292
242
  this.put("time_zone", timeZone);
293
243
  return this;
294
- };
244
+ }
295
245
  /**
296
246
  * Sets delay.
297
247
  */
298
- TakeOptions.prototype.delay = function (delay) {
248
+ delay(delay) {
299
249
  this.put("delay", delay.toString());
300
250
  return this;
301
- };
251
+ }
302
252
  /**
303
253
  * Sets timeout.
304
254
  */
305
- TakeOptions.prototype.timeout = function (timeout) {
255
+ timeout(timeout) {
306
256
  this.put("timeout", timeout.toString());
307
257
  return this;
308
- };
309
- TakeOptions.prototype.toQuery = function () {
258
+ }
259
+ toQuery() {
310
260
  return new URLSearchParams(this.query.toString());
311
- };
312
- return TakeOptions;
313
- }());
261
+ }
262
+ }
314
263
  exports.TakeOptions = TakeOptions;
315
- //# sourceMappingURL=main.js.map
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.14",
4
+ "version": "1.0.17",
5
5
  "description": "Use ScreenshotOne.com API to generate screenshots of any website.",
6
6
  "repository": {
7
7
  "type": "git",
@@ -29,7 +29,6 @@
29
29
  },
30
30
  "main": "dist/main.js",
31
31
  "types": "dist/@types/main.d.ts",
32
- "type": "module",
33
32
  "devDependencies": {
34
33
  "@types/big.js": "^6.1.3",
35
34
  "@types/node": "^17.0.40",
package/src/main.ts CHANGED
@@ -2,13 +2,13 @@ import * as crypto from 'crypto';
2
2
  import Big from 'big.js';
3
3
  import fetch from 'cross-fetch';
4
4
 
5
+ const API_BASE_URL = "https://api.screenshotone.com";
6
+ const API_TAKE_PATH = "/take";
7
+
5
8
  /**
6
9
  * Represents an API client for the screenshotone.com API.
7
10
  */
8
11
  export class Client {
9
- private readonly API_BASE_URL = "https://api.screenshotone.com";
10
- private readonly API_TAKE_PATH = "/take";
11
-
12
12
  private readonly accessKey: string;
13
13
  private readonly secretKey: string;
14
14
 
@@ -27,7 +27,7 @@ export class Client {
27
27
  .digest('hex');
28
28
  queryString += '&signature=' + signature;
29
29
 
30
- return `${this.API_BASE_URL}${this.API_TAKE_PATH}?${queryString}`;
30
+ return `${API_BASE_URL}${API_TAKE_PATH}?${queryString}`;
31
31
  }
32
32
 
33
33
  async take(options: TakeOptions): Promise<Blob> {
@@ -37,7 +37,9 @@ export class Client {
37
37
  return await response.blob()
38
38
  }
39
39
 
40
- throw new Error(`failed to take screenshot, response returned ${response.status} ${response.statusText}`);
40
+ const data = await response.json();
41
+
42
+ throw new Error(`failed to take screenshot, response returned ${response.status} ${response.statusText}: ${data?.message}`);
41
43
  }
42
44
  }
43
45
 
package/tsconfig.json CHANGED
@@ -8,7 +8,10 @@
8
8
  "strict": true,
9
9
  "esModuleInterop": true,
10
10
  "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true
11
+ "forceConsistentCasingInFileNames": true,
12
+ "outDir": "dist",
13
+ "declarationDir": "dist/@types",
14
+ "declaration": true,
12
15
  },
13
16
  "include": [
14
17
  "src/**/*"
package/src/main.js DELETED
@@ -1,262 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.TakeOptions = exports.Client = void 0;
30
- const crypto = __importStar(require("crypto"));
31
- const big_js_1 = __importDefault(require("big.js"));
32
- const cross_fetch_1 = __importDefault(require("cross-fetch"));
33
- /**
34
- * Represents an API client for the screenshotone.com API.
35
- */
36
- class Client {
37
- constructor(accessKey, secretKey) {
38
- this.API_BASE_URL = "https://api.screenshotone.com";
39
- this.API_TAKE_PATH = "/take";
40
- this.accessKey = accessKey;
41
- this.secretKey = secretKey;
42
- }
43
- generateTakeURL(options) {
44
- const query = options.toQuery();
45
- query.append("access_key", this.accessKey);
46
- let queryString = query.toString();
47
- const signature = crypto.createHmac("sha256", this.secretKey)
48
- .update(queryString, 'utf-8')
49
- .digest('hex');
50
- queryString += '&signature=' + signature;
51
- return `${this.API_BASE_URL}${this.API_TAKE_PATH}?${queryString}`;
52
- }
53
- async take(options) {
54
- const url = this.generateTakeURL(options);
55
- const response = await (0, cross_fetch_1.default)(url);
56
- if (response.ok) {
57
- return await response.blob();
58
- }
59
- throw new Error(`failed to take screenshot, response returned ${response.status} ${response.statusText}`);
60
- }
61
- }
62
- exports.Client = Client;
63
- /**
64
- * Represents options for taking screenshots.
65
- */
66
- class TakeOptions {
67
- constructor(url) {
68
- const query = new URLSearchParams();
69
- query.append("url", url);
70
- this.query = query;
71
- }
72
- /**
73
- * Initializes take screenshot options with provided website URL.
74
- */
75
- static url(url) {
76
- return new TakeOptions(url);
77
- }
78
- put(key, ...values) {
79
- for (const value of values) {
80
- this.query.append(key, value);
81
- }
82
- }
83
- ;
84
- /**
85
- * Renders the full page.
86
- */
87
- fullPage(fullPage) {
88
- this.put("full_page", fullPage ? "true" : "false");
89
- return this;
90
- }
91
- /**
92
- * Sets response format, one of: "png", "jpeg", "webp" or "jpg".
93
- */
94
- format(format) {
95
- this.put("format", format);
96
- return this;
97
- }
98
- /**
99
- * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
100
- */
101
- imageQuality(imageQuality) {
102
- this.put("image_quality", imageQuality.toString());
103
- return this;
104
- }
105
- /**
106
- * Renders a transparent background for the image. Works only if the site has not defined background color.
107
- * Available for the following response formats: "png", "webp".
108
- */
109
- omitBackground(omitBackground) {
110
- this.put("omit_background", omitBackground ? "true" : "false");
111
- return this;
112
- }
113
- /**
114
- * Sets the width of the browser viewport (pixels).
115
- */
116
- viewportWidth(viewportWidth) {
117
- this.put("viewport_width", viewportWidth.toString());
118
- return this;
119
- }
120
- /**
121
- * Sets the height of the browser viewport (pixels).
122
- */
123
- viewportHeight(viewportHeight) {
124
- this.put("viewport_height", viewportHeight.toString());
125
- return this;
126
- }
127
- /**
128
- * Sets the device scale factor. Acceptable value is one of: 1, 2 or 3.
129
- */
130
- deviceScaleFactor(deviceScaleFactor) {
131
- this.put("device_scale_factor", deviceScaleFactor.toString());
132
- return this;
133
- }
134
- /**
135
- * Sets geolocation latitude for the request.
136
- * Both latitude and longitude are required if one of them is set.
137
- */
138
- geolocationLatitude(latitude) {
139
- this.put("geolocation_latitude", new big_js_1.default(latitude).toFixed(20).replace(/0+$/, ""));
140
- return this;
141
- }
142
- /**
143
- * Sets geolocation longitude for the request. Both latitude and longitude are required if one of them is set.
144
- */
145
- geolocationLongitude(longitude) {
146
- this.put("geolocation_longitude", new big_js_1.default(longitude).toFixed(20).replace(/0+$/, ""));
147
- return this;
148
- }
149
- /**
150
- * Sets the geolocation accuracy in meters.
151
- */
152
- geolocationAccuracy(accuracy) {
153
- this.put("geolocation_accuracy", accuracy.toString());
154
- return this;
155
- }
156
- /**
157
- * Blocks ads.
158
- */
159
- blockAds(blockAds) {
160
- this.put("block_ads", blockAds ? "true" : "false");
161
- return this;
162
- }
163
- /**
164
- * Blocks trackers.
165
- */
166
- blockTrackers(blockTrackers) {
167
- this.put("block_trackers", blockTrackers ? "true" : "false");
168
- return this;
169
- }
170
- /**
171
- * Blocks requests by specifying URL, domain, or even a simple pattern.
172
- */
173
- blockRequests(...blockRequests) {
174
- this.put("block_requests", ...blockRequests);
175
- return this;
176
- }
177
- /**
178
- * Blocks loading resources by type. Available resource types are: "document", "stylesheet", "image", "media",
179
- * "font", "script", "texttrack", "xhr", "fetch", "eventsource", "websocket", "manifest", "other".
180
- */
181
- blockResources(...blockResources) {
182
- this.put("block_resources", ...blockResources);
183
- return this;
184
- }
185
- /**
186
- * Enables caching.
187
- */
188
- cache(cache) {
189
- this.put("cache", cache ? "true" : "false");
190
- return this;
191
- }
192
- /**
193
- * Sets cache TTL.
194
- */
195
- cacheTtl(cacheTTL) {
196
- this.put("cache_ttl", cacheTTL.toString());
197
- return this;
198
- }
199
- /**
200
- * Sets cache key.
201
- */
202
- cacheKey(cacheKey) {
203
- this.put("cache_key", cacheKey);
204
- return this;
205
- }
206
- /**
207
- * Sets a user agent for the request.
208
- */
209
- userAgent(userAgent) {
210
- this.put("user_agent", userAgent);
211
- return this;
212
- }
213
- /**
214
- * Sets an authorization header for the request.
215
- */
216
- authorization(authorization) {
217
- this.put("authorization", authorization);
218
- return this;
219
- }
220
- /**
221
- * Set cookies for the request.
222
- */
223
- cookies(...cookies) {
224
- this.put("cookies", ...cookies);
225
- return this;
226
- }
227
- /**
228
- * Sets extra headers for the request.
229
- */
230
- headers(...headers) {
231
- this.put("headers", ...headers);
232
- return this;
233
- }
234
- /**
235
- * TimeZone sets time zone for the request.
236
- * Available time zones are: "America/Santiago", "Asia/Shanghai", "Europe/Berlin", "America/Guayaquil",
237
- * "Europe/Madrid", "Pacific/Majuro", "Asia/Kuala_Lumpur", "Pacific/Auckland", "Europe/Lisbon", "Europe/Kiev",
238
- * "Asia/Tashkent", "Europe/London".
239
- */
240
- timeZone(timeZone) {
241
- this.put("time_zone", timeZone);
242
- return this;
243
- }
244
- /**
245
- * Sets delay.
246
- */
247
- delay(delay) {
248
- this.put("delay", delay.toString());
249
- return this;
250
- }
251
- /**
252
- * Sets timeout.
253
- */
254
- timeout(timeout) {
255
- this.put("timeout", timeout.toString());
256
- return this;
257
- }
258
- toQuery() {
259
- return new URLSearchParams(this.query.toString());
260
- }
261
- }
262
- exports.TakeOptions = TakeOptions;