@@ -3,10 +3,13 @@ import { log } from './logger.js';
3
3
import { Rec , HttpMethod } from './types.js' ;
4
4
import { ScrapeConfigError } from './errors.js' ;
5
5
6
+ type ScreenshotFlags = "load_images" | "dark_mode" | "block_banners" | "high_quality" | "print_media_format" ;
7
+ type Format = "raw" | "json" | "text" | "markdown" | "clean_html" ;
8
+
6
9
export class ScrapeConfig {
7
10
static PUBLIC_DATACENTER_POOL = 'public_datacenter_pool' ;
8
11
static PUBLIC_RESIDENTIAL_POOL = 'public_residential_pool' ;
9
-
12
+
10
13
url : string ;
11
14
retry = true ;
12
15
method : HttpMethod = 'GET' ;
@@ -24,6 +27,7 @@ export class ScrapeConfig {
24
27
proxy_pool ?: string = null ;
25
28
session ?: string = null ;
26
29
tags : Set < string > = new Set < string > ( ) ;
30
+ format ?: Format = null ; // raw(unchanged)
27
31
correlation_id ?: string = null ;
28
32
cookies ?: Rec < string > = null ;
29
33
body ?: string = null ;
@@ -34,6 +38,7 @@ export class ScrapeConfig {
34
38
wait_for_selector ?: string = null ;
35
39
session_sticky_proxy = false ;
36
40
screenshots ?: Rec < any > = null ;
41
+ screenshot_flags ?: ScreenshotFlags [ ] = null ;
37
42
webhook ?: string = null ;
38
43
timeout ?: number = null ; // in milliseconds
39
44
js_scenario ?: Rec < any > = null ;
@@ -60,6 +65,7 @@ export class ScrapeConfig {
60
65
proxy_pool ?: string ;
61
66
session ?: string ;
62
67
tags ?: Array < string > ;
68
+ format ?: Format ;
63
69
correlation_id ?: string ;
64
70
cookies ?: Rec < string > ;
65
71
body ?: string ;
@@ -69,6 +75,7 @@ export class ScrapeConfig {
69
75
rendering_wait ?: number ;
70
76
wait_for_selector ?: string ;
71
77
screenshots ?: Rec < any > ;
78
+ screenshot_flags ?: ScreenshotFlags [ ] ;
72
79
session_sticky_proxy ?: boolean ;
73
80
webhook ?: string ;
74
81
timeout ?: number ; // in milliseconds
@@ -96,6 +103,7 @@ export class ScrapeConfig {
96
103
this . proxy_pool = options . proxy_pool ?? this . proxy_pool ;
97
104
this . session = options . session ?? this . session ;
98
105
this . tags = new Set ( options . tags ) ?? this . tags ;
106
+ this . format = options . format ?? this . format ;
99
107
this . correlation_id = options . correlation_id ?? this . correlation_id ;
100
108
this . cookies = options . cookies
101
109
? Object . fromEntries ( Object . entries ( options . cookies ) . map ( ( [ k , v ] ) => [ k . toLowerCase ( ) , v ] ) )
@@ -106,6 +114,7 @@ export class ScrapeConfig {
106
114
this . rendering_wait = options . rendering_wait ?? this . rendering_wait ;
107
115
this . wait_for_selector = options . wait_for_selector ?? this . wait_for_selector ;
108
116
this . screenshots = options . screenshots ?? this . screenshots ;
117
+ this . screenshot_flags = options . screenshot_flags ?? this . screenshot_flags ;
109
118
this . webhook = options . webhook ?? this . webhook ;
110
119
this . timeout = options . timeout ?? this . timeout ;
111
120
this . js_scenario = options . js_scenario ?? this . js_scenario ;
@@ -194,6 +203,13 @@ export class ScrapeConfig {
194
203
Object . keys ( this . screenshots ) . forEach ( ( key ) => {
195
204
params [ `screenshots[${ key } ]` ] = this . screenshots [ key ] ;
196
205
} ) ;
206
+ if ( this . screenshot_flags ) {
207
+ params . screenshot_flags = this . screenshot_flags . join ( ',' ) ;
208
+ }
209
+ } else {
210
+ if ( this . screenshot_flags ) {
211
+ log . warn ( 'Params "screenshot_flags" is ignored. Works only if screenshots is enabled' ) ;
212
+ }
197
213
}
198
214
if ( this . auto_scroll !== null ) {
199
215
params . auto_scroll = this . auto_scroll ;
@@ -247,6 +263,9 @@ export class ScrapeConfig {
247
263
if ( this . tags . size > 0 ) {
248
264
params . tags = Array . from ( this . tags ) . join ( ',' ) ;
249
265
}
266
+ if ( this . format ) {
267
+ params . format = this . format . valueOf ( ) ;
268
+ }
250
269
if ( this . correlation_id ) {
251
270
params . correlation_id = this . correlation_id ;
252
271
}
0 commit comments