Skip to content

Commit 6da676f

Browse files
committed
Send captured DOM as root resource
1 parent 8222a65 commit 6da676f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/lib/processSnapshot.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
126126
await page.route('**/*', async (route, request) => {
127127
const requestUrl = request.url()
128128
const requestHostname = new URL(requestUrl).hostname;
129+
let requestOptions: Record<string, any> = { timeout: REQUEST_TIMEOUT }
129130

130131
try {
131132
// abort audio/video media requests
@@ -136,11 +137,7 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
136137
// handle discovery config
137138
ctx.config.allowedHostnames.push(new URL(snapshot.url).hostname);
138139
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) {
144141
ctx.log.debug(`Adding basic authorization to the headers for root url`);
145142
let token = Buffer.from(`${ctx.config.basicAuthorization.username}:${ctx.config.basicAuthorization.password}`).toString('base64');
146143
requestOptions.headers = {
@@ -149,9 +146,20 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
149146
};
150147
}
151148

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+
}
154161

162+
// handle response
155163
if (!body) {
156164
ctx.log.debug(`Handling request ${requestUrl}\n - skipping no response`);
157165
} else if (!body.length) {

0 commit comments

Comments
 (0)