feat(Page): teach Page.setContent to wait for resources to load (#1152)

This patch adds "options" parameter to the `page.setContent` method. The
parameter is the same as a navigation parameter and allows to specify
maximum timeout to wait for resources to be loaded, as well as to
describe events that should be emitted before the setContent operation
would be considered successful.

Fixes #728.
This commit is contained in:
Andrey Lushnikov
2017-10-24 13:57:39 -07:00
committed by GitHub
parent f38c8bb17b
commit 80ee469429
3 changed files with 36 additions and 14 deletions

View File

@@ -437,13 +437,17 @@ class Page extends EventEmitter {
/**
* @param {string} html
* @param {!Object=} options
*/
async setContent(html) {
await this.evaluate(html => {
document.open();
document.write(html);
document.close();
}, html);
async setContent(html, options) {
await Promise.all([
this.evaluate(html => {
document.open();
document.write(html);
document.close();
}, html),
this.waitForNavigation(options),
]);
}
/**