From d71feb63d09c3bd32b3b1f097bc5cb0e3e54851a Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 17 Aug 2017 23:24:16 -0700 Subject: [PATCH] Determine failed navigation based on Frame.unreachedURL (#365) This patch starts using frame.unreachedURL property from frameNavigated event to determine if the page navigation was successful. --- lib/FrameManager.js | 9 +++++++++ lib/Page.js | 7 ++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/FrameManager.js b/lib/FrameManager.js index df3aa74b4aa..37a993e5967 100644 --- a/lib/FrameManager.js +++ b/lib/FrameManager.js @@ -130,6 +130,14 @@ class FrameManager extends EventEmitter { this._frames.delete(frame._id); this.emit(FrameManager.Events.FrameDetached, frame); } + + /** + * @param {!Frame} frame + * @return {boolean} + */ + isMainFrameLoadingFailed() { + return !!this._mainFrame._loadingFailed; + } } /** @enum {string} */ @@ -337,6 +345,7 @@ class Frame { _navigated(framePayload) { this._name = framePayload.name; this._url = framePayload.url; + this._loadingFailed = !!framePayload.unreachableUrl; } _detach() { diff --git a/lib/Page.js b/lib/Page.js index ae33ac8324e..e05d52c500b 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -293,12 +293,9 @@ class Page extends EventEmitter { } await result; helper.removeEventListeners([listener]); - if (url === 'about:blank') - return null; - let response = responses.get(this.mainFrame().url()); - if (!response) + if (this._frameManager.isMainFrameLoadingFailed()) throw new Error('Failed to navigate: ' + url); - return response; + return responses.get(this.mainFrame().url()) || null; } /**