Skip to content

Commit

Permalink
fix: use isPageTargetCallback in Browser::pages() (#8460)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Jun 2, 2022
1 parent cf49b18 commit 5c9050a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/common/Browser.ts
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/common/Target.ts
Expand Up @@ -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`.
*/
Expand Down
1 change: 1 addition & 0 deletions test/headful.spec.ts
Expand Up @@ -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 () {
Expand Down

0 comments on commit 5c9050a

Please sign in to comment.