mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Change Page.navigate to return main resource response
This patch changes Page.navigate API: - Page.navigate now resolves to the main page response - Page.navigate throws errors if there's no main page response, e.g. in case of SSL errors, max navigation timeout, or invalid url. This patch also adds httpsServer with a self-signed certificates for the testing purposes. Fixes #10.
This commit is contained in:
22
lib/Page.js
22
lib/Page.js
@@ -260,10 +260,26 @@ class Page extends EventEmitter {
|
||||
/**
|
||||
* @param {string} html
|
||||
* @param {!Object=} options
|
||||
* @return {!Promise<boolean>}
|
||||
* @return {!Promise<!Response>}
|
||||
*/
|
||||
navigate(url, options) {
|
||||
return new Navigator(this._client, url, this._networkManager.httpHeaders().referer, options).navigate();
|
||||
async navigate(url, options) {
|
||||
/** @type {!Map<string, !Response>} */
|
||||
const responses = new Map();
|
||||
const onResponse = response => responses.set(response.url, response);
|
||||
const navigator = new Navigator(this._client, url, this._networkManager.httpHeaders().referer, options);
|
||||
|
||||
try {
|
||||
this._networkManager.on(NetworkManager.Events.Response, onResponse);
|
||||
await navigator.navigate();
|
||||
} catch (e) {
|
||||
this._networkManager.removeListener(NetworkManager.Events.Response, onResponse);
|
||||
throw e;
|
||||
}
|
||||
|
||||
this._networkManager.removeListener(NetworkManager.Events.Response, onResponse);
|
||||
const response = responses.get(this.mainFrame().url());
|
||||
console.assert(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user