feat(target): add support for target.page for 'backgroud_page' (#2600)

This patch teaches `target.page()` method to attach to extension background pages.

Fixes #2438
This commit is contained in:
Yaniv Efraim
2018-06-14 23:58:51 +03:00
committed by Andrey Lushnikov
parent cd8d750628
commit 38f112f395
4 changed files with 16 additions and 4 deletions

View File

@@ -183,7 +183,11 @@ class Browser extends EventEmitter {
* @return {!Promise<!Array<!Puppeteer.Page>>}
*/
async pages() {
const pages = await Promise.all(this.targets().map(target => target.page()));
const pages = await Promise.all(
this.targets()
.filter(target => target.type() === 'page')
.map(target => target.page())
);
return pages.filter(page => !!page);
}

View File

@@ -38,7 +38,7 @@ class Target {
* @return {!Promise<?Page>}
*/
async page() {
if (this._targetInfo.type === 'page' && !this._pagePromise) {
if ((this._targetInfo.type === 'page' || this._targetInfo.type === 'background_page') && !this._pagePromise) {
this._pagePromise = this._sessionFactory()
.then(client => Page.create(client, this, this._ignoreHTTPSErrors, this._setDefaultViewport, this._screenshotTaskQueue));
}