@@ -126,6 +126,7 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
126
126
await page . route ( '**/*' , async ( route , request ) => {
127
127
const requestUrl = request . url ( )
128
128
const requestHostname = new URL ( requestUrl ) . hostname ;
129
+ let requestOptions : Record < string , any > = { timeout : REQUEST_TIMEOUT }
129
130
130
131
try {
131
132
// abort audio/video media requests
@@ -136,11 +137,7 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
136
137
// handle discovery config
137
138
ctx . config . allowedHostnames . push ( new URL ( snapshot . url ) . hostname ) ;
138
139
if ( ctx . config . enableJavaScript ) ALLOWED_RESOURCES . push ( 'script' ) ;
139
-
140
- let requestOptions : Record < string , any > = {
141
- timeout : REQUEST_TIMEOUT
142
- }
143
- if ( requestUrl === snapshot . url && ctx . config . basicAuthorization ) {
140
+ if ( ctx . config . basicAuthorization ) {
144
141
ctx . log . debug ( `Adding basic authorization to the headers for root url` ) ;
145
142
let token = Buffer . from ( `${ ctx . config . basicAuthorization . username } :${ ctx . config . basicAuthorization . password } ` ) . toString ( 'base64' ) ;
146
143
requestOptions . headers = {
@@ -149,9 +146,20 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
149
146
} ;
150
147
}
151
148
152
- const response = await page . request . fetch ( request , { timeout : REQUEST_TIMEOUT } ) ;
153
- const body = await response . body ( ) ;
149
+ // get response
150
+ let response , body ;
151
+ if ( requestUrl === snapshot . url ) {
152
+ response = {
153
+ status : ( ) => 200 ,
154
+ headers : ( ) => ( { 'content-type' : 'text/html' } )
155
+ }
156
+ body = snapshot . dom . html
157
+ } else {
158
+ response = await page . request . fetch ( request , requestOptions ) ;
159
+ body = await response . body ( ) ;
160
+ }
154
161
162
+ // handle response
155
163
if ( ! body ) {
156
164
ctx . log . debug ( `Handling request ${ requestUrl } \n - skipping no response` ) ;
157
165
} else if ( ! body . length ) {
0 commit comments