Websocket is closing before connection is established

I get this error: VM595 frame:1364 WebSocket connection to ‘ws://localhost:4000/phoenix/live_reload/socket/websocket?vsn=2.0.0’ failed: WebSocket is closed before the connection is established.

and I don’t know how to debug this.
Also, on a possibly related matter, my live_reload stopped working.

I went through the obvious topics such as dependencies and I went through the configurations. But where would I even look further?

The server-side part of phoenix_live_reload is not likely to encounter issues.

Focus on inspecting the browser part, such as:

  • if the <iframe /> element (<iframe hidden="" height="0" width="0" src="/phoenix/live_reload/frame"></iframe>) is injected into <body /> ?

I encountered the same error as you.

The reason for my error was that generated HTML did not include a <body /> element, which caused phoenix_live_reload to fail in injecting code.

(I put <body /> in app.html.heex instead of root.html.heex. I assumed this should work, but Phoenix.LiveView does not function the way I assumed.)