mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	fix(adb): enable newPage in mobile browser (#4728)
This commit is contained in:
		
							parent
							
								
									eecb798356
								
							
						
					
					
						commit
						97be66b15c
					
				@ -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)!;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user