pychrome icon indicating copy to clipboard operation
pychrome copied to clipboard

WebSocketBadStatusException raised when connecting to webSocketDebuggerUrl in Chrome 108+

Open realwumbl3 opened this issue 2 years ago • 7 comments

When using PyChrome to connect to a tab's "webSocketDebuggerUrl" in Chrome 108 or newer, the following error is raised: "websocket._exceptions.WebSocketBadStatusException: Handshake status 403 Forbidden".

realwumbl3 avatar Feb 21 '23 00:02 realwumbl3

Seems to be related to Chrome checking the Origin of the incoming request. The recommended fix seems to be to suppress the header entirely: https://bugs.chromium.org/p/chromium/issues/detail?id=1422444#c5

I added an extra kwarg suppress_origin=True and that fixed the issue.

https://github.com/fate0/pychrome/blob/c6c755b9964eead9a84dd57e84f53eb9981b26ac/pychrome/tab.py#L208

jerivas avatar Mar 13 '23 21:03 jerivas

I tried it and that worked! Thanks and good job! 💖

realwumbl3 avatar Mar 13 '23 22:03 realwumbl3

suppress_origin=True

This fix worked. Can you raise the PR for this?

sc231997 avatar Mar 29 '23 05:03 sc231997

@sc231997 feel free to include it in #62

jerivas avatar Mar 29 '23 16:03 jerivas

@sc231997 feel free to include it in #62

Done!

sc231997 avatar Mar 30 '23 09:03 sc231997

version(0.2.4) I'm using has this suppress_origin=True and still not working

independent of any port I use.

chrome version: 117.0.5938.63

rrfaria avatar Sep 13 '23 17:09 rrfaria

still not working

start chrome with one of

--remote-allow-origins=http://localhost:5222
--remote-allow-origins=*

chrome will print this to stderr

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

see also

  • https://github.com/MasterDevs/ChromeDevTools/issues/52#issuecomment-1500857987
  • https://github.com/marty90/PyChromeDevTools/issues/28#issuecomment-1491529548

milahu avatar Nov 22 '23 13:11 milahu