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:
Andrey Lushnikov
2017-07-10 15:09:52 -07:00
parent a7e91dc126
commit 50d9c186b5
8 changed files with 251 additions and 64 deletions

View File

@@ -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;
}
/**