Local Network Access for HTML5 Export

Godot Version

4.7

Question

I asked this question on the Discord, and I figure I’ll ask here, too.

I’m trying to build a sort of Jackbox-esque local party game, where the game server runs on desktop, and the clients are HTML5, with the players going to the web page (either locally hosted and spun up by the game server, or hosted on itch.io) on their phones.

So I’m testing Web Sockets with the WebSockets Chat Demo, and I’m having issues accessing the LAN on the HTML5 export. If the web page is hosted and accessed from the same machine without a security certificate (i.e. by running serve.py on the HTML5 export), the client can connect to the desktop host on another device no problem. As soon as https gets involved, things fall apart. If I host the website with a developer certificate, LAN access is denied, even if the desktop host is on the same machine, and if I host with a legit certificate (i.e. hosting it on itch.io), LAN access is still denied.

The thing about hosting on itch is that Local Network Access doesn’t appear to even be being requested, because I’m not getting any permission pop-up. I’ve tried using JavaScripBridge.eval to check the permissions, but since navigator.permissions.query({ name: “local-network” }) returns a Promise, all I get is null.

So what the heck is going on? Why is it not throwing the Local Network Access permission prompt when a local address is entered? Is the problem that I’m not using TLS on the chat server on the desktop, but the HTML5 client is, so wants wss instead of ws? If that’s the case, how do I get a dummy TLS certificate for the server?

For testing purposes I’d also really like a way to be able to host on a machine without TLS but access the hosted page from another device on my LAN, but when I do that I get the SecureContext fail. I’ve tried removing the SecureContext check, but it throws a weird audio device error when I do that.

Websockets will be promoted automatically to secure web sockets if on an secure page. HTTPS will always use WSS, so you need a certificate for who ever is hosting if you intend to have clients join from itch.io. I am not sure if you need a signed certificate, Godot can create web sockets with TLSOptions.client_unsafe(), but this has a note that web platforms will still use their own certificate authority store, so maybe not.

Probably not a good idea to distribute a signed cert with the desktop app game server… I’ll have to do a test with an unsigned one.

I did figure out that my problem with it not working with local hosting is a Firefox issue. Chromium browsers are able to connect to the game server when the HTML5 client is hosted on the local network, even when hosted as HTTPS. Still didn’t work with Chromium when hosted on itch, and I’m still not even getting the Local Network Access Permission prompt in both cases, which is bothering me.