fix: use isPageTargetCallback in Browser::pages() (#8460)

This commit is contained in:
Alex Rudenko 2022-06-02 13:27:31 +02:00 committed by GitHub
parent cf49b18beb
commit 5c9050aea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -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<Page[]> {
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);

View File

@ -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`.
*/

View File

@ -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 () {