diff --git a/docs/api.md b/docs/api.md index a27aee22..154fb144 100644 --- a/docs/api.md +++ b/docs/api.md @@ -461,6 +461,9 @@ The `page.navigate` will throw an error if: - there's an SSL error (e.g. in case of self-signed certificates). - target URL is invalid. - the `timeout` is exceeded during navigation. +- the main resource failed to load. + +> **NOTE** `page.navigate` either throw or return a main resource response. The only exception is navigation to `about:blank`, which would succeed and return `null`. #### page.pdf(options) - `options` <[Object]> Options object which might have the following properties: diff --git a/lib/Page.js b/lib/Page.js index 6cabff24..fe5f3b1d 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -242,7 +242,7 @@ class Page extends EventEmitter { /** * @param {string} html * @param {!Object=} options - * @return {!Promise} + * @return {!Promise} */ async navigate(url, options) { const watcher = new NavigatorWatcher(this._client, options); @@ -260,6 +260,8 @@ class Page extends EventEmitter { } await result; helper.removeEventListeners([listener]); + if (url === 'about:blank') + return null; let response = responses.get(this.mainFrame().url()); if (!response) throw new Error('Failed to navigate: ' + url); diff --git a/test/test.js b/test/test.js index 98137382..a0b39e13 100644 --- a/test/test.js +++ b/test/test.js @@ -443,6 +443,10 @@ describe('Puppeteer', function() { }); describe('Page.navigate', function() { + it('should navigate to about:blank', SX(async function() { + let response = await page.navigate('about:blank'); + expect(response).toBe(null); + })); it('should fail when navigating to bad url', SX(async function() { let error = null; try {