1
1
import axios , { AxiosInstance , AxiosResponse } from "axios" ;
2
2
import { PlayWithBrowser } from "./playwithbrowser" ;
3
+ import { GeoCode } from "./geocode" ;
3
4
4
5
export const API_URL = "https://api.scrape.do" ;
5
6
6
7
/**
7
8
* Proxy options for the request
8
9
* @property {boolean } [super] - Use super proxy
9
- * @property {string } [geoCode] - Geographical code
10
- * @property {string } [regionalGeoCode] - Regional geographical code
10
+ * @property {GeoCode } [geoCode] - Geographical code
11
+ * @property {"europe" | "asia" | "africa" | "oceania" | "northamerica" | "southamerica" } [regionalGeoCode] - Regional geographical code
11
12
* @property {string } [sessionId] - Session ID for the proxy
12
13
*
13
14
* @see https://scrape.do/documentation/
14
15
*/
15
16
type ProxyOptions = {
16
17
super ?: boolean ;
17
- geoCode ?: string ;
18
- regionalGeoCode ?: string ;
18
+ geoCode ?: GeoCode ;
19
+ regionalGeoCode ?: "europe" | "asia" | "africa" | "oceania" | "northamerica" | "southamerica" ;
19
20
sessionId ?: string ;
20
21
} ;
21
22
@@ -63,8 +64,8 @@ type RenderOptions = {
63
64
* @property {number } [timeout] - Timeout for the request
64
65
* @property {number } [retryTimeout] - Retry timeout for the request
65
66
* @property {boolean } [disableRetry] - Disable retry
66
- * @property {string } [device] - Device for the request
67
- * @property {string } [output] - Output format
67
+ * @property {"Desktop" | "Mobile" } [device] - Device for the request
68
+ * @property {"raw" | "markdown" } [output] - Output format
68
69
* @property {boolean } [transparentResponse] - Get transparent response
69
70
* @property {ProxyOptions } [super] - Proxy options
70
71
* @property {RenderOptions } [render] - Render options
@@ -82,8 +83,8 @@ export type DoRequest = {
82
83
timeout ?: number ;
83
84
retryTimeout ?: number ;
84
85
disableRetry ?: boolean ;
85
- device ?: string ;
86
- output ?: string ;
86
+ device ?: "Desktop" | "Mobile" ;
87
+ output ?: "raw" | "markdown" ;
87
88
transparentResponse ?: boolean ;
88
89
} & ProxyOptions &
89
90
RenderOptions ;
@@ -205,10 +206,13 @@ export class ScrapeDo {
205
206
}
206
207
207
208
if ( options . extraHeaders ) {
208
- headers = {
209
- ...headers ,
210
- ...options . extraHeaders ,
211
- } ;
209
+ for ( let key in options . extraHeaders ) {
210
+ if ( key . startsWith ( "sd-" ) ) {
211
+ headers [ key ] = options . extraHeaders [ key ] ;
212
+ } else {
213
+ headers [ `sd-${ key } ` ] = options . extraHeaders [ key ] ;
214
+ }
215
+ }
212
216
}
213
217
214
218
if ( options . forwardHeaders ) {
0 commit comments