Skip to content

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

fix(browser): a page seen before sleep never counts as the woken browser's page

AdityaUmale7e1f34ade384
diff --git a/src/components/BrowserPanel.test.ts b/src/components/BrowserPanel.test.ts
index 3a0e27d834..24e91b612f 100644
--- a/src/components/BrowserPanel.test.ts
+++ b/src/components/BrowserPanel.test.ts
@@ -416,6 +416,24 @@ describe("what the person does in the panel", () => {
await flush();
expect(socket.sent.at(-1)).toEqual({ type: "navigate", url: "https://accounts.example.com/login" });
});
+ it("opens the sign-in page on the woken browser's blank tab, not the page it had before sleeping", async () => {
+ await render({ signIn: { url: "https://accounts.example.com/login", site: "example.com", nonce: 1 } });
+ const socket = FakeSocket.instances.at(-1)!;
+ await act(async () => {
+ socket.open();
+ socket.message({ type: "tabs", tabs: [{ tabId: "t1", title: "Docs", url: "https://docs.example.com/", active: true }] });
+ socket.control("unclaimed");
+ socket.message({ type: "asleep" });
+ });
+ await flush();
+ expect(socket.sent).toEqual([{ type: "wake" }]);
+ await act(async () => socket.message({ type: "awake" }));
+ await flush();
+ await act(async () => socket.message({ type: "tabs", tabs: [{ tabId: "t2", title: "", url: "about:blank", active: true }] }));
+ await act(async () => socket.control("you"));
+ await flush();
+ expect(socket.sent.at(-1)).toEqual({ type: "navigate", url: "https://accounts.example.com/login" });
+ });
});
describe("a published page's Open", () => {
diff --git a/src/components/BrowserPanel.tsx b/src/components/BrowserPanel.tsx
index 28861cdf34..ac4e6c69fc 100644
--- a/src/components/BrowserPanel.tsx
+++ b/src/components/BrowserPanel.tsx
@@ -187,6 +187,7 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS
} else if (message.type === "starting") {
setStarting(true);
} else if (message.type === "asleep" || message.type === "awake") {
+ if (message.type === "asleep") pageNow.current = null;
setAsleep(message.type === "asleep" ? "asleep" : "");
}
}, []);