playwright: [Bug]: Status code 404 gives net::ERR_HTTP_RESPONSE_CODE_FAILURE

Version

1.49.1

Steps to reproduce

Example steps (replace with your own):

  1. save this code as a script and run it
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)
    context = browser.new_context()
    page = context.new_page()
    res = page.goto('http://httpbin.org/status/404')
    html = page.content()
    page.close()
  1. Run the script and it will crash once it reaches the page.

Expected behavior

I expect to get a response with error code 404 as before the last update

Actual behavior

I get this error:

Traceback (most recent call last):
  File "/Users/karim/rebrowser.py", line 7, in <module>
    res = page.goto('http://httpbin.org/status/404')
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/karim/.venv/lib/python3.12/site-packages/playwright/sync_api/_generated.py", line 9006, in goto
    self._sync(
  File "/Users/karim/.venv/lib/python3.12/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
    return task.result()
           ^^^^^^^^^^^^^
  File "/Users/karim/.venv/lib/python3.12/site-packages/playwright/_impl/_page.py", line 551, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/karim/.venv/lib/python3.12/site-packages/playwright/_impl/_frame.py", line 145, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "/Users/karim/.venv/lib/python3.12/site-packages/playwright/_impl/_connection.py", line 61, in send
    return await self._connection.wrap_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/karim/.venv/lib/python3.12/site-packages/playwright/_impl/_connection.py", line 528, in wrap_api_call
    raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.Error: Page.goto: net::ERR_HTTP_RESPONSE_CODE_FAILURE at http://httpbin.org/status/404
Call log:
  - navigating to "http://httpbin.org/status/404", waiting until "load"

Additional context

This happens only with pages that give the error 404 without an HTML response. It didn’t happen before 1.49; I just noticed it because I use httpbin in my unit tests.

Environment

- Operating System: MacOS 15.1.1
- CPU: M1
- Browser: Chromium
- Python Version: 3.12.7

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

look. let’s be honest it sucks. but directing your anger to me is not gonna solve your problem.

Catch the error. then do:

status_code = browser.evaluate("window.performance.getEntries()[0].responseStatus")

and get underlying status code and that would be it.

I don’t maintain this. I am trying to help instead of mocking your skill issues. How does it feel?

Sorry mate, I thought you are one of the maintainers, I don’t know who work on this. Your solution looks neat I will try it. Thanks for looking into it.

I didn’t try to solve it or work for a workaround as it’s not that big issue and I want to see the maintainers comment about this first!

Sorry again