Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Live updates: a page on this computer's own address keeps the event stream, since the server takes the socket only from a signed-in browser

milind-soniac8d1760cba2
diff --git a/src/lib/websocket-events.ts b/src/lib/websocket-events.ts
index 7204813477..bd7bb505d6 100644
--- a/src/lib/websocket-events.ts
+++ b/src/lib/websocket-events.ts
@@ -1,7 +1,11 @@
import { relayLink, type LiveEventSourceLike } from "./relay-server";
+/** The server takes the event socket only from a cookie-signed-in browser; a page on this computer's own address is not one, so it keeps the event stream. */
+const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
+
export function isDirectWebBrowser(): boolean {
- return typeof window !== "undefined" && typeof WebSocket === "function" && !window.ogb?.platform && !relayLink();
+ return typeof window !== "undefined" && typeof WebSocket === "function" && !window.ogb?.platform && !relayLink()
+ && !LOOPBACK_HOSTS.has(window.location?.hostname ?? "");
}
export function websocketEvents(url: string): LiveEventSourceLike {