Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: add fixme test for binding called from pagehide in chromium (#43073)

Dmitry Gozmanca64f9f19c7d
diff --git a/tests/library/browsercontext-expose-function.spec.ts b/tests/library/browsercontext-expose-function.spec.ts
index ab1acc37ab..6050f5961f 100644
--- a/tests/library/browsercontext-expose-function.spec.ts
+++ b/tests/library/browsercontext-expose-function.spec.ts
@@ -97,3 +97,24 @@ it('should work with CSP', async ({ page, context, server }) => {
await page.evaluate(() => (window as any).hi());
expect(called).toBe(true);
});
+
+it('should call binding from pagehide handler when navigating away', {
+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43064' },
+}, async ({ context, page, server, browserName }) => {
+ it.fixme(browserName === 'chromium', 'Chromium drops CDP events from the old document after the frame host swap');
+ const calls: string[] = [];
+ await context.exposeBinding('reportFromPage', (_source, message: string) => { calls.push(message); });
+ const html = (body: string) => `<!doctype html>${body}<script>addEventListener('pagehide', () => window.reportFromPage('pagehide of ' + location.pathname));</script>`;
+ server.setRoute('/a.html', (req, res) => {
+ res.writeHead(200, { 'content-type': 'text/html' });
+ res.end(html(`<a id="next" href="/b.html">next</a>`));
+ });
+ server.setRoute('/b.html', (req, res) => {
+ res.writeHead(200, { 'content-type': 'text/html' });
+ res.end(html(`<p>b</p>`));
+ });
+ await page.goto(server.PREFIX + '/a.html');
+ await page.click('#next');
+ await page.waitForURL('**/b.html');
+ await expect.poll(() => calls).toContain('pagehide of /a.html');
+});