fix: exception in exposeFunction when oopif detaches (#18078)

The test is racy but it was reliably failing several times in 100
iterations.

Fixes https://github.com/microsoft/playwright/issues/18067
This commit is contained in:
Yury Semikhatsky 2022-10-14 08:37:42 -07:00 committed by GitHub
parent 1c1060e85b
commit 7219a68b12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -133,7 +133,7 @@ export class CRPage implements PageDelegate {
return cb(frameSession);
return cb(frameSession).catch(e => {
// Broadcasting a message to the closed iframe shoule be a noop.
if (e.message && (e.message.includes('Target closed.') || e.message.includes('Session closed.')))
if (e.message && e.message.includes('Target closed'))
return;
throw e;
});

View file

@ -326,6 +326,16 @@ it('should emit filechooser event for iframe', async ({ page, server, browser })
expect(chooser).toBeTruthy();
});
it('should not throw on exposeFunction when oopif detaches', async ({ page, browser, server }) => {
await page.goto(server.PREFIX + '/dynamic-oopif.html');
expect(await countOOPIFs(browser)).toBe(1);
await Promise.all([
page.exposeFunction('myFunc', () => 2022),
page.evaluate(() => document.querySelector('iframe').remove()),
]);
expect(await page.evaluate(() => (window as any).myFunc())).toBe(2022);
});
async function countOOPIFs(browser) {
const browserSession = await browser.newBrowserCDPSession();
const oopifs = [];