Puppeteer's Page.navigate should not throw with invalid URL.

This patch makes puppeteer's Page.navigate to just return
'false' when given an invalid URL.
This commit is contained in:
Andrey Lushnikov 2017-05-14 22:17:57 -07:00
parent 91e54378a3
commit 2f74644cb8
2 changed files with 16 additions and 1 deletions

View File

@ -260,7 +260,11 @@ class Page extends EventEmitter {
var interstitialPromise = new Promise(fulfill => this._client.once('Security.certificateError', fulfill)).then(() => false);
var referrer = this._extraHeaders.referer;
// Await for the command to throw exception in case of illegal arguments.
await this._client.send('Page.navigate', {url, referrer});
try {
await this._client.send('Page.navigate', {url, referrer});
} catch (e) {
return false;
}
return await Promise.race([loadPromise, interstitialPromise]);
}

View File

@ -40,6 +40,17 @@ describe('Puppeteer', function() {
expect(msgs).toEqual(['Message!']);
}));
describe('Page.navigate', function() {
it('should fail when navigating to bad url', SX(async function() {
var success = await page.navigate('asdfasdf');
expect(success).toBe(false);
}));
it('should succeed when navigating to good url', SX(async function() {
var success = await page.navigate(EMPTY_PAGE);
expect(success).toBe(true);
}));
});
describe('Page.setInPageCallback', function() {
it('should work', SX(async function() {
await page.setInPageCallback('callController', function(a, b) {