@@ -38,6 +38,7 @@ export enum Format {
38
38
export enum FormatOption {
39
39
NO_LINKS = 'no_links' ,
40
40
NO_IMAGES = 'no_images' ,
41
+ ONLY_CONTENT = 'only_content'
41
42
}
42
43
43
44
type ScrapeConfigOptions = {
@@ -58,8 +59,8 @@ type ScrapeConfigOptions = {
58
59
proxy_pool ?: string ;
59
60
session ?: string ;
60
61
tags ?: string [ ] ;
61
- format ?: Format ;
62
- format_options ?: FormatOption [ ] ;
62
+ format ?: 'json' | 'text' | 'markdown' | 'clean_html' | 'raw' | Format ;
63
+ format_options ?: ( 'no_links' | 'no_images' | 'only_content' | FormatOption ) [ ] ;
63
64
correlation_id ?: string ;
64
65
cookies ?: Rec < string > ;
65
66
body ?: string ;
@@ -69,7 +70,7 @@ type ScrapeConfigOptions = {
69
70
rendering_wait ?: number ;
70
71
wait_for_selector ?: string ;
71
72
screenshots ?: Rec < any > ;
72
- screenshot_flags ?: ScreenshotFlags [ ] ;
73
+ screenshot_flags ?: ( 'load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags ) [ ] ;
73
74
session_sticky_proxy ?: boolean ;
74
75
webhook ?: string ;
75
76
timeout ?: number ;
@@ -100,8 +101,8 @@ export class ScrapeConfig {
100
101
proxy_pool ?: string ;
101
102
session ?: string ;
102
103
tags : Set < string > = new Set < string > ( ) ;
103
- format ?: Format ; // raw(unchanged)
104
- format_options ?: FormatOption [ ] ;
104
+ format ?: 'json' | 'text' | 'markdown' | 'clean_html' | ' raw' | Format ;
105
+ format_options ?: ( 'no_links' | 'no_images' | 'only_content' | FormatOption ) [ ] ;
105
106
correlation_id ?: string ;
106
107
cookies ?: Rec < string > ;
107
108
body ?: string ;
@@ -112,7 +113,7 @@ export class ScrapeConfig {
112
113
wait_for_selector ?: string ;
113
114
session_sticky_proxy = false ;
114
115
screenshots ?: Rec < any > ;
115
- screenshot_flags ?: ScreenshotFlags [ ] ;
116
+ screenshot_flags ?: ( 'load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags ) [ ] ;
116
117
webhook ?: string ;
117
118
timeout ?: number ; // in milliseconds
118
119
js_scenario ?: Rec < any > ;
@@ -122,14 +123,21 @@ export class ScrapeConfig {
122
123
123
124
constructor ( options : ScrapeConfigOptions ) {
124
125
this . validateOptions ( options ) ;
125
- if ( options . format && ! Object . values ( Format ) . includes ( options . format ) ) {
126
- throw new ScrapeConfigError ( `Invalid format param value: ${ options . format } ` ) ;
126
+ if ( options . format && ! Object . values ( Format ) . includes ( options . format as Format ) ) {
127
+ throw new ScrapeConfigError ( `Invalid Format param value: ${ options . format } ` ) ;
127
128
}
128
129
this . format = options . format ?? this . format ;
130
+ if ( options . format_options ) {
131
+ options . format_options . forEach ( ( flag ) => {
132
+ if ( ! Object . values ( FormatOption ) . includes ( flag as FormatOption ) ) {
133
+ throw new ScrapeConfigError ( `Invalid FormatOption param value: ${ flag } ` ) ;
134
+ }
135
+ } ) ;
136
+ }
129
137
if ( options . screenshot_flags ) {
130
138
options . screenshot_flags . forEach ( ( flag ) => {
131
- if ( ! Object . values ( ScreenshotFlags ) . includes ( flag ) ) {
132
- throw new ScrapeConfigError ( `Invalid screenshot_flags param value: ${ flag } ` ) ;
139
+ if ( ! Object . values ( ScreenshotFlags ) . includes ( flag as ScreenshotFlags ) ) {
140
+ throw new ScrapeConfigError ( `Invalid ScreenshotFlags param value: ${ flag } ` ) ;
133
141
}
134
142
} ) ;
135
143
}
0 commit comments