Skip to content

Commit 8afc4e5

Browse files
committed
bugfix(web): Do not open the LAN relay socket from an https page
emscripten_websocket_new passes its URL straight to the WebSocket constructor, and a browser does not merely refuse a ws:// socket opened from an https:// page - it throws a SecurityError out of the constructor. That unwound through main() and killed the engine before it drew a frame, so the hosted page stopped working altogether the moment the relay was connected at startup. The same throw was waiting in UDP::Bind for anyone opening the LAN screen there. Decide the URL in JS and let it answer "no relay": plain ws:// only for a page that is not https, ?relay=<url> to name a reachable (wss://) one, and an empty answer means skip the socket entirely. relay.py speaks plain ws and is a local dev tool, so a hosted page has nothing to reach by default - LAN is unavailable there, which is not fatal, unlike the crash. Verified the three cases (http, https, https with ?relay=) against the extracted EM_ASM body.
1 parent 1860f61 commit 8afc4e5

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

  • Core/GameEngine/Source/GameNetwork

Core/GameEngine/Source/GameNetwork/udp.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,26 @@ namespace
8484
return;
8585
char url[256];
8686
EM_ASM({
87-
var h = (typeof location !== 'undefined' && location.hostname) ? location.hostname : 'localhost';
88-
stringToUTF8('ws://' + h + ':8090', $0, 256);
87+
var loc = (typeof location !== 'undefined') ? location : null;
88+
var host = (loc && loc.hostname) ? loc.hostname : 'localhost';
89+
var params = new URLSearchParams(loc ? loc.search : '');
90+
var override = params.get('relay');
91+
// A page served over https may not open a ws:// socket at all, and the browser
92+
// refuses by throwing, so report no relay rather than a URL that cannot be
93+
// used. ?relay=wss://host:port names a reachable one.
94+
var relayUrl = override ? override
95+
: ((loc && loc.protocol === 'https:') ? '' : 'ws://' + host + ':8090');
96+
stringToUTF8(relayUrl, $0, 256);
8997
}, url);
98+
// TheSuperHackers @bugfix githubawn 30/07/2026 No relay to reach: skip the socket
99+
// entirely. emscripten_websocket_new hands the URL straight to the WebSocket
100+
// constructor, and a ws:// URL on an https:// page makes that constructor THROW a
101+
// SecurityError, which unwinds out through main() and takes the engine down before
102+
// it can draw. LAN is simply unavailable in that case, which is not fatal.
103+
if (url[0] == '\0')
104+
{
105+
return;
106+
}
90107
EmscriptenWebSocketCreateAttributes attr;
91108
emscripten_websocket_init_create_attributes(&attr);
92109
attr.url = url;

0 commit comments

Comments
 (0)