microsoft / playwright-python

Python version of the Playwright testing and automation library.
https://playwright.dev/python/
Apache License 2.0
11.87k stars 906 forks source link

[Bug]: Abort not working correctly #2574

Closed mostafamdy closed 1 month ago

mostafamdy commented 1 month ago

Version

1.45.1

Steps to reproduce

I attempted to block image (.png) and monitor network traffic using Burp Suite Proxy I observed that these requests were still being made, as shown by Burp Suite

Code Used to Abort .png Requests:

page.route("**/*.png", lambda route: route.abort())

Proxy Setup with Burp Suite:

I configured Playwright to use Burp Suite as a proxy with the following parameters:

params = {
    "headless": HEADLESS,
    "args": [
        "--no-sandbox",
        "--disable-setuid-sandbox",
        "--disable-dev-shm-usage",
        "--disable-web-security",
        "--disable-notifications",
    ],
}
b = p.firefox.launch(proxy={"server": "http://127.0.0.1:8080"}, **params)

Expected behavior

.

Actual behavior

.

Additional context

No response

Environment

- Operating System: windows 10
- CPU: [arm64]
- Browser: Firefox
- Python Version: 3.11.9
mostafamdy commented 1 month ago

I tried this code:

def route_handler(route):
    request = route.request
    url = request.url.lower()
    print(url)
    if ".png" in url or ".ico" in url:
        route.abort()
        print('Aborted')

page.route('**/*', route_handler)

some images are successfully blocked and others don't seem to trigger the function. The URLs aren't being printed, although they are visible in both Burp Suite and the browser.

mostafamdy commented 1 month ago

this website do many requests at the same time so may be playwright is vulnerable to race condition?

mxschmitt commented 1 month ago

Would it be possible to share a full reproduction with us? Ideally a script which we can run locally with expected and actual outcome.

mxschmitt commented 1 month ago

Closing as per above. Feel free to re-file with a working reproduction.