Skip to content

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

Tell a reloaded app frame Point is on before resending outlines

AdityaUmaleb6f90acc199f
diff --git a/src/components/app/PageTools.test.ts b/src/components/app/PageTools.test.ts
index b6dde1cc22..4b02a980ca 100644
--- a/src/components/app/PageTools.test.ts
+++ b/src/components/app/PageTools.test.ts
@@ -149,7 +149,7 @@ describe("a bot's page in the chat", () => {
expect(posted).toHaveBeenCalledWith({ jsonrpc: "2.0", method: "mausbot/point", params: { on: false } }, "*");
});
- it("sends the numbered outlines again to the frame a reload puts in place", async () => {
+ it("sends Point and the numbered outlines again to the frame a reload puts in place", async () => {
await render(row(payload()));
await click("Point", card());
await fromFrame(PICK, inlineFrame().contentWindow);
@@ -158,7 +158,11 @@ describe("a bot's page in the chat", () => {
expect(inlineFrame()).not.toBe(before);
const posted = vi.spyOn(inlineFrame().contentWindow!, "postMessage").mockImplementation(() => {});
await act(async () => { inlineFrame().dispatchEvent(new Event("load")); });
- expect(posted).toHaveBeenCalledWith(marksMessage(["main > section:nth-of-type(2) > button"]), "*");
+ // The new page starts with Point off, so it is told Point is still on before it gets the outlines.
+ expect(posted.mock.calls.map(([message]) => message)).toEqual([
+ { jsonrpc: "2.0", method: "mausbot/point", params: { on: true } },
+ marksMessage(["main > section:nth-of-type(2) > button"]),
+ ]);
});
it("shares the version on screen; the card the server patches shows the link with Copy, opens it, and unpublishes it", async () => {
diff --git a/src/components/app/PageTools.tsx b/src/components/app/PageTools.tsx
index c07d82d9bc..3279acadac 100644
--- a/src/components/app/PageTools.tsx
+++ b/src/components/app/PageTools.tsx
@@ -173,10 +173,15 @@ export function usePagePoint(args: { frame(): HTMLIFrameElement | null | undefin
const iframe = latest.current.frame();
const send = () => iframe?.contentWindow?.postMessage(marksMessage(JSON.parse(marks) as string[]), "*");
send();
- // A new frame (full screen, a reload) gets them again once its page has loaded; `frameKey` changes with each frame.
- iframe?.addEventListener("load", send);
- return () => iframe?.removeEventListener("load", send);
- }, [marks, pointing, args.view, args.frameKey]);
+ // A new frame (full screen, a reload) starts with Point off: once its page has loaded it gets the Point state, then
+ // the outlines again; `frameKey` changes with each frame.
+ const loaded = () => {
+ say(on.current);
+ send();
+ };
+ iframe?.addEventListener("load", loaded);
+ return () => iframe?.removeEventListener("load", loaded);
+ }, [marks, pointing, args.view, args.frameKey, say]);
return { pointing, toggle: () => set(!on.current), stop: () => { if (on.current) set(false); } };
}