Skip to content

Commit

Permalink
Logs: Redirect log in response (#589)
Browse files Browse the repository at this point in the history
* redirect added

* resource type comparison added

* semicolon added

* Apply suggestions from code review

---------

Co-authored-by: Agnès Toulet <[email protected]>
  • Loading branch information
juanicabanas and AgnesToulet authored Jan 31, 2025
1 parent 122374c commit 850e037
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ export class Browser {
page.on('request', this.logRequest);
page.on('requestfinished', this.logRequestFinished);
page.on('close', this.logPageClosed);
page.on('response', this.logRedirectResponse);
}
}

Expand All @@ -568,6 +569,7 @@ export class Browser {
page.off('request', this.logRequest);
page.off('requestfinished', this.logRequestFinished);
page.off('close', this.logPageClosed);
page.off('response', this.logRedirectResponse);
}
}

Expand Down Expand Up @@ -598,6 +600,14 @@ export class Browser {
this.log.debug('Browser request', 'url', req.url(), 'method', req.method());
};

logRedirectResponse = (resp: puppeteer.HTTPResponse) => {
const status = resp.status();
if (status >= 300 && status <= 399 && resp.request().resourceType() === 'document') {
const headers = resp.headers();
this.log.debug(`Redirect from ${resp.url()} to ${headers['location']}`);
}
};

logRequestFailed = (req: any) => {
let failureError = '';
const failure = req?.failure();
Expand Down

0 comments on commit 850e037

Please sign in to comment.