feat(browsercontext): add BrowserContext.pages() method (#3003)

This commit is contained in:
Andrey Lushnikov
2018-07-31 13:24:29 -07:00
committed by GitHub
parent 25d7eff374
commit c018ff1555
3 changed files with 25 additions and 6 deletions

View File

@@ -183,12 +183,9 @@ class Browser extends EventEmitter {
* @return {!Promise<!Array<!Puppeteer.Page>>}
*/
async pages() {
const pages = await Promise.all(
this.targets()
.filter(target => target.type() === 'page')
.map(target => target.page())
);
return pages.filter(page => !!page);
const contextPages = await Promise.all(this.browserContexts().map(context => context.pages()));
// Flatten array.
return contextPages.reduce((acc, x) => acc.concat(x), []);
}
/**
@@ -250,6 +247,18 @@ class BrowserContext extends EventEmitter {
return this._browser.targets().filter(target => target.browserContext() === this);
}
/**
* @return {!Promise<!Array<!Puppeteer.Page>>}
*/
async pages() {
const pages = await Promise.all(
this.targets()
.filter(target => target.type() === 'page')
.map(target => target.page())
);
return pages.filter(page => !!page);
}
/**
* @return {boolean}
*/