From b9e3cce5fd7e6c61f35a8ff6b7bbfa34e03fb496 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 27 Jul 2017 17:54:39 -0700 Subject: [PATCH] Fail navigation when main resource fails to load This patch fails navigation when the main resource fails to load. Fixes #148. --- lib/Page.js | 5 ++++- test/test.js | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Page.js b/lib/Page.js index 67a07409..50c5fc19 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -260,7 +260,10 @@ class Page extends EventEmitter { } await result; helper.removeEventListeners([listener]); - return responses.get(this.mainFrame().url()); + let response = responses.get(this.mainFrame().url()); + if (!response) + throw new Error('Failed to navigate: ' + url); + return response; } /** diff --git a/test/test.js b/test/test.js index 3a0580ed..a3563bcd 100644 --- a/test/test.js +++ b/test/test.js @@ -461,6 +461,15 @@ describe('Puppeteer', function() { } expect(error.message).toContain('SSL Certificate error'); })); + it('should fail when main resources failed to load', SX(async function() { + let error = null; + try { + await page.navigate('chrome-devtools://devtools/bundled/inspector.html'); + } catch (e) { + error = e; + } + expect(error.message).toContain('Failed to navigate'); + })); it('should fail when exceeding maximum navigation timeout', SX(async function() { let error = null; // Hang for request to the empty.html