[puppeteer] Add Request.failure and test. (#25178)

This commit is contained in:
Aankhen
2018-04-25 04:27:24 +05:30
committed by Wesley Wigham
parent e87728aa06
commit b11cc1ee03
2 changed files with 23 additions and 0 deletions

View File

@@ -627,6 +627,11 @@ export interface Request {
*/
continue(overrides?: Overrides): Promise<void>;
/**
* @returns An object if the request failed, null otherwise.
*/
failure(): { errorText: string; } | null;
/**
* @returns The `Frame` object that initiated the request, or `null` if navigating to error pages
*/

View File

@@ -282,6 +282,24 @@ puppeteer.launch().then(async browser => {
browser.close();
})();
// Test 0.13 features
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const handler = (r: puppeteer.Request) => {
const failure = r.failure();
if (failure == null) {
console.error("Request completed successfully");
return;
}
console.log("Request failed", failure.errorText.toUpperCase());
};
page.on('requestfinished', handler);
page.on('requestfailed', handler);
})();
// Test 1.0 features
(async () => {
const browser = await puppeteer.launch({