11import axios , { AxiosInstance , AxiosResponse } from "axios" ;
22import { PlayWithBrowser } from "./playwithbrowser" ;
3+ import { GeoCode } from "./geocode" ;
34
45export const API_URL = "https://api.scrape.do" ;
56
67/**
78 * Proxy options for the request
89 * @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
1112 * @property {string } [sessionId] - Session ID for the proxy
1213 *
1314 * @see https://scrape.do/documentation/
1415 */
1516type ProxyOptions = {
1617 super ?: boolean ;
17- geoCode ?: string ;
18- regionalGeoCode ?: string ;
18+ geoCode ?: GeoCode ;
19+ regionalGeoCode ?: "europe" | "asia" | "africa" | "oceania" | "northamerica" | "southamerica" ;
1920 sessionId ?: string ;
2021} ;
2122
@@ -63,8 +64,8 @@ type RenderOptions = {
6364 * @property {number } [timeout] - Timeout for the request
6465 * @property {number } [retryTimeout] - Retry timeout for the request
6566 * @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
6869 * @property {boolean } [transparentResponse] - Get transparent response
6970 * @property {ProxyOptions } [super] - Proxy options
7071 * @property {RenderOptions } [render] - Render options
@@ -82,8 +83,8 @@ export type DoRequest = {
8283 timeout ?: number ;
8384 retryTimeout ?: number ;
8485 disableRetry ?: boolean ;
85- device ?: string ;
86- output ?: string ;
86+ device ?: "Desktop" | "Mobile" ;
87+ output ?: "raw" | "markdown" ;
8788 transparentResponse ?: boolean ;
8889} & ProxyOptions &
8990 RenderOptions ;
@@ -205,10 +206,13 @@ export class ScrapeDo {
205206 }
206207
207208 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+ }
212216 }
213217
214218 if ( options . forwardHeaders ) {
0 commit comments