fix: use isPageTargetCallback in Browser::pages() (#8460)
This commit is contained in:
parent
cf49b18beb
commit
5c9050aea0
@ -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
|
* Creates a new incognito browser context. This won't share cookies/cache with other
|
||||||
* browser contexts.
|
* browser contexts.
|
||||||
@ -782,7 +789,14 @@ export class BrowserContext extends EventEmitter {
|
|||||||
async pages(): Promise<Page[]> {
|
async pages(): Promise<Page[]> {
|
||||||
const pages = await Promise.all(
|
const pages = await Promise.all(
|
||||||
this.targets()
|
this.targets()
|
||||||
.filter((target) => target.type() === 'page')
|
.filter(
|
||||||
|
(target) =>
|
||||||
|
target.type() === 'page' ||
|
||||||
|
(target.type() === 'other' &&
|
||||||
|
this._browser._getIsPageTargetCallback()?.(
|
||||||
|
target._getTargetInfo()
|
||||||
|
))
|
||||||
|
)
|
||||||
.map((target) => target.page())
|
.map((target) => target.page())
|
||||||
);
|
);
|
||||||
return pages.filter((page): page is Page => !!page);
|
return pages.filter((page): page is Page => !!page);
|
||||||
|
@ -113,6 +113,13 @@ export class Target {
|
|||||||
return this._sessionFactory();
|
return this._sessionFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
_getTargetInfo(): Protocol.Target.TargetInfo {
|
||||||
|
return this._targetInfo;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the target is not of type `"page"` or `"background_page"`, returns `null`.
|
* If the target is not of type `"page"` or `"background_page"`, returns `null`.
|
||||||
*/
|
*/
|
||||||
|
@ -145,6 +145,7 @@ describeChromeOnly('headful tests', function () {
|
|||||||
);
|
);
|
||||||
const page = await devtoolsPageTarget.page();
|
const page = await devtoolsPageTarget.page();
|
||||||
expect(await page.evaluate(() => 2 * 3)).toBe(6);
|
expect(await page.evaluate(() => 2 * 3)).toBe(6);
|
||||||
|
expect(await browser.pages()).toContainEqual(page);
|
||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
it('should have default url when launching browser', async function () {
|
it('should have default url when launching browser', async function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user