Skip to content

[Bug]: Python: await page.route() hangs indefinitely on macOS with pytest #35757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
willthefirst opened this issue Apr 25, 2025 · 1 comment

Comments

@willthefirst
Copy link

Version

1.51.0

Steps to reproduce

Code Snippet

# Minimal Reproducible Example (tests/test_minimal_playwright_route.py)
# Needs: pytest, pytest-asyncio, pytest-playwright
import pytest
from playwright.async_api import Page
import asyncio

# Using pytest-playwright page fixture

@pytest.mark.asyncio
async def test_minimal_route_hang(page: Page):
    print("LOG: Minimal Test (pytest-playwright) - START")

    print("LOG: Minimal Test (pytest-playwright) - Setting up route interception...")
    try:
        # THIS LINE HANGS INDEFINITELY
        await page.route("**/*",
            lambda route: print(f"LOG: Minimal Test (pytest-playwright) - Intercepted {route.request.url}")
        )
        print("LOG: Minimal Test (pytest-playwright) - Route interception setup COMPLETE.")
    except Exception as e:
        print(f"LOG: Minimal Test (pytest-playwright) - ERROR during page.route setup: {e}")
        pytest.fail(f"page.route setup failed: {e}")

    # --- Code below this line is never reached ---
    print("LOG: Minimal Test (pytest-playwright) - Navigating to example.com...")
    try:
        await page.goto("http://example.com", timeout=10000)
        print("LOG: Minimal Test (pytest-playwright) - Navigation COMPLETE.")
    except Exception as e:
        print(f"LOG: Minimal Test (pytest-playwright) - ERROR during navigation: {e}")
        pytest.fail(f"Navigation failed: {e}")

    await page.wait_for_timeout(2000)
    print("LOG: Minimal Test (pytest-playwright) - END")
# pytest.ini
[pytest]
pythonpath = .
asyncio_mode = strict
asyncio_default_test_loop_scope = session
addopts = -v --asyncio-mode=strict
filterwarnings =
    ignore::DeprecationWarning:starlette
    ignore::PendingDeprecationWarning:starlette

Libraries Used:

  • pytest: 8.3.5
  • pytest-asyncio: 0.26.0
  • pytest-playwright: 0.7.0

Steps to Reproduce:

  1. Set up a Python 3.11 environment on macOS.
  2. Install the required libraries: pip install "pytest==8.3.5" "pytest-asyncio==0.26.0" "pytest-playwright==0.7.0" "playwright==1.51.0"
  3. Run playwright install.
  4. Save the minimal Python code above as tests/test_minimal_playwright_route.py.
  5. Save the pytest.ini content in the project root.
  6. Run the test from the project root using the command: pytest -v -s tests/test_minimal_playwright_route.py

Expected behavior

Expected Result:

The test execution should print the following logs (or similar) and eventually complete or fail during navigation/timeout:

LOG: Minimal Test (pytest-playwright) - START
LOG: Minimal Test (pytest-playwright) - Setting up route interception...
LOG: Minimal Test (pytest-playwright) - Route interception setup COMPLETE.
LOG: Minimal Test (pytest-playwright) - Navigating to example.com...

Actual behavior

Actual Result:

The test execution prints the following and then hangs indefinitely. It never proceeds past the await page.route(...) call and must be manually interrupted (Ctrl+C).

LOG: Minimal Test (pytest-playwright) - START
LOG: Minimal Test (pytest-playwright) - Setting up route interception...

Additional context

No response

Environment

System:
    OS: macOS 15.3.2
    CPU: (8) arm64 Apple M2
    Memory: 374.73 MB / 24.00 GB
  Binaries:
    Node: 18.18.1 - ~/.nvm/versions/node/v18.18.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v18.18.1/bin/npm
    pnpm: 9.5.0 - ~/.nvm/versions/node/v18.18.1/bin/pnpm
    bun: 1.0.6 - /opt/homebrew/bin/bun
  IDEs:
    VSCode: 1.99.2 - /usr/local/bin/code
  Languages:
    Bash: 3.2.57 - /bin/bash
@mxschmitt
Copy link
Member

mxschmitt commented Apr 26, 2025

I was not able to reproduce that it hangs indefinitely. For me it was throwing after 10s. Are you intentionally not calling continue/fulfill etc. in the route handler?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants