From 5f7254c41c7c1bda82477488f10254d204373d54 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Wed, 10 Apr 2024 13:13:00 +0200 Subject: [PATCH] fix: suppress error for wrong error code (#12244) --- packages/puppeteer-core/src/bidi/Frame.ts | 23 ++++++++++++++--------- test/TestExpectations.json | 14 -------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/packages/puppeteer-core/src/bidi/Frame.ts b/packages/puppeteer-core/src/bidi/Frame.ts index a9ac5cd9d91..1702b00b308 100644 --- a/packages/puppeteer-core/src/bidi/Frame.ts +++ b/packages/puppeteer-core/src/bidi/Frame.ts @@ -37,6 +37,7 @@ import {TargetCloseError, UnsupportedOperation} from '../common/Errors.js'; import type {TimeoutSettings} from '../common/TimeoutSettings.js'; import type {Awaitable, NodeFor} from '../common/types.js'; import {debugError, fromEmitterEvent, timeout} from '../common/util.js'; +import {isErrorLike} from '../util/ErrorLike.js'; import {BidiCdpSession} from './CDPSession.js'; import type {BrowsingContext} from './core/BrowsingContext.js'; @@ -301,10 +302,18 @@ export class BidiFrame extends Frame { // readiness=interactive. // // Related: https://bugzilla.mozilla.org/show_bug.cgi?id=1846601 - this.browsingContext.navigate( - url, - Bidi.BrowsingContext.ReadinessState.Interactive - ), + this.browsingContext + .navigate(url, Bidi.BrowsingContext.ReadinessState.Interactive) + .catch(error => { + if ( + isErrorLike(error) && + error.message.includes('net::ERR_HTTP_RESPONSE_CODE_FAILURE') + ) { + return; + } + + throw error; + }), ]).catch( rewriteNavigationError( url, @@ -352,11 +361,7 @@ export class BidiFrame extends Frame { }), raceWith( fromEmitterEvent(navigation, 'fragment'), - fromEmitterEvent(navigation, 'failed').pipe( - map(({url}) => { - throw new Error(`Navigation failed: ${url}`); - }) - ), + fromEmitterEvent(navigation, 'failed'), fromEmitterEvent(navigation, 'aborted').pipe( map(({url}) => { throw new Error(`Navigation aborted: ${url}`); diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 6e0d583bae3..ecc688b4c82 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -2538,20 +2538,6 @@ "expectations": ["SKIP"], "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" }, - { - "testIdPattern": "[navigation.spec] navigation Page.goto should not throw an error for a 404 response with an empty body", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["chrome", "webDriverBiDi"], - "expectations": ["FAIL"], - "comment": "Chrome returns an error instead of the network request" - }, - { - "testIdPattern": "[navigation.spec] navigation Page.goto should not throw an error for a 500 response with an empty body", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["chrome", "webDriverBiDi"], - "expectations": ["FAIL"], - "comment": "Chrome returns an error instead of the network request" - }, { "testIdPattern": "[navigation.spec] navigation Page.goto should send referer", "platforms": ["darwin", "linux", "win32"],