Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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