scrapfly-sdk 0.10.3 → 0.10.5
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/esm/browserconfig.d.ts +70 -1
- package/esm/browserconfig.d.ts.map +1 -1
- package/esm/browserconfig.js +44 -1
- package/esm/client.d.ts +33 -0
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js +33 -5
- package/esm/crawl.d.ts +4 -0
- package/esm/crawl.d.ts.map +1 -1
- package/esm/crawl.js +4 -0
- package/esm/crawlerresult.d.ts +7 -0
- package/esm/crawlerresult.d.ts.map +1 -1
- package/esm/errors.d.ts +43 -0
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +43 -16
- package/esm/extractionconfig.d.ts +54 -9
- package/esm/extractionconfig.d.ts.map +1 -1
- package/esm/extractionconfig.js +37 -13
- package/esm/logger.d.ts +1 -0
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +1 -0
- package/esm/main.d.ts +27 -0
- package/esm/main.d.ts.map +1 -1
- package/esm/main.js +27 -0
- package/esm/monitoringconfig.d.ts +48 -11
- package/esm/monitoringconfig.d.ts.map +1 -1
- package/esm/monitoringconfig.js +14 -0
- package/esm/result.d.ts +2 -0
- package/esm/result.d.ts.map +1 -1
- package/esm/scrapeconfig.d.ts +10 -8
- package/esm/scrapeconfig.d.ts.map +1 -1
- package/esm/scrapeconfig.js +10 -8
- package/esm/screenshotconfig.d.ts +59 -26
- package/esm/screenshotconfig.d.ts.map +1 -1
- package/esm/screenshotconfig.js +38 -26
- package/esm/webhookserver.d.ts +24 -0
- package/esm/webhookserver.d.ts.map +1 -1
- package/esm/webhookserver.js +24 -0
- package/package.json +1 -1
- package/script/browserconfig.d.ts +70 -1
- package/script/browserconfig.d.ts.map +1 -1
- package/script/browserconfig.js +44 -1
- package/script/client.d.ts +33 -0
- package/script/client.d.ts.map +1 -1
- package/script/client.js +33 -5
- package/script/crawl.d.ts +4 -0
- package/script/crawl.d.ts.map +1 -1
- package/script/crawl.js +4 -0
- package/script/crawlerresult.d.ts +7 -0
- package/script/crawlerresult.d.ts.map +1 -1
- package/script/errors.d.ts +43 -0
- package/script/errors.d.ts.map +1 -1
- package/script/errors.js +43 -16
- package/script/extractionconfig.d.ts +54 -9
- package/script/extractionconfig.d.ts.map +1 -1
- package/script/extractionconfig.js +37 -13
- package/script/logger.d.ts +1 -0
- package/script/logger.d.ts.map +1 -1
- package/script/logger.js +1 -0
- package/script/main.d.ts +27 -0
- package/script/main.d.ts.map +1 -1
- package/script/main.js +27 -0
- package/script/monitoringconfig.d.ts +48 -11
- package/script/monitoringconfig.d.ts.map +1 -1
- package/script/monitoringconfig.js +14 -0
- package/script/result.d.ts +2 -0
- package/script/result.d.ts.map +1 -1
- package/script/scrapeconfig.d.ts +10 -8
- package/script/scrapeconfig.d.ts.map +1 -1
- package/script/scrapeconfig.js +10 -8
- package/script/screenshotconfig.d.ts +59 -26
- package/script/screenshotconfig.d.ts.map +1 -1
- package/script/screenshotconfig.js +38 -26
- package/script/webhookserver.d.ts +24 -0
- package/script/webhookserver.d.ts.map +1 -1
- package/script/webhookserver.js +24 -0
- package/src/_dnt.shims.ts +64 -0
- package/src/batch.ts +272 -0
- package/src/browserconfig.ts +187 -0
- package/src/client.ts +1637 -0
- package/src/crawl.ts +255 -0
- package/src/crawlerconfig.ts +363 -0
- package/src/crawlerresult.ts +478 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/assert_path.ts +10 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/basename.ts +53 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/common.ts +26 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/constants.ts +49 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/dirname.ts +9 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/format.ts +25 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/from_file_url.ts +10 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/glob_to_reg_exp.ts +290 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/normalize.ts +9 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/normalize_string.ts +74 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/relative.ts +10 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/strip_trailing_separators.ts +25 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/to_file_url.ts +17 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_os.ts +31 -0
- package/src/deps/jsr.io/@std/path/1.0.1/basename.ts +35 -0
- package/src/deps/jsr.io/@std/path/1.0.1/common.ts +35 -0
- package/src/deps/jsr.io/@std/path/1.0.1/constants.ts +18 -0
- package/src/deps/jsr.io/@std/path/1.0.1/dirname.ts +28 -0
- package/src/deps/jsr.io/@std/path/1.0.1/extname.ts +27 -0
- package/src/deps/jsr.io/@std/path/1.0.1/format.ts +30 -0
- package/src/deps/jsr.io/@std/path/1.0.1/from_file_url.ts +30 -0
- package/src/deps/jsr.io/@std/path/1.0.1/glob_to_regexp.ts +94 -0
- package/src/deps/jsr.io/@std/path/1.0.1/is_absolute.ts +30 -0
- package/src/deps/jsr.io/@std/path/1.0.1/is_glob.ts +49 -0
- package/src/deps/jsr.io/@std/path/1.0.1/join.ts +28 -0
- package/src/deps/jsr.io/@std/path/1.0.1/join_globs.ts +42 -0
- package/src/deps/jsr.io/@std/path/1.0.1/mod.ts +55 -0
- package/src/deps/jsr.io/@std/path/1.0.1/normalize.ts +31 -0
- package/src/deps/jsr.io/@std/path/1.0.1/normalize_glob.ts +45 -0
- package/src/deps/jsr.io/@std/path/1.0.1/parse.ts +44 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/_util.ts +10 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/basename.ts +39 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/constants.ts +15 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/dirname.ts +55 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/extname.ts +73 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/format.ts +31 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/from_file_url.ts +25 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/glob_to_regexp.ts +94 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/is_absolute.ts +25 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/join.ts +27 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/join_globs.ts +44 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/normalize.ts +41 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/normalize_glob.ts +42 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/parse.ts +121 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/relative.ts +103 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/resolve.ts +69 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/to_file_url.ts +32 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/to_namespaced_path.ts +21 -0
- package/src/deps/jsr.io/@std/path/1.0.1/relative.ts +32 -0
- package/src/deps/jsr.io/@std/path/1.0.1/resolve.ts +32 -0
- package/src/deps/jsr.io/@std/path/1.0.1/to_file_url.ts +30 -0
- package/src/deps/jsr.io/@std/path/1.0.1/to_namespaced_path.ts +31 -0
- package/src/deps/jsr.io/@std/path/1.0.1/types.ts +40 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/_util.ts +28 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/basename.ts +48 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/constants.ts +15 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/dirname.ts +114 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/extname.ts +86 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/format.ts +31 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/from_file_url.ts +34 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/glob_to_regexp.ts +92 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/is_absolute.ts +40 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/join.ts +72 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/join_globs.ts +45 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/normalize.ts +132 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/normalize_glob.ts +42 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/parse.ts +184 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/relative.ts +128 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/resolve.ts +174 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/to_file_url.ts +38 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/to_namespaced_path.ts +60 -0
- package/src/deps.ts +4 -0
- package/src/errors.ts +82 -0
- package/src/extractionconfig.ts +217 -0
- package/src/logger.ts +53 -0
- package/src/main.ts +88 -0
- package/src/monitoringconfig.ts +88 -0
- package/src/polyfill.ts +37 -0
- package/src/result.ts +340 -0
- package/src/scrapeconfig.ts +450 -0
- package/src/screenshotconfig.ts +237 -0
- package/src/types.ts +2 -0
- package/src/utils.ts +86 -0
- package/src/webhookserver.ts +90 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { urlsafe_b64encode } from './utils.js';
|
|
2
|
+
import { log } from './logger.js';
|
|
3
|
+
import type { HttpMethod, Rec } from './types.js';
|
|
4
|
+
import { ScrapeConfigError } from './errors.js';
|
|
5
|
+
|
|
6
|
+
export enum ScreenshotFlags {
|
|
7
|
+
/**
|
|
8
|
+
Options to customize the screenshot behavior
|
|
9
|
+
Attributes:
|
|
10
|
+
LOAD_IMAGES: Enable image rendering with the request, add extra usage for the bandwidth consumed.
|
|
11
|
+
DARK_MODE: Enable dark mode display.
|
|
12
|
+
BLOCK_BANNERS: Block cookies banners and overlay that cover the screen.
|
|
13
|
+
PRINT_MEDIA_FORMAT: Render the page in the print mode.
|
|
14
|
+
*/
|
|
15
|
+
LOAD_IMAGES = 'load_images',
|
|
16
|
+
DARK_MODE = 'dark_mode',
|
|
17
|
+
BLOCK_BANNERS = 'block_banners',
|
|
18
|
+
PRINT_MEDIA_FORMAT = 'print_media_format',
|
|
19
|
+
HIGH_QUALITY = 'high_quality',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Output format requested for the scraped content. */
|
|
23
|
+
export enum Format {
|
|
24
|
+
/** Structured JSON. */
|
|
25
|
+
JSON = 'json',
|
|
26
|
+
/** Plain text with markup stripped. */
|
|
27
|
+
TEXT = 'text',
|
|
28
|
+
/** Markdown rendering of the page. */
|
|
29
|
+
MARKDOWN = 'markdown',
|
|
30
|
+
/** Readability-cleaned HTML. */
|
|
31
|
+
CLEAN_HTML = 'clean_html',
|
|
32
|
+
/** Raw HTML as returned by the target. */
|
|
33
|
+
RAW = 'raw',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Additional filters applied to the chosen {@link Format}. */
|
|
37
|
+
export enum FormatOption {
|
|
38
|
+
/** Strip hyperlinks from the output. */
|
|
39
|
+
NO_LINKS = 'no_links',
|
|
40
|
+
/** Strip images from the output. */
|
|
41
|
+
NO_IMAGES = 'no_images',
|
|
42
|
+
/** Keep only the "content" section (drop navigation, sidebars, footers). */
|
|
43
|
+
ONLY_CONTENT = 'only_content',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type ScrapeConfigOptions = {
|
|
47
|
+
url: string;
|
|
48
|
+
retry?: boolean;
|
|
49
|
+
method?: HttpMethod;
|
|
50
|
+
country?: string;
|
|
51
|
+
render_js?: boolean;
|
|
52
|
+
cache?: boolean;
|
|
53
|
+
cache_clear?: boolean;
|
|
54
|
+
cost_budget?: number;
|
|
55
|
+
ssl?: boolean;
|
|
56
|
+
dns?: boolean;
|
|
57
|
+
asp?: boolean;
|
|
58
|
+
debug?: boolean;
|
|
59
|
+
raise_on_upstream_error?: boolean;
|
|
60
|
+
cache_ttl?: number;
|
|
61
|
+
proxy_pool?: string;
|
|
62
|
+
session?: string;
|
|
63
|
+
tags?: string[];
|
|
64
|
+
format?: 'json' | 'text' | 'markdown' | 'clean_html' | 'raw' | Format;
|
|
65
|
+
format_options?: ('no_links' | 'no_images' | 'only_content' | FormatOption)[];
|
|
66
|
+
extraction_template?: string; // saved template name
|
|
67
|
+
extraction_ephemeral_template?: object; // ephemeraly declared json template
|
|
68
|
+
extraction_prompt?: string;
|
|
69
|
+
extraction_model?: string;
|
|
70
|
+
correlation_id?: string;
|
|
71
|
+
cookies?: Rec<string>;
|
|
72
|
+
body?: string;
|
|
73
|
+
data?: Rec<any>;
|
|
74
|
+
headers?: Rec<string>;
|
|
75
|
+
js?: string;
|
|
76
|
+
rendering_wait?: number;
|
|
77
|
+
wait_for_selector?: string;
|
|
78
|
+
screenshots?: Rec<any>;
|
|
79
|
+
screenshot_flags?:
|
|
80
|
+
('load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags)[];
|
|
81
|
+
session_sticky_proxy?: boolean;
|
|
82
|
+
webhook?: string;
|
|
83
|
+
timeout?: number;
|
|
84
|
+
js_scenario?: Rec<any>;
|
|
85
|
+
os?: string;
|
|
86
|
+
lang?: string[];
|
|
87
|
+
auto_scroll?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Chromium-based browser brand used for fingerprint generation.
|
|
90
|
+
* One of "chrome" | "edge" | "brave" | "opera". Defaults to "chrome"
|
|
91
|
+
* when omitted. Invalid values are silently dropped by the server.
|
|
92
|
+
*/
|
|
93
|
+
browser_brand?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Return the raw upstream response (target's status, headers, body)
|
|
96
|
+
* instead of the JSON envelope. When true, ScrapflyClient.scrape()
|
|
97
|
+
* returns the raw fetch Response so callers can drive it like any
|
|
98
|
+
* HTTP response. Scrapfly metadata is on the X-Scrapfly-* headers.
|
|
99
|
+
*/
|
|
100
|
+
proxified_response?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Controls when the browser considers the page loaded.
|
|
103
|
+
* "complete" (default) or "domcontentloaded" for faster scrapes.
|
|
104
|
+
*/
|
|
105
|
+
rendering_stage?: 'complete' | 'domcontentloaded';
|
|
106
|
+
/**
|
|
107
|
+
* Spoof browser geolocation. Format: "latitude,longitude"
|
|
108
|
+
* e.g. "48.856614,2.3522219" for Paris.
|
|
109
|
+
*/
|
|
110
|
+
geolocation?: string;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export class ScrapeConfig {
|
|
114
|
+
static PUBLIC_DATACENTER_POOL = 'public_datacenter_pool';
|
|
115
|
+
static PUBLIC_RESIDENTIAL_POOL = 'public_residential_pool';
|
|
116
|
+
|
|
117
|
+
url: string;
|
|
118
|
+
retry = true;
|
|
119
|
+
method: HttpMethod = 'GET';
|
|
120
|
+
country?: string | null = null;
|
|
121
|
+
render_js = false;
|
|
122
|
+
cache = false;
|
|
123
|
+
cache_clear = false;
|
|
124
|
+
cost_budget?: number;
|
|
125
|
+
ssl = false;
|
|
126
|
+
dns = false;
|
|
127
|
+
asp = false;
|
|
128
|
+
debug = false;
|
|
129
|
+
raise_on_upstream_error = true;
|
|
130
|
+
cache_ttl?: number;
|
|
131
|
+
proxy_pool?: string;
|
|
132
|
+
session?: string;
|
|
133
|
+
tags: Set<string> = new Set<string>();
|
|
134
|
+
format?: 'json' | 'text' | 'markdown' | 'clean_html' | 'raw' | Format;
|
|
135
|
+
format_options?: ('no_links' | 'no_images' | 'only_content' | FormatOption)[];
|
|
136
|
+
extraction_template?: string; // saved template name
|
|
137
|
+
extraction_ephemeral_template?: object; // ephemeraly declared json template
|
|
138
|
+
extraction_prompt?: string;
|
|
139
|
+
extraction_model?: string;
|
|
140
|
+
correlation_id?: string;
|
|
141
|
+
cookies?: Rec<string>;
|
|
142
|
+
body?: string;
|
|
143
|
+
data?: Rec<any>;
|
|
144
|
+
headers?: Rec<string>;
|
|
145
|
+
js?: string;
|
|
146
|
+
rendering_wait?: number;
|
|
147
|
+
wait_for_selector?: string;
|
|
148
|
+
session_sticky_proxy = false;
|
|
149
|
+
screenshots?: Rec<any>;
|
|
150
|
+
screenshot_flags?:
|
|
151
|
+
('load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags)[];
|
|
152
|
+
webhook?: string;
|
|
153
|
+
timeout?: number; // in milliseconds
|
|
154
|
+
js_scenario?: Rec<any>;
|
|
155
|
+
lang?: string[];
|
|
156
|
+
os?: string;
|
|
157
|
+
auto_scroll?: boolean;
|
|
158
|
+
browser_brand?: string;
|
|
159
|
+
proxified_response?: boolean;
|
|
160
|
+
rendering_stage?: 'complete' | 'domcontentloaded';
|
|
161
|
+
geolocation?: string;
|
|
162
|
+
|
|
163
|
+
constructor(options: ScrapeConfigOptions) {
|
|
164
|
+
this.validateOptions(options);
|
|
165
|
+
if (options.format && !Object.values(Format).includes(options.format as Format)) {
|
|
166
|
+
throw new ScrapeConfigError(`Invalid Format param value: ${options.format}`);
|
|
167
|
+
}
|
|
168
|
+
this.format = options.format ?? this.format;
|
|
169
|
+
if (options.format_options) {
|
|
170
|
+
options.format_options.forEach((flag) => {
|
|
171
|
+
if (!Object.values(FormatOption).includes(flag as FormatOption)) {
|
|
172
|
+
throw new ScrapeConfigError(`Invalid FormatOption param value: ${flag}`);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
if (options.screenshot_flags) {
|
|
177
|
+
options.screenshot_flags.forEach((flag) => {
|
|
178
|
+
if (!Object.values(ScreenshotFlags).includes(flag as ScreenshotFlags)) {
|
|
179
|
+
throw new ScrapeConfigError(`Invalid ScreenshotFlags param value: ${flag}`);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
this.url = options.url;
|
|
184
|
+
this.retry = options.retry ?? this.retry;
|
|
185
|
+
this.method = options.method ?? this.method;
|
|
186
|
+
this.country = options.country ?? this.country;
|
|
187
|
+
this.session_sticky_proxy = options.session_sticky_proxy ?? this.session_sticky_proxy;
|
|
188
|
+
this.render_js = options.render_js ?? this.render_js;
|
|
189
|
+
this.cache = options.cache ?? this.cache;
|
|
190
|
+
this.cache_clear = options.cache_clear ?? this.cache_clear;
|
|
191
|
+
this.cost_budget = options.cost_budget ?? this.cost_budget;
|
|
192
|
+
this.asp = options.asp ?? this.asp;
|
|
193
|
+
this.headers = options.headers
|
|
194
|
+
? Object.fromEntries(Object.entries(options.headers).map(([k, v]) => [k.toLowerCase(), v]))
|
|
195
|
+
: {};
|
|
196
|
+
this.raise_on_upstream_error = options.raise_on_upstream_error ?? this.raise_on_upstream_error;
|
|
197
|
+
this.cache_ttl = options.cache_ttl ?? this.cache_ttl;
|
|
198
|
+
this.proxy_pool = options.proxy_pool ?? this.proxy_pool;
|
|
199
|
+
this.session = options.session ?? this.session;
|
|
200
|
+
this.tags = options.tags ? new Set(options.tags) : this.tags;
|
|
201
|
+
this.format = options.format ?? this.format;
|
|
202
|
+
this.format_options = options.format_options ?? this.format_options;
|
|
203
|
+
this.extraction_template = options.extraction_template ?? this.extraction_template;
|
|
204
|
+
this.extraction_ephemeral_template = options.extraction_ephemeral_template ?? this.extraction_ephemeral_template;
|
|
205
|
+
this.extraction_prompt = options.extraction_prompt ?? this.extraction_prompt;
|
|
206
|
+
this.extraction_model = options.extraction_model ?? this.extraction_model;
|
|
207
|
+
this.correlation_id = options.correlation_id ?? this.correlation_id;
|
|
208
|
+
this.cookies = options.cookies
|
|
209
|
+
? Object.fromEntries(Object.entries(options.cookies).map(([k, v]) => [k.toLowerCase(), v]))
|
|
210
|
+
: {};
|
|
211
|
+
this.body = options.body ?? this.body;
|
|
212
|
+
this.data = options.data ?? this.data;
|
|
213
|
+
this.js = options.js ?? this.js;
|
|
214
|
+
this.rendering_wait = options.rendering_wait ?? this.rendering_wait;
|
|
215
|
+
this.wait_for_selector = options.wait_for_selector ?? this.wait_for_selector;
|
|
216
|
+
this.screenshots = options.screenshots ?? this.screenshots;
|
|
217
|
+
this.screenshot_flags = options.screenshot_flags ?? this.screenshot_flags;
|
|
218
|
+
this.webhook = options.webhook ?? this.webhook;
|
|
219
|
+
this.timeout = options.timeout ?? this.timeout;
|
|
220
|
+
this.js_scenario = options.js_scenario ?? this.js_scenario;
|
|
221
|
+
this.os = options.os ?? this.os;
|
|
222
|
+
this.lang = options.lang ?? this.lang;
|
|
223
|
+
this.auto_scroll = options.auto_scroll ?? this.auto_scroll;
|
|
224
|
+
this.browser_brand = options.browser_brand ?? this.browser_brand;
|
|
225
|
+
this.proxified_response = options.proxified_response ?? this.proxified_response;
|
|
226
|
+
this.rendering_stage = options.rendering_stage ?? this.rendering_stage;
|
|
227
|
+
this.geolocation = options.geolocation ?? this.geolocation;
|
|
228
|
+
this.dns = options.dns ?? this.dns;
|
|
229
|
+
this.ssl = options.ssl ?? this.ssl;
|
|
230
|
+
this.debug = options.debug ?? this.debug;
|
|
231
|
+
if (this.body && this.data) {
|
|
232
|
+
throw new ScrapeConfigError('Cannot set both body and data');
|
|
233
|
+
}
|
|
234
|
+
if (['POST', 'PUT', 'PATCH'].includes(this.method)) {
|
|
235
|
+
if (this.data && !this.body) {
|
|
236
|
+
if (!this.headers['content-type']) {
|
|
237
|
+
this.headers['content-type'] = 'application/x-www-form-urlencoded';
|
|
238
|
+
this.body = new URLSearchParams(this.data).toString();
|
|
239
|
+
} else {
|
|
240
|
+
if (this.headers['content-type']?.includes('application/json')) {
|
|
241
|
+
this.body = JSON.stringify(this.data);
|
|
242
|
+
} else if (this.headers['content-type']?.includes('application/x-www-form-urlencoded')) {
|
|
243
|
+
this.body = new URLSearchParams(this.data).toString();
|
|
244
|
+
} else {
|
|
245
|
+
throw new ScrapeConfigError(
|
|
246
|
+
`Content-Type "${
|
|
247
|
+
this.headers['content-type']
|
|
248
|
+
}" not supported, use body parameter to pass pre encoded body according to your content type`,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
} else if (this.body && !this.data && !this.headers['content-type']) {
|
|
253
|
+
this.headers['content-type'] = 'text/plain';
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private validateOptions(options: Partial<ScrapeConfigOptions>) {
|
|
259
|
+
const validKeys = new Set(Object.keys(this) as Array<keyof ScrapeConfig>);
|
|
260
|
+
for (const key in options) {
|
|
261
|
+
if (!validKeys.has(key as keyof ScrapeConfig)) {
|
|
262
|
+
throw new ScrapeConfigError(`Invalid option provided: ${key}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
toApiParams(options: { key: string }): Record<string, any> {
|
|
268
|
+
const params: Record<string, any> = {
|
|
269
|
+
key: options.key,
|
|
270
|
+
};
|
|
271
|
+
params.url = this.url;
|
|
272
|
+
if (this.country) {
|
|
273
|
+
params.country = this.country;
|
|
274
|
+
}
|
|
275
|
+
if (this.headers !== undefined && Object.keys(this.headers).length > 0) {
|
|
276
|
+
Object.entries(this.headers).forEach(([key, value]) => {
|
|
277
|
+
params[`headers[${key}]`] = value;
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (this.cookies !== undefined && Object.keys(this.cookies).length > 0) {
|
|
282
|
+
const cookiesAsHeader = [...Object.entries(this.cookies)]
|
|
283
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
284
|
+
.join('; ');
|
|
285
|
+
|
|
286
|
+
if (params['headers[cookie]']) {
|
|
287
|
+
// if current cookie value doesn't have a ';' at the end, add it.
|
|
288
|
+
if (params['headers[cookie]'][params['headers[cookie]'].length - 1] !== ';') {
|
|
289
|
+
params['headers[cookie]'] += ';';
|
|
290
|
+
}
|
|
291
|
+
params['headers[cookie]'] += ` ${cookiesAsHeader}`;
|
|
292
|
+
} else {
|
|
293
|
+
params['headers[cookie]'] = cookiesAsHeader;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (this.webhook) {
|
|
297
|
+
params.webhook_name = this.webhook;
|
|
298
|
+
}
|
|
299
|
+
if (this.timeout) {
|
|
300
|
+
params.timeout = this.timeout;
|
|
301
|
+
}
|
|
302
|
+
if (this.cost_budget !== undefined) {
|
|
303
|
+
params.cost_budget = this.cost_budget;
|
|
304
|
+
}
|
|
305
|
+
if (this.proxified_response !== undefined) {
|
|
306
|
+
params.proxified_response = this.proxified_response;
|
|
307
|
+
}
|
|
308
|
+
if (this.render_js === true) {
|
|
309
|
+
params.render_js = true;
|
|
310
|
+
if (this.wait_for_selector !== undefined) {
|
|
311
|
+
params.wait_for_selector = this.wait_for_selector;
|
|
312
|
+
}
|
|
313
|
+
if (this.js !== undefined) {
|
|
314
|
+
params.js = urlsafe_b64encode(this.js);
|
|
315
|
+
}
|
|
316
|
+
if (this.js_scenario !== undefined) {
|
|
317
|
+
params.js_scenario = urlsafe_b64encode(JSON.stringify(this.js_scenario));
|
|
318
|
+
}
|
|
319
|
+
if (this.rendering_wait !== undefined) {
|
|
320
|
+
params.rendering_wait = this.rendering_wait;
|
|
321
|
+
}
|
|
322
|
+
if (this.rendering_stage && this.rendering_stage !== 'complete') {
|
|
323
|
+
params.rendering_stage = this.rendering_stage;
|
|
324
|
+
}
|
|
325
|
+
if (this.geolocation) {
|
|
326
|
+
params.geolocation = this.geolocation;
|
|
327
|
+
}
|
|
328
|
+
if (this.screenshots !== undefined) {
|
|
329
|
+
Object.keys(this.screenshots).forEach((key) => {
|
|
330
|
+
params[`screenshots[${key}]`] = (this.screenshots || {})[key];
|
|
331
|
+
});
|
|
332
|
+
if (this.screenshot_flags) {
|
|
333
|
+
params.screenshot_flags = this.screenshot_flags.join(',');
|
|
334
|
+
}
|
|
335
|
+
} else {
|
|
336
|
+
if (this.screenshot_flags) {
|
|
337
|
+
log.warn('Params "screenshot_flags" is ignored. Works only if screenshots is enabled');
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (this.auto_scroll !== undefined) {
|
|
341
|
+
params.auto_scroll = this.auto_scroll;
|
|
342
|
+
}
|
|
343
|
+
} else {
|
|
344
|
+
if (this.wait_for_selector !== undefined) {
|
|
345
|
+
log.warn('Params "wait_for_selector" is ignored. Works only if render_js is enabled');
|
|
346
|
+
}
|
|
347
|
+
if (this.screenshots !== undefined) {
|
|
348
|
+
log.warn('Params "screenshots" is ignored. Works only if render_js is enabled');
|
|
349
|
+
}
|
|
350
|
+
if (this.js_scenario !== undefined) {
|
|
351
|
+
log.warn('Params "js_scenario" is ignored. Works only if render_js is enabled');
|
|
352
|
+
}
|
|
353
|
+
if (this.js !== undefined) {
|
|
354
|
+
log.warn('Params "js" is ignored. Works only if render_js is enabled');
|
|
355
|
+
}
|
|
356
|
+
if (this.rendering_wait !== undefined) {
|
|
357
|
+
log.warn('Params "rendering_wait" is ignored. Works only if render_js is enabled');
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (this.asp === true) {
|
|
362
|
+
params.asp = true;
|
|
363
|
+
}
|
|
364
|
+
if (this.retry === false) {
|
|
365
|
+
params.retry = false;
|
|
366
|
+
}
|
|
367
|
+
if (this.cache === true) {
|
|
368
|
+
params.cache = true;
|
|
369
|
+
if (this.cache_clear) {
|
|
370
|
+
params.cache_clear = true;
|
|
371
|
+
}
|
|
372
|
+
if (this.cache_ttl) {
|
|
373
|
+
params.cache_ttl = this.cache_ttl;
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
if (this.cache_clear) {
|
|
377
|
+
log.warn('Params "cache_clear" is ignored. Works only if cache is enabled');
|
|
378
|
+
}
|
|
379
|
+
if (this.cache_ttl) {
|
|
380
|
+
log.warn('Params "cache_ttl" is ignored. Works only if cache is enabled');
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (this.dns === true) {
|
|
384
|
+
params.dns = true;
|
|
385
|
+
}
|
|
386
|
+
if (this.ssl === true) {
|
|
387
|
+
params.ssl = true;
|
|
388
|
+
}
|
|
389
|
+
if (this.tags.size > 0) {
|
|
390
|
+
params.tags = Array.from(this.tags).join(',');
|
|
391
|
+
}
|
|
392
|
+
if (this.format) {
|
|
393
|
+
params.format = this.format.valueOf();
|
|
394
|
+
if (this.format_options) {
|
|
395
|
+
params.format += ':' + this.format_options.join(',');
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (this.extraction_template && this.extraction_ephemeral_template) {
|
|
399
|
+
throw new ScrapeConfigError(
|
|
400
|
+
'You cannot pass both parameters extraction_template and extraction_ephemeral_template. You must choose',
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (this.extraction_template) {
|
|
405
|
+
params.extraction_template = this.extraction_template;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (this.extraction_ephemeral_template) {
|
|
409
|
+
params.extraction_template = 'ephemeral:' + urlsafe_b64encode(JSON.stringify(this.extraction_ephemeral_template));
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (this.extraction_prompt) {
|
|
413
|
+
params.extraction_prompt = this.extraction_prompt;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (this.extraction_model) {
|
|
417
|
+
params.extraction_model = this.extraction_model;
|
|
418
|
+
}
|
|
419
|
+
if (this.correlation_id) {
|
|
420
|
+
params.correlation_id = this.correlation_id;
|
|
421
|
+
}
|
|
422
|
+
if (this.session) {
|
|
423
|
+
params.session = this.session;
|
|
424
|
+
if (this.session_sticky_proxy) {
|
|
425
|
+
params.session_sticky_proxy = true;
|
|
426
|
+
}
|
|
427
|
+
} else {
|
|
428
|
+
if (this.session_sticky_proxy) {
|
|
429
|
+
log.warn('Params "session_sticky_proxy" is ignored. Works only if session is enabled');
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (this.debug === true) {
|
|
433
|
+
params.debug = true;
|
|
434
|
+
}
|
|
435
|
+
if (this.proxy_pool) {
|
|
436
|
+
params.proxy_pool = this.proxy_pool;
|
|
437
|
+
}
|
|
438
|
+
if (this.lang !== undefined) {
|
|
439
|
+
params.lang = this.lang.join(',');
|
|
440
|
+
}
|
|
441
|
+
if (this.os !== undefined) {
|
|
442
|
+
params.os = this.os;
|
|
443
|
+
}
|
|
444
|
+
if (this.browser_brand !== undefined) {
|
|
445
|
+
params.browser_brand = this.browser_brand;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return params;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { ScreenshotConfigError } from './errors.js';
|
|
2
|
+
import { urlsafe_b64encode } from './utils.js';
|
|
3
|
+
import { log } from './logger.js';
|
|
4
|
+
|
|
5
|
+
/** Toggles that customize how the screenshot is captured. */
|
|
6
|
+
export enum Options {
|
|
7
|
+
/** Render images before capturing. Consumes additional bandwidth. */
|
|
8
|
+
LOAD_IMAGES = 'load_images',
|
|
9
|
+
/** Render the page in dark mode. */
|
|
10
|
+
DARK_MODE = 'dark_mode',
|
|
11
|
+
/** Block cookie banners and overlays that would otherwise occlude the page. */
|
|
12
|
+
BLOCK_BANNERS = 'block_banners',
|
|
13
|
+
/** Render the page using the `print` media query. */
|
|
14
|
+
PRINT_MEDIA_FORMAT = 'print_media_format',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Output format of the screenshot image. */
|
|
18
|
+
export enum Format {
|
|
19
|
+
/** JPEG encoding. */
|
|
20
|
+
JPG = 'jpg',
|
|
21
|
+
/** PNG encoding. */
|
|
22
|
+
PNG = 'png',
|
|
23
|
+
/** WebP encoding. */
|
|
24
|
+
WEBP = 'webp',
|
|
25
|
+
/** Animated GIF encoding. */
|
|
26
|
+
GIF = 'gif',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Visual impairments to simulate when capturing the screenshot.
|
|
31
|
+
* Useful for WCAG accessibility testing.
|
|
32
|
+
*/
|
|
33
|
+
export enum VisionDeficiency {
|
|
34
|
+
/** Difficulty distinguishing green from red; green appears beige/gray. */
|
|
35
|
+
DEUTERANOPIA = 'deuteranopia',
|
|
36
|
+
/** Reduced sensitivity to red light; red appears dark/black. */
|
|
37
|
+
PROTANOPIA = 'protanopia',
|
|
38
|
+
/** Difficulty distinguishing blue from yellow and violet from red. */
|
|
39
|
+
TRITANOPIA = 'tritanopia',
|
|
40
|
+
/** Complete color blindness; the image is grayscale. */
|
|
41
|
+
ACHROMATOPSIA = 'achromatopsia',
|
|
42
|
+
/** Reduced contrast (aging, low light). */
|
|
43
|
+
REDUCED_CONTRAST = 'reducedContrast',
|
|
44
|
+
/** Blurred vision (uncorrected refractive errors). */
|
|
45
|
+
BLURRED_VISION = 'blurredVision',
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* User-facing options accepted by {@link ScreenshotConfig}. See the
|
|
50
|
+
* [Screenshot API reference](https://scrapfly.io/docs/screenshot-api)
|
|
51
|
+
* for the authoritative list of valid values.
|
|
52
|
+
*/
|
|
53
|
+
type ScreenshotConfigOptions = {
|
|
54
|
+
/** URL of the page to screenshot. Required. */
|
|
55
|
+
url: string;
|
|
56
|
+
/** Output image format. Defaults to JPG. */
|
|
57
|
+
format?: 'jpg' | 'png' | 'webp' | 'gif' | Format;
|
|
58
|
+
/** Capture area: `fullpage`, `viewport`, or a CSS selector. */
|
|
59
|
+
capture?: string;
|
|
60
|
+
/** Viewport resolution, formatted as "widthxheight". */
|
|
61
|
+
resolution?: string;
|
|
62
|
+
/** ISO country code for geo-targeting the rendering browser. */
|
|
63
|
+
country?: string;
|
|
64
|
+
/** Request timeout in milliseconds. */
|
|
65
|
+
timeout?: number;
|
|
66
|
+
/** Additional delay (ms) after load before capturing. */
|
|
67
|
+
rendering_wait?: number;
|
|
68
|
+
/** CSS selector to wait for before capturing. */
|
|
69
|
+
wait_for_selector?: string;
|
|
70
|
+
/** Behavior toggles. See {@link Options}. */
|
|
71
|
+
options?: ('load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | Options)[];
|
|
72
|
+
/** Scroll to the bottom of the page before capture. */
|
|
73
|
+
auto_scroll?: boolean;
|
|
74
|
+
/** Custom JavaScript to run on the page before capture. */
|
|
75
|
+
js?: string;
|
|
76
|
+
/** Serve from Scrapfly's cache when possible. */
|
|
77
|
+
cache?: boolean;
|
|
78
|
+
/** TTL in seconds for the cached entry. Ignored if cache is disabled. */
|
|
79
|
+
cache_ttl?: number;
|
|
80
|
+
/** Invalidate the existing cache entry before capturing. */
|
|
81
|
+
cache_clear?: boolean;
|
|
82
|
+
/** Vision deficiency to simulate. See {@link VisionDeficiency}. */
|
|
83
|
+
vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredVision' | 'reducedContrast' | VisionDeficiency;
|
|
84
|
+
/** Webhook name to notify when the screenshot completes. */
|
|
85
|
+
webhook?: string;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Configuration for a single screenshot request. Instances are passed
|
|
90
|
+
* to {@link ScrapflyClient.screenshot}; this class is responsible for
|
|
91
|
+
* validating options and encoding them into Scrapfly's query string
|
|
92
|
+
* format.
|
|
93
|
+
*/
|
|
94
|
+
export class ScreenshotConfig {
|
|
95
|
+
/** URL of the page to screenshot. */
|
|
96
|
+
url: string;
|
|
97
|
+
/** Output image format. */
|
|
98
|
+
format?: 'jpg' | 'png' | 'webp' | 'gif' | Format;
|
|
99
|
+
/** Capture area (`fullpage`, `viewport`, or a CSS selector). */
|
|
100
|
+
capture?: string;
|
|
101
|
+
/** Viewport resolution (`widthxheight`). */
|
|
102
|
+
resolution?: string;
|
|
103
|
+
/** Geo-targeting country (ISO code). */
|
|
104
|
+
country?: string = undefined;
|
|
105
|
+
timeout?: number;
|
|
106
|
+
rendering_wait?: number;
|
|
107
|
+
wait_for_selector?: string;
|
|
108
|
+
options?: ('load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | Options)[];
|
|
109
|
+
auto_scroll?: boolean;
|
|
110
|
+
js?: string;
|
|
111
|
+
cache?: boolean;
|
|
112
|
+
cache_ttl?: number;
|
|
113
|
+
cache_clear?: boolean;
|
|
114
|
+
vision_deficiency?: 'deuteranopia' | 'protanopia' | 'tritanopia' | 'achromatopsia' | 'blurredVision' | 'reducedContrast' | VisionDeficiency;
|
|
115
|
+
webhook?: string;
|
|
116
|
+
|
|
117
|
+
constructor(options: ScreenshotConfigOptions) {
|
|
118
|
+
this.validateOptions(options);
|
|
119
|
+
if (options.format && !Object.values(Format).includes(options.format as Format)) {
|
|
120
|
+
throw new ScreenshotConfigError(`Invalid Format param value: ${options.format}`);
|
|
121
|
+
}
|
|
122
|
+
this.format = options.format ?? this.format;
|
|
123
|
+
if (options.options) {
|
|
124
|
+
options.options.forEach((opt) => {
|
|
125
|
+
if (!Object.values(Options).includes(opt as Options)) {
|
|
126
|
+
throw new ScreenshotConfigError(`Invalid Options param value: ${opt}`);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
this.url = options.url;
|
|
131
|
+
this.format = options.format ?? this.format;
|
|
132
|
+
this.capture = options.capture ?? this.capture;
|
|
133
|
+
this.resolution = options.resolution ?? this.resolution;
|
|
134
|
+
this.country = options.country ?? this.country;
|
|
135
|
+
this.timeout = options.timeout ?? this.timeout;
|
|
136
|
+
this.rendering_wait = options.rendering_wait ?? this.rendering_wait;
|
|
137
|
+
this.wait_for_selector = options.wait_for_selector ?? this.wait_for_selector;
|
|
138
|
+
this.options = options.options ?? this.options;
|
|
139
|
+
this.auto_scroll = options.auto_scroll ?? this.auto_scroll;
|
|
140
|
+
this.js = options.js ?? this.js;
|
|
141
|
+
this.cache = options.cache ?? this.cache;
|
|
142
|
+
this.cache_ttl = options.cache_ttl ?? this.cache_ttl;
|
|
143
|
+
this.cache_clear = options.cache_clear ?? this.cache_clear;
|
|
144
|
+
this.vision_deficiency = options.vision_deficiency ?? this.vision_deficiency;
|
|
145
|
+
this.webhook = options.webhook;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private validateOptions(options: Partial<ScreenshotConfigOptions>) {
|
|
149
|
+
const validKeys = new Set(Object.keys(this) as Array<keyof ScreenshotConfig>);
|
|
150
|
+
for (const key in options) {
|
|
151
|
+
if (!validKeys.has(key as keyof ScreenshotConfig)) {
|
|
152
|
+
throw new ScreenshotConfigError(`Invalid option provided: ${key}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Encode this config as the query-string parameters sent to the
|
|
159
|
+
* Screenshot API.
|
|
160
|
+
*
|
|
161
|
+
* @param options.key Scrapfly API key.
|
|
162
|
+
* @returns A record suitable for `URLSearchParams` construction.
|
|
163
|
+
*/
|
|
164
|
+
toApiParams(options: { key: string }): Record<string, any> {
|
|
165
|
+
const params: Record<string, any> = {
|
|
166
|
+
key: options.key,
|
|
167
|
+
};
|
|
168
|
+
params.url = this.url;
|
|
169
|
+
|
|
170
|
+
if (this.format) {
|
|
171
|
+
params.format = this.format.valueOf();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (this.capture) {
|
|
175
|
+
params.capture = this.capture;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (this.resolution) {
|
|
179
|
+
params.resolution = this.resolution;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (this.country) {
|
|
183
|
+
params.country = this.country;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (this.timeout) {
|
|
187
|
+
params.timeout = this.timeout;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (this.rendering_wait) {
|
|
191
|
+
params.rendering_wait = this.rendering_wait;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (this.wait_for_selector) {
|
|
195
|
+
params.wait_for_selector = this.wait_for_selector;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (this.options) {
|
|
199
|
+
params.options = this.options.join(',');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (this.auto_scroll === true) {
|
|
203
|
+
params.auto_scroll = this.auto_scroll;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (this.js) {
|
|
207
|
+
params.js = urlsafe_b64encode(this.js);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (this.cache === true) {
|
|
211
|
+
params.cache = this.cache;
|
|
212
|
+
if (this.cache_ttl) {
|
|
213
|
+
params.cache_ttl = this.cache_ttl;
|
|
214
|
+
}
|
|
215
|
+
if (this.cache_clear === true) {
|
|
216
|
+
params.cache_clear = this.cache_clear;
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
if (this.cache_ttl) {
|
|
220
|
+
log.warn('Params "cache_ttl" is ignored. Works only if cache is enabled');
|
|
221
|
+
}
|
|
222
|
+
if (this.cache_clear) {
|
|
223
|
+
log.warn('Params "cache_clear" is ignored. Works only if cache is enabled');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (this.vision_deficiency) {
|
|
228
|
+
params.vision_deficiency = this.vision_deficiency;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (this.webhook) {
|
|
232
|
+
params.webhook_name = this.webhook;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return params;
|
|
236
|
+
}
|
|
237
|
+
}
|
package/src/types.ts
ADDED