Skip to content

[Bug]: page.close() hangs on Chromium when racing with cross-origin navigation commit #41900

Closed as duplicate

Description

@gofr

Version

1.61.1

Steps to reproduce

Steps:

  1. Load page on origin A (port X)
  2. Navigate cross-origin to origin B (port Y)
  3. After 10ms, navigate back to origin A
  4. Call page.close()
import http from 'node:http';

import { test as base } from '@playwright/test';

function createServer(): Promise<{ url: string; close: () => void }> {
  return new Promise((resolve) => {
    const server = http.createServer((_req, res) => {
      res.writeHead(200, { 'content-type': 'text/html' });
      res.end('<html><body>ok</body></html>');
    });
    server.listen(0, '127.0.0.1', () => {
      const port = (server.address() as { port: number }).port;
      resolve({ url: `http://127.0.0.1:${port}`, close: () => server.close() });
    });
  });
}

const test = base.extend<{ origins: [string, string] }>({
  async origins({}, use) {
    const a = await createServer();
    const b = await createServer();
    await use([a.url, b.url]);
    a.close();
    b.close();
  },
});

test.describe('page.close() race with cross-origin navigation commit', () => {
  for (let i = 0; i < 30; i++) {
    test(`attempt ${i}`, async ({ context, origins: [originA, originB] }) => {
      test.setTimeout(10_000);
      const page = await context.newPage();
      await page.goto(originA);

      // Cross-origin nav: A → B
      page.goto(originB).catch(() => {});
      await new Promise((r) => setTimeout(r, 10));

      // Cross-origin nav: B → A (second RFH swap)
      page.goto(originA).catch(() => {});

      // Races with the second commit — hangs sometimes
      await page.close();
    });
  }
});

Expected behavior

All tests pass

Actual behavior

Some tests time out, hanging on the page.close()

Additional context

Probably caused by https://issues.chromium.org/issues/536385539 which is presumably also the cause of #41695.

Environment

System:
    OS: Linux 6.18 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (12) x64 13th Gen Intel(R) Core(TM) i7-1365U
    Memory: 11.55 GB / 15.45 GB
    Container: Yes
  Binaries:
    Node: 24.14.0 - /mnt/wslg/runtime-dir/fnm_multishells/<redacted>/bin/node
    Yarn: 1.22.22 - /mnt/wslg/runtime-dir/fnm_multishells/<redacted>/bin/yarn
    npm: 11.16.0 - /mnt/wslg/runtime-dir/fnm_multishells/<redacted>/bin/npm
    pnpm: 10.13.1 - /home/<redacted>/.local/share/pnpm/pnpm
  IDEs:
    VSCode: 1.129.1 - /mnt/c/Users/<redacted>/AppData/Local/Programs/Microsoft VS Code/bin/code
  Languages:
    Bash: 5.1.16 - /usr/bin/bash
  npmPackages:
    @playwright/test: 1.61.1 => 1.61.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions