Skip to content
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

WebSocketBadStatusException: Handshake status 403 Forbidden when connecting to >= WebView 111.0.5563.58 #28

Open
Igorxp5 opened this issue Mar 30, 2023 · 1 comment

Comments

@Igorxp5
Copy link

Igorxp5 commented Mar 30, 2023

I'm getting following error for recent versions of WebView.

Call: PyChromeDevTools.ChromeInterface(host='127.0.0.1', port=37461, timeout=5)

Stack trace:

    websock.connect(url, **options)
  File "/home/.../.pyenv/versions/venv/lib/python3.10/site-packages/websocket/_core.py", line 253, in connect
    self.handshake_response = handshake(self.sock, url, *addrs, **options)
  File "/home/.../.pyenv/versions/venv/lib/python3.10/site-packages/websocket/_handshake.py", line 57, in handshake
    status, resp = _get_resp_headers(sock)
  File "/home/.../.pyenv/versions/venv/lib/python3.10/site-packages/websocket/_handshake.py", line 147, in _get_resp_headers
    raise WebSocketBadStatusException("Handshake status %d %s", status, status_message, resp_headers)
websocket._exceptions.WebSocketBadStatusException: Handshake status 403 Forbidden

It sems server is not accepting connection from the localhost. When I've added suppress_origin=True to create_connection call it worked.

@marty90
Copy link
Owner

marty90 commented Mar 31, 2023

The problem is not PyChromeDevTools, but Chrome, which added a mechanism for which the user must specify a whitelist of origins that can establish WebSocket connection.
Indeed, if you look at the stdout of Chrome, you see:

[1182969:1182969:0331/102931.723102:ERROR:devtools_http_handler.cc(766)] Rejected an incoming WebSocket connection from the http://localhost:9222 origin. Use the command line flag --remote-allow-origins=http://localhost:9222 to allow connections from this origin or --remote-allow-origins=* to allow all origins.

So, please run Chrome with the --remote-allow-origins=* option.
I added a note on the Readme.

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