fix(adb): enable newPage in mobile browser (#4728)

This commit is contained in:
Pavel Feldman 2020-12-15 15:14:16 -08:00 committed by GitHub
parent eecb798356
commit 97be66b15c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -316,7 +316,27 @@ export class CRBrowserContext extends BrowserContext {
async newPageDelegate(): Promise<PageDelegate> {
assertBrowserContextIsNotOwned(this);
const { targetId } = await this._browser._session.send('Target.createTarget', { url: 'about:blank', browserContextId: this._browserContextId });
const oldKeys = this._browser.isClank() ? new Set(this._browser._crPages.keys()) : undefined;
let { targetId } = await this._browser._session.send('Target.createTarget', { url: 'about:blank', browserContextId: this._browserContextId });
if (oldKeys) {
// Chrome for Android returns tab ids (1, 2, 3, 4, 5) instead of content target ids here, work around it via the
// heuristic assuming that there is only one page created at a time.
const newKeys = new Set(this._browser._crPages.keys());
// Remove old keys.
for (const key of oldKeys)
newKeys.delete(key);
// Remove potential concurrent popups.
for (const key of newKeys) {
const page = this._browser._crPages.get(key)!;
if (page._opener)
newKeys.delete(key);
}
assert(newKeys.size === 1);
[ targetId ] = [...newKeys];
}
return this._browser._crPages.get(targetId)!;
}

View File

@ -29,4 +29,13 @@ if (process.env.PW_ANDROID_TESTS) {
expect(await page.title()).toBe('Hello world!');
await context.close();
});
it('should create new page', async function({ device }) {
const context = await device.launchBrowser();
const page = await context.newPage();
await page.goto('data:text/html,<title>Hello world!</title>');
expect(await page.title()).toBe('Hello world!');
await page.close();
await context.close();
});
}