Skip to content

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

fix(pair): name the desktop app after the app, not Chrome

Bugfixer 20137ffc382de
diff --git a/src/lib/session.test.ts b/src/lib/session.test.ts
index 21e1a98a5f..a730fbc1af 100644
--- a/src/lib/session.test.ts
+++ b/src/lib/session.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it, vi } from "vitest";
import {
- BROWSER_SIGN_IN_FAILED, cloudOwnerOf, isConnected, isOwnerOrAdmin, previewBrowserSignIn, profileForSession, readSessionState, reasonWorthShowing, SERVICE_TRUST_REASON, signInWithBrowserGrant,
+ BROWSER_SIGN_IN_FAILED, cloudOwnerOf, defaultDeviceLabel, isConnected, isOwnerOrAdmin, previewBrowserSignIn, profileForSession, readSessionState, reasonWorthShowing, SERVICE_TRUST_REASON, signInWithBrowserGrant,
takeBrowserSignInFromLocation, takeInvitedEmailFromLocation, takePairingCodeFromLocation,
type SessionState,
} from "./session";
@@ -182,3 +182,27 @@ describe("an SSH tunnel to a server that treats local requests as a service", ()
expect(reasonWorthShowing(SERVICE_TRUST_REASON)).toBe(SERVICE_TRUST_REASON);
});
});
+
+describe("the name a new device gets on the pair page", () => {
+ const WINDOWS_APP = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) MausBot/0.1.187 Chrome/148.0.7778.97 Electron/43.8.13 Safari/537.36";
+ const MAC_APP = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) MausBot/0.1.187 Chrome/148.0.7778.97 Electron/43.8.13 Safari/537.36";
+
+ it("names the desktop app after the app, not the Chrome inside it", () => {
+ expect(defaultDeviceLabel(WINDOWS_APP, true)).toBe("MausBot on Windows");
+ expect(defaultDeviceLabel(MAC_APP, true)).toBe("MausBot on Mac");
+ });
+
+ it("still names a browser after the browser", () => {
+ expect(defaultDeviceLabel("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36", false)).toBe("Chrome on Windows");
+ expect(defaultDeviceLabel("Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1", false)).toBe("Safari on iPhone");
+ });
+
+ it("knows it is in the desktop app from the app's own window bridge", () => {
+ vi.stubGlobal("window", { ogb: { workspaces: {} } });
+ try {
+ expect(defaultDeviceLabel(WINDOWS_APP)).toBe("MausBot on Windows");
+ } finally {
+ vi.unstubAllGlobals();
+ }
+ });
+});
diff --git a/src/lib/session.ts b/src/lib/session.ts
index 221533ae23..b55cacc107 100644
--- a/src/lib/session.ts
+++ b/src/lib/session.ts
@@ -1,3 +1,4 @@
+import { productName } from "./brand";
import { t } from "./i18n";
import { serverErrorText } from "./server-error";
import { forgetSharedSession } from "./session-reuse";
@@ -120,8 +121,9 @@ export function takeInvitedEmailFromLocation(): string | null {
return /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email) ? email : null;
}
-export function defaultDeviceLabel(userAgent: string = navigator.userAgent): string {
- const browser = /Edg\//.test(userAgent) ? "Edge" : /OPR\//.test(userAgent) ? "Opera" : /Chrome\//.test(userAgent) ? "Chrome" : /Firefox\//.test(userAgent) ? "Firefox" : /Safari\//.test(userAgent) ? "Safari" : "Browser";
+/** The desktop app's window is Chromium too, so its user agent alone would name it Chrome. */
+export function defaultDeviceLabel(userAgent: string = navigator.userAgent, desktopApp = typeof window !== "undefined" && Boolean(window.ogb?.workspaces)): string {
+ const browser = desktopApp ? productName() : /Edg\//.test(userAgent) ? "Edge" : /OPR\//.test(userAgent) ? "Opera" : /Chrome\//.test(userAgent) ? "Chrome" : /Firefox\//.test(userAgent) ? "Firefox" : /Safari\//.test(userAgent) ? "Safari" : "Browser";
const os = /iPhone/.test(userAgent) ? "iPhone" : /iPad/.test(userAgent) ? "iPad" : /Android/.test(userAgent) ? "Android" : /Mac OS X/.test(userAgent) ? "Mac" : /Windows/.test(userAgent) ? "Windows" : /Linux/.test(userAgent) ? "Linux" : "";
return os ? `${browser} on ${os}` : browser;
}