microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.96k stars 3.59k forks source link

[Bug]: 204 response are considered failed #32752

Open Mattwmaster58 opened 1 week ago

Mattwmaster58 commented 1 week ago

Version

1.47

Steps to reproduce

server for serving HTML (doesn't matter how, just an example):

from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return '''
<!DOCTYPE html>
<html>
<script>
  fetch('https://httpbin.org/status/204');
</script>
</html>
    '''

if __name__ == '__main__':
    app.run(debug=True, port=5001)

repro:

import asyncio

from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        def catch_request_failure(s):
            print(s.url, " failed ", s.failure)
        page.on("requestfailed", catch_request_failure)
        await page.goto("http://127.0.0.1:5001", wait_until="networkidle")

asyncio.run(main())

Expected behavior

No output from the script. There are no requests that have failed.

Actual behavior

https://httpbin.org/status/204  failed  net::ERR_ABORTED

This isn't true, the request succeeded. If you run with launch(devtools=True) then you can see the very request in the devtools and that it did succeed.

Additional context

Similar to https://github.com/microsoft/playwright/issues/26897, https://github.com/microsoft/playwright/issues/31570

However, this time I think it's different as instead of talking about a Page.goto call, it's a request initiated by the page. There was justification in #31570 that a failure of navigation could be technically correct as no navigation takes place, but for a request initiated by a page, I do not think that a requestfailed event is correct.

In my use case, I monitor the requests that a site makes on load for privacy assessment. It's important to know whether a request was actually made or whether it happened to failed.

Environment

System:
    OS: Linux 6.10 EndeavourOS
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 38.26 GB / 62.71 GB
    Container: Yes
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
  IDEs:
    VSCode: 1.92.1 - /usr/bin/code
  Languages:
    Bash: 5.2.32 - /usr/bin/bash
yury-s commented 5 days ago

Related WebKit change https://github.com/microsoft/playwright/pull/1260