Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

docs(web): state the back-to-tab trade-off in picture-in-picture

muterCb3744a63df10
diff --git a/apps/web/src/features/rooms/chat/voice-mode/voice-pip.test.ts b/apps/web/src/features/rooms/chat/voice-mode/voice-pip.test.ts
index 81cc9057..9012b82a 100644
--- a/apps/web/src/features/rooms/chat/voice-mode/voice-pip.test.ts
+++ b/apps/web/src/features/rooms/chat/voice-mode/voice-pip.test.ts
@@ -6,6 +6,7 @@ import {
onVoicePipClosedByHuman,
openVoicePip,
resetVoicePipForTest,
+ returnedToOpener,
} from "./voice-pip";
/** A stand-in for the browser's picture-in-picture window. */
@@ -87,6 +88,25 @@ describe("Voice Mode picture-in-picture window", () => {
stop();
});
+ it("reads back to tab only from the page coming to the front", async () => {
+ installFakeVoicePip();
+ await openVoicePip("voice-mode");
+ const focused = vi.spyOn(document, "hasFocus").mockReturnValue(true);
+ try {
+ // Back to tab from a background tab brings the page to the front.
+ const returned = returnedToOpener(20);
+ document.dispatchEvent(new Event("visibilitychange"));
+ await expect(returned).resolves.toBe(true);
+ resetVoicePipForTest();
+ // The documented trade-off: a page that stayed visible, focused
+ // afterwards or not, reads as a close, so the close button always ends
+ // the call even where back to tab on an unfocused visible window does too.
+ await expect(returnedToOpener(20)).resolves.toBe(false);
+ } finally {
+ focused.mockRestore();
+ }
+ });
+
it("gives the window to one owner at a time", async () => {
const fake = installFakeVoicePip();
const voiceModeClosed = vi.fn();
diff --git a/apps/web/src/features/rooms/chat/voice-mode/voice-pip.ts b/apps/web/src/features/rooms/chat/voice-mode/voice-pip.ts
index 6b524e84..adfb4964 100644
--- a/apps/web/src/features/rooms/chat/voice-mode/voice-pip.ts
+++ b/apps/web/src/features/rooms/chat/voice-mode/voice-pip.ts
@@ -91,6 +91,13 @@ export function closeVoicePip(owner: VoicePipOwner) {
* neither, so this checks a moment later whether the page came to the front
* around the close. A close while this page was already in front is a close,
* even though focus lands on the page afterwards.
+ *
+ * Trade-off: back to tab on a page that stayed visible but unfocused (its
+ * window on another screen, or only partly covered, while the Human works in
+ * another app) brings no visibility change and also reads as a close, so the
+ * call ends. Telling it apart by focus instead made the close button keep the
+ * call whenever the page was in front; a close that ends the call is the
+ * surer of the two, and starting Voice Mode again floats a new window.
*/
export function returnedToOpener(waitMs = 300): Promise<boolean> {
const closedAt = performance.now();