Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(desktop): let the published-site preview load in the desktop app
AdityaUmale89c8a22a4454
diff --git a/electron/app-frame-guard.mjs b/electron/app-frame-guard.mjsindex c9c714eeea..a60c91853a 100644--- a/electron/app-frame-guard.mjs+++ b/electron/app-frame-guard.mjs@@ -5,11 +5,15 @@//// Electron 43.7.9: a frame's self-navigation fires will-frame-navigate with frame.origin === "null" and an// empty frame.url, and preventDefault() stops it before any request leaves.+//+// A frame that has not loaded anything yet reads "null" as well, so the published-site preview beside the chat+// (a frame with a real origin once loaded) is let through when the page that holds it gives it its address:+// the initiator is the frame's parent and the parent's origin is not opaque.const OWN_DOCUMENTS = new Set(["about:srcdoc", "about:blank"]);/**- * @param {{ isMainFrame?: boolean, url?: string, frame?: { origin?: string } | null } | null | undefined} details+ * @param {{ isMainFrame?: boolean, url?: string, frame?: { origin?: string, parent?: { frameTreeNodeId?: number } | null } | null, initiator?: { frameTreeNodeId?: number, origin?: string } | null } | null | undefined} details* @returns {boolean} false when the navigation must be cancelled*/export function appFrameNavigationAllowed(details) {@@ -25,5 +29,17 @@ export function appFrameNavigationAllowed(details) {// frame that navigates again right after a cancelled navigation. A frame nobody can read is not let through.return false;}- return origin !== "null";+ return origin !== "null" || givenByOpenParent(details);+}++/** @param {{ frame?: { parent?: { frameTreeNodeId?: number } | null } | null, initiator?: { frameTreeNodeId?: number, origin?: string } | null }} details */+function givenByOpenParent(details) {+ try {+ const parent = details.frame?.parent;+ const initiator = details.initiator;+ if (!parent || !initiator || typeof parent.frameTreeNodeId !== "number") return false;+ return initiator.frameTreeNodeId === parent.frameTreeNodeId && typeof initiator.origin === "string" && initiator.origin !== "null";+ } catch {+ return false;+ }}diff --git a/electron/app-frame-guard.node-test.mjs b/electron/app-frame-guard.node-test.mjsindex a2bfcd4272..f65269817e 100644--- a/electron/app-frame-guard.node-test.mjs+++ b/electron/app-frame-guard.node-test.mjs@@ -43,3 +43,26 @@ test("leaves main frames and frames with a real origin alone", () => {assert.equal(appFrameNavigationAllowed(null), true);assert.equal(appFrameNavigationAllowed(undefined), true);});++// A frame that has not loaded anything yet reads "null" too. Electron 43.7.9 reports the parent as the initiator when+// the page that holds the frame gives it its address, and the frame (or a sandboxed parent) when an app moves itself.+const appPage = { frameTreeNodeId: 1, origin: "http://127.0.0.1:5199" };+const newFrame = (url, initiator, parent = appPage) => ({ isMainFrame: false, url, frame: { origin: "null", url: "", parent }, initiator });++test("a new frame may load the address the app page gives it (a published site beside the chat)", () => {+ assert.equal(appFrameNavigationAllowed(newFrame("https://abc.mausbot.page/", { frameTreeNodeId: 1, origin: "http://127.0.0.1:5199" })), true);+});++test("an app frame still may not go anywhere by itself or through a frame of its own", () => {+ const app = { frameTreeNodeId: 2, origin: "null" };+ // Meta refresh: the app frame starts its own navigation.+ assert.equal(appFrameNavigationAllowed(newFrame("http://127.0.0.1:9/meta", app)), false);+ // An iframe inside the app: its parent is the app frame, whose origin is opaque.+ assert.equal(appFrameNavigationAllowed(newFrame("http://127.0.0.1:9/inner", app, app)), false);+ // No initiator, or one from elsewhere, is not the app page.+ assert.equal(appFrameNavigationAllowed(newFrame("http://127.0.0.1:9/x", undefined)), false);+ assert.equal(appFrameNavigationAllowed(newFrame("http://127.0.0.1:9/x", { frameTreeNodeId: 3, origin: "https://example.com" })), false);+ assert.equal(appFrameNavigationAllowed(newFrame("http://127.0.0.1:9/x", { origin: "http://127.0.0.1:5199" }, { origin: "http://127.0.0.1:5199" })), false);+ const gone = { get frameTreeNodeId() { throw new Error("Render frame was disposed before WebFrameMain could be accessed"); }, origin: "http://127.0.0.1:5199" };+ assert.equal(appFrameNavigationAllowed(newFrame("http://127.0.0.1:9/x", gone)), false);+});