mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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:
parent
91e54378a3
commit
2f74644cb8
@ -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]);
|
||||
}
|
||||
|
||||
|
11
test/test.js
11
test/test.js
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user