Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(browser): opt browser panel out of window drag and handle restore clicks (#3995) (#3996)
Praveen Bishnoiab59ba866e0b
diff --git a/src/components/BrowserPanel.dom.test.ts b/src/components/BrowserPanel.dom.test.tsindex 98ec875b60..d33e3e1b00 100644--- a/src/components/BrowserPanel.dom.test.ts+++ b/src/components/BrowserPanel.dom.test.ts@@ -86,4 +86,46 @@ describe("the browser panel's Maximize", () => {expect(skyward()).toBe(false);expect(dialogCloses).toHaveBeenCalledTimes(1);});++ it("restores the panel when clicking Restore size", async () => {+ click(maximizeButton());+ expect(skyward()).toBe(true);+ expect(maximizeButton()?.getAttribute("aria-label")).toBe("Restore size");++ click(maximizeButton());+ await settle();+ expect(skyward()).toBe(false);+ expect(maximizeButton()?.getAttribute("aria-label")).toBe("Maximize");+ });++ it("opts out of window dragging so toolbar clicks reach buttons instead of moving the window", () => {+ expect(panel().matches("[data-browser-transport]")).toBe(true);+ });+});++describe("the browser panel's Full screen", () => {+ it("toggles full screen and exits cleanly", async () => {+ const fullscreenButton = () => host.querySelector<HTMLButtonElement>('[aria-label="Full screen"], [aria-label="Exit full screen"]');+ expect(fullscreenButton()?.getAttribute("aria-label")).toBe("Full screen");++ const p = panel();+ p.requestFullscreen = vi.fn().mockImplementation(() => {+ Object.defineProperty(document, "fullscreenElement", { value: p, configurable: true, writable: true });+ document.dispatchEvent(new Event("fullscreenchange"));+ return Promise.resolve();+ });+ document.exitFullscreen = vi.fn().mockImplementation(() => {+ Object.defineProperty(document, "fullscreenElement", { value: null, configurable: true, writable: true });+ document.dispatchEvent(new Event("fullscreenchange"));+ return Promise.resolve();+ });++ click(fullscreenButton());+ await settle();+ expect(fullscreenButton()?.getAttribute("aria-label")).toBe("Exit full screen");++ click(fullscreenButton());+ await settle();+ expect(fullscreenButton()?.getAttribute("aria-label")).toBe("Full screen");+ });});diff --git a/src/components/BrowserPanel.tsx b/src/components/BrowserPanel.tsxindex e5f674af70..969c72bf95 100644--- a/src/components/BrowserPanel.tsx+++ b/src/components/BrowserPanel.tsx@@ -222,9 +222,18 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS}, []);const toggleFullscreen = () => {const leaving = Boolean(panel.current) && document.fullscreenElement === panel.current;+ if (leaving && maximized) {+ setMaximized(false);+ }const request = leaving ? document.exitFullscreen() : panel.current?.requestFullscreen();void request?.catch(() => setError(leaving ? "Could not leave full screen. Press Esc instead." : "Full screen is unavailable in this browser."));};+ const toggleMaximize = () => {+ if (fullscreen && document.fullscreenElement === panel.current) {+ void document.exitFullscreen().catch(() => {});+ }+ setMaximized((value) => !value);+ };// The maximized panel swallows its Escape (defaultPrevented) so the same press cannot close a dialog beneath.// Capture: listeners registered before this panel must see the key already refused.useEffect(() => {@@ -232,11 +241,14 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserSconst onKey = (event: KeyboardEvent) => {if (event.key !== "Escape" || event.defaultPrevented) return;event.preventDefault();+ if (fullscreen && document.fullscreenElement === panel.current) {+ void document.exitFullscreen().catch(() => {});+ }setMaximized(false);};window.addEventListener("keydown", onKey, true);return () => window.removeEventListener("keydown", onKey, true);- }, [maximized]);+ }, [maximized, fullscreen]);const restart = () => {if (!window.confirm(t("browser.panel.confirmRestart"))) return;@@ -291,7 +303,7 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserSonTake={takeControl}onHandBack={handBack}onFullscreen={toggleFullscreen}- onMaximize={() => setMaximized((value) => !value)}+ onMaximize={toggleMaximize}onProfiles={() => { browserControl.current?.handBack(); setShowProfiles(true); }}menu={<MoreMenustream={stream}diff --git a/src/components/window-drag-regions.test.ts b/src/components/window-drag-regions.test.tsindex d4949b2186..4e1230f0c7 100644--- a/src/components/window-drag-regions.test.ts+++ b/src/components/window-drag-regions.test.ts@@ -84,9 +84,9 @@ describe("caption chrome", () => {it("opts controls, menus and dialogs out of a drag region in styles.css", () => {const document = new Window().document;- document.body.innerHTML = `<div data-window-drag><button></button><input><a href="#"></a><span role="button"></span><span></span><div class="field"><select></select><svg></svg></div></div><div role="menu"></div><div class="fixed backdrop"><div role="dialog"></div></div><div class="fixed overlay"><p></p></div>`;- const matches = [...document.querySelectorAll("button, input, a, span, .field, [role], .backdrop, .overlay")].map((element) => element.matches(noDragSelector));- expect(matches).toEqual([true, true, true, true, false, true, true, true, true, false]);+ document.body.innerHTML = `<div data-window-drag><button></button><input><a href="#"></a><span role="button"></span><span></span><div class="field"><select></select><svg></svg></div></div><div role="menu"></div><div class="fixed backdrop"><div role="dialog"></div></div><div class="fixed overlay"><p></p></div><div data-browser-transport="stream"></div>`;+ const matches = [...document.querySelectorAll("button, input, a, span, .field, [role], .backdrop, .overlay, [data-browser-transport]")].map((element) => element.matches(noDragSelector));+ expect(matches).toEqual([true, true, true, true, false, true, true, true, true, false, true]);});});diff --git a/src/styles.css b/src/styles.cssindex 4846f5f01d..de83531d39 100644--- a/src/styles.css+++ b/src/styles.css@@ -2958,7 +2958,8 @@ button:disabled.bg-danger {[data-window-drag] :has(> :is(select, input)),[data-window-drag] :is(button, a[href], input, select, textarea, label, summary, [role="button"], [role="link"], [role="tab"], [role="switch"], [role="checkbox"], [role="radio"], [role="combobox"], [role="slider"], [role="separator"], [contenteditable]:not([contenteditable="false"]), [tabindex]:not([tabindex="-1"])),:is([role="menu"], [role="listbox"], [role="dialog"], [role="alertdialog"], [role="tooltip"]),-.fixed:has(> :is([role="dialog"], [role="alertdialog"], [aria-modal="true"])) {+.fixed:has(> :is([role="dialog"], [role="alertdialog"], [aria-modal="true"])),+[data-browser-transport] {-webkit-app-region: no-drag;}