diff --git a/src/common/FrameManager.ts b/src/common/FrameManager.ts index ba1c9ba2237..c2639a956d3 100644 --- a/src/common/FrameManager.ts +++ b/src/common/FrameManager.ts @@ -256,7 +256,7 @@ export class FrameManager extends EventEmitter { const session = Connection.fromSession(this._client).session( event.sessionId ); - frame._updateClient(session); + if (frame) frame._updateClient(session); this.setupEventListeners(session); await this.initialize(session); } diff --git a/test/oopif.spec.ts b/test/oopif.spec.ts index 883936d6e61..2696ac6ebb2 100644 --- a/test/oopif.spec.ts +++ b/test/oopif.spec.ts @@ -28,7 +28,10 @@ describeChromeOnly('OOPIF', function () { const { puppeteer, defaultBrowserOptions } = getTestState(); browser = await puppeteer.launch( Object.assign({}, defaultBrowserOptions, { - args: (defaultBrowserOptions.args || []).concat(['--site-per-process']), + args: (defaultBrowserOptions.args || []).concat([ + '--site-per-process', + '--remote-debugging-port=21222', + ]), }) ); }); @@ -309,6 +312,26 @@ describeChromeOnly('OOPIF', function () { expect(result.x).toBeGreaterThan(150); // padding + margin + border left expect(result.y).toBeGreaterThan(150); // padding + margin + border top }); + + it('should detect existing OOPIFs when Puppeteer connects to an existing page', async () => { + const { server, puppeteer } = getTestState(); + + const frame = page.waitForFrame((frame) => + frame.url().endsWith('/oopif.html') + ); + await page.goto(server.PREFIX + '/dynamic-oopif.html'); + await frame; + expect(oopifs(context).length).toBe(1); + expect(page.frames().length).toBe(2); + + const browserURL = 'http://127.0.0.1:21222'; + const browser1 = await puppeteer.connect({ browserURL }); + const target = await browser1.waitForTarget((target) => + target.url().endsWith('dynamic-oopif.html') + ); + await target.page(); + browser1.disconnect(); + }); }); /**