From 5c9050aea0fe8d57114130fe38bd33ed2b4955d6 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 2 Jun 2022 13:27:31 +0200 Subject: [PATCH] fix: use isPageTargetCallback in Browser::pages() (#8460) --- src/common/Browser.ts | 16 +++++++++++++++- src/common/Target.ts | 7 +++++++ test/headful.spec.ts | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/common/Browser.ts b/src/common/Browser.ts index bf8cb39f..60208af9 100644 --- a/src/common/Browser.ts +++ b/src/common/Browser.ts @@ -326,6 +326,13 @@ export class Browser extends EventEmitter { }); } + /** + * @internal + */ + _getIsPageTargetCallback(): IsPageTargetCallback | undefined { + return this._isPageTargetCallback; + } + /** * Creates a new incognito browser context. This won't share cookies/cache with other * browser contexts. @@ -782,7 +789,14 @@ export class BrowserContext extends EventEmitter { async pages(): Promise { const pages = await Promise.all( this.targets() - .filter((target) => target.type() === 'page') + .filter( + (target) => + target.type() === 'page' || + (target.type() === 'other' && + this._browser._getIsPageTargetCallback()?.( + target._getTargetInfo() + )) + ) .map((target) => target.page()) ); return pages.filter((page): page is Page => !!page); diff --git a/src/common/Target.ts b/src/common/Target.ts index c1c26974..08400865 100644 --- a/src/common/Target.ts +++ b/src/common/Target.ts @@ -113,6 +113,13 @@ export class Target { return this._sessionFactory(); } + /** + * @internal + */ + _getTargetInfo(): Protocol.Target.TargetInfo { + return this._targetInfo; + } + /** * If the target is not of type `"page"` or `"background_page"`, returns `null`. */ diff --git a/test/headful.spec.ts b/test/headful.spec.ts index b41eabc8..54c3b044 100644 --- a/test/headful.spec.ts +++ b/test/headful.spec.ts @@ -145,6 +145,7 @@ describeChromeOnly('headful tests', function () { ); const page = await devtoolsPageTarget.page(); expect(await page.evaluate(() => 2 * 3)).toBe(6); + expect(await browser.pages()).toContainEqual(page); await browser.close(); }); it('should have default url when launching browser', async function () {