@omercnet/paseo-shared-browser 4.1.11-next.492.1 → 4.1.11-next.501.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -5
- package/STREAMING_DESIGN.md +4 -1
- package/client/browser-input-queue.test.ts +104 -1
- package/client/browser-input-queue.ts +56 -1
- package/client/browser-resolution-picker.tsx +44 -0
- package/client/browser-viewer-recovery.test.ts +69 -0
- package/client/browser-viewer-recovery.ts +41 -2
- package/client/browser.tsx +64 -6
- package/client/use-browser-canvas-input.ts +1 -0
- package/client/use-browser-video.test.ts +22 -0
- package/client/use-browser-video.ts +14 -1
- package/index.server.ts +9 -0
- package/npm-shrinkwrap.json +117 -4
- package/package.json +3 -2
- package/scripts/agent-browser-native.mjs +94 -0
- package/scripts/prepare-runtime.mjs +14 -17
- package/server/agent-browser-runtime.ts +1 -1
- package/server/browser-gesture.ts +10 -0
- package/server/browser-policy.ts +147 -26
- package/server/browser.ts +36 -0
- package/server/live-input-policy.test.ts +71 -0
- package/server/runtime-launch-environment.test.ts +1 -1
- package/server/runtime-owner.ts +10 -2
- package/server/runtime-video-opt-in.test.ts +1 -1
- package/server/stale-wheel-admission.test.ts +1 -0
- package/server/supervisor.ts +55 -1
- package/server/video-preference.test.ts +331 -0
- package/server/video-preference.ts +51 -0
- package/shared/browser.ts +31 -0
package/README.md
CHANGED
|
@@ -40,13 +40,15 @@ organization names.
|
|
|
40
40
|
controller when a takeover is needed, and continues the selected action after control is granted.
|
|
41
41
|
Closing a tab or browser still requires its own confirmation. Actions that need a fresh frame wait
|
|
42
42
|
for one before sending input.
|
|
43
|
-
- The plugin owns `agent-browser` version `0.
|
|
43
|
+
- The plugin owns `agent-browser` version `0.43.0`, its IPC directory, and the Chromium executable.
|
|
44
44
|
It strips inherited `AGENT_BROWSER_*` variables and sets `AGENT_BROWSER_SOCKET_DIR`,
|
|
45
45
|
`AGENT_BROWSER_IDLE_TIMEOUT_MS=0`, `AGENT_BROWSER_STREAM_PORT=0`, and
|
|
46
46
|
`AGENT_BROWSER_NO_AUTO_DIALOG=1` itself.
|
|
47
47
|
- By default every client receives JPEG frames from CDP `Page.startScreencast` or bounded
|
|
48
|
-
screenshots, and no capture extension is loaded into Chromium. When
|
|
49
|
-
|
|
48
|
+
screenshots, and no capture extension is loaded into Chromium. When **Encoded video** is turned
|
|
49
|
+
on in the resolution menu (host-wide, any viewer can change it, open browsers restart to apply
|
|
50
|
+
it) or the daemon is started with `PASEO_SHARED_BROWSER_VIDEO=1` (which forces it on),
|
|
51
|
+
desktop/web clients with usable WebCodecs receive encoded
|
|
50
52
|
workspace-tab video instead; other clients keep JPEG.
|
|
51
53
|
Remote input supports mouse hover, wheel scrolling, continuous dragging, native touch pan/pinch,
|
|
52
54
|
tap, double-tap, right-click, text, and special keys.
|
|
@@ -105,6 +107,14 @@ from `/usr/bin/chromium`. Install a non-Snap Chromium build with the system pack
|
|
|
105
107
|
adding the plugin. Set `PASEO_SHARED_BROWSER_CHROMIUM_EXECUTABLE` to an absolute path when Chromium
|
|
106
108
|
is installed elsewhere. The plugin does not emulate x64 Chromium on Linux.
|
|
107
109
|
|
|
110
|
+
agent-browser 0.43 and newer ships its native binary in a per-platform optional package
|
|
111
|
+
(`@agent-browser/cli-<os>-<arch>`), and runtime preparation stages the host's package into the
|
|
112
|
+
runtime. Install the plugin's dependencies with scripts disabled (`npm install --ignore-scripts` or
|
|
113
|
+
`npm ci --ignore-scripts`, which is what Paseo and `scripts/prepare-dependencies.mjs` do). When the
|
|
114
|
+
platform package is missing, agent-browser's `postinstall` downloads a binary from GitHub releases
|
|
115
|
+
without an integrity check; with scripts disabled, runtime preparation fails instead and names the
|
|
116
|
+
missing package.
|
|
117
|
+
|
|
108
118
|
Runtime preparation keeps no Chrome download cache. When it uses the upstream installer (every
|
|
109
119
|
platform except Linux ARM64, unless `PASEO_SHARED_BROWSER_CHROMIUM_EXECUTABLE` is set), the
|
|
110
120
|
installer runs with a private home inside the staging directory, so each preparation downloads the
|
|
@@ -198,11 +208,12 @@ User-supplied `AGENT_BROWSER_*` variables are deliberately ignored.
|
|
|
198
208
|
page instead. Fitting images stay centered without empty scroll ranges; a scrollbar on
|
|
199
209
|
one axis does not force one on the other. Returning to Fit resets local offsets without
|
|
200
210
|
reloading the page or image.
|
|
201
|
-
- With
|
|
211
|
+
- With **Encoded video** on (resolution menu toggle, or `PASEO_SHARED_BROWSER_VIDEO=1` in the
|
|
212
|
+
daemon environment), desktop and web clients
|
|
202
213
|
with WebCodecs play genuine encoded tab video (H264 when supported, otherwise VP8). The
|
|
203
214
|
bundled capture helper, which holds `tabCapture` and `debugger` permissions, is then
|
|
204
215
|
loaded into every workspace Chromium profile and captures the exact workspace tab, not a
|
|
205
|
-
screenshot loop or title-selected window.
|
|
216
|
+
screenshot loop or title-selected window. When encoded video is off the helper is never
|
|
206
217
|
materialized or loaded, and clients show a one-time disabled reply then use JPEG.
|
|
207
218
|
Android and other native apps use JPEG: the plugin SDK this package targets publishes no
|
|
208
219
|
encoded-video surface, so native video is deferred until the host ships one.
|
package/STREAMING_DESIGN.md
CHANGED
|
@@ -7,7 +7,10 @@ comparisons behind the input design.
|
|
|
7
7
|
|
|
8
8
|
## Transport and ownership
|
|
9
9
|
|
|
10
|
-
Encoded video is opt-in:
|
|
10
|
+
Encoded video is opt-in: a host-wide toggle in the resolution menu, persisted in
|
|
11
|
+
`plugin-data/shared-browser/video-preference.json`, or `PASEO_SHARED_BROWSER_VIDEO=1` in the
|
|
12
|
+
daemon environment (which forces it on). Each Chromium launch reads the effective value, and a
|
|
13
|
+
change relaunches open browsers. Without it
|
|
11
14
|
the capture helper is never loaded and `video.read` returns a typed `video-disabled` reply,
|
|
12
15
|
after which the client stops reading and uses JPEG. When enabled, desktop and web clients
|
|
13
16
|
use Chromium tab capture, a realtime WebCodecs encoder, and bounded encoded-packet reads
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
2
|
import type { BrowserGestureEvent, BrowserState } from "../shared/browser";
|
|
3
3
|
import { createBrowserCanvasInput } from "./browser-canvas-input";
|
|
4
4
|
import {
|
|
@@ -57,6 +57,7 @@ function fixture(
|
|
|
57
57
|
let control: BrowserGestureControl | null = authority;
|
|
58
58
|
const sent: Parameters<BrowserGestureTransport["update"]>[0][] = [];
|
|
59
59
|
const ended: Parameters<BrowserGestureTransport["end"]>[0][] = [];
|
|
60
|
+
const keptAlive: Parameters<BrowserGestureTransport["keepAlive"]>[0][] = [];
|
|
60
61
|
const errors: unknown[] = [];
|
|
61
62
|
const cursors: unknown[] = [];
|
|
62
63
|
const navigationCompleted: boolean[] = [];
|
|
@@ -80,6 +81,10 @@ function fixture(
|
|
|
80
81
|
ended.push(input);
|
|
81
82
|
return { state, cursor: null };
|
|
82
83
|
},
|
|
84
|
+
keepAlive: async (input) => {
|
|
85
|
+
keptAlive.push(input);
|
|
86
|
+
return { gestureId: input.gestureId, nextSequence: input.sequence };
|
|
87
|
+
},
|
|
83
88
|
};
|
|
84
89
|
const queue = createBrowserInputQueue({
|
|
85
90
|
transport,
|
|
@@ -102,6 +107,7 @@ function fixture(
|
|
|
102
107
|
queue,
|
|
103
108
|
sent,
|
|
104
109
|
ended,
|
|
110
|
+
keptAlive,
|
|
105
111
|
errors,
|
|
106
112
|
cursors,
|
|
107
113
|
beginGate,
|
|
@@ -713,6 +719,103 @@ describe("bounded browser input queue", () => {
|
|
|
713
719
|
expect(f.sent).toHaveLength(1);
|
|
714
720
|
expect(f.errors).toEqual([]);
|
|
715
721
|
});
|
|
722
|
+
|
|
723
|
+
describe("held-input keep-alive", () => {
|
|
724
|
+
const down = (x: number): BrowserGestureEvent => ({
|
|
725
|
+
kind: "down",
|
|
726
|
+
button: "left",
|
|
727
|
+
clickCount: 1,
|
|
728
|
+
point: point(x),
|
|
729
|
+
});
|
|
730
|
+
const up = (x: number): BrowserGestureEvent => ({
|
|
731
|
+
kind: "up",
|
|
732
|
+
button: "left",
|
|
733
|
+
clickCount: 1,
|
|
734
|
+
point: point(x),
|
|
735
|
+
});
|
|
736
|
+
const heldContext = {
|
|
737
|
+
viewerToken: authority.viewerToken,
|
|
738
|
+
controlToken: authority.controlToken,
|
|
739
|
+
expected: authority.expected,
|
|
740
|
+
};
|
|
741
|
+
afterEach(() => vi.useRealTimers());
|
|
742
|
+
|
|
743
|
+
it("renews a motionless held press below the server idle bound and stops on release", async () => {
|
|
744
|
+
vi.useFakeTimers();
|
|
745
|
+
const f = fixture();
|
|
746
|
+
f.queue.enqueue(down(10));
|
|
747
|
+
f.beginGate.resolve({ state, gestureId: "held", nextSequence: 1 });
|
|
748
|
+
await flush();
|
|
749
|
+
expect(f.sent.map(({ event }) => event.kind)).toEqual(["down"]);
|
|
750
|
+
// Holding still for longer than the server's five-second idle bound.
|
|
751
|
+
await vi.advanceTimersByTimeAsync(6_500);
|
|
752
|
+
expect(f.keptAlive).toEqual([
|
|
753
|
+
{ ...heldContext, gestureId: "held", sequence: 2 },
|
|
754
|
+
{ ...heldContext, gestureId: "held", sequence: 2 },
|
|
755
|
+
{ ...heldContext, gestureId: "held", sequence: 2 },
|
|
756
|
+
]);
|
|
757
|
+
// Keep-alive consumed no sequence: the release continues the same order.
|
|
758
|
+
f.queue.enqueue(up(40));
|
|
759
|
+
await flush();
|
|
760
|
+
expect(f.sent.map(({ event, sequence }) => [event.kind, sequence])).toEqual([
|
|
761
|
+
["down", 1],
|
|
762
|
+
["up", 2],
|
|
763
|
+
]);
|
|
764
|
+
f.queue.finish();
|
|
765
|
+
await flush();
|
|
766
|
+
await vi.advanceTimersByTimeAsync(10_000);
|
|
767
|
+
expect(f.keptAlive).toHaveLength(3);
|
|
768
|
+
expect(f.ended).toEqual([
|
|
769
|
+
expect.objectContaining({ gestureId: "held", sequence: 3, cancel: false }),
|
|
770
|
+
]);
|
|
771
|
+
expect(f.errors).toEqual([]);
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
it("never keeps an unpressed hover channel alive", async () => {
|
|
775
|
+
vi.useFakeTimers();
|
|
776
|
+
const f = fixture();
|
|
777
|
+
f.queue.enqueue(move(10));
|
|
778
|
+
f.beginGate.resolve({ state, gestureId: "hover", nextSequence: 1 });
|
|
779
|
+
await flush();
|
|
780
|
+
await vi.advanceTimersByTimeAsync(10_000);
|
|
781
|
+
expect(f.sent).toHaveLength(1);
|
|
782
|
+
expect(f.keptAlive).toEqual([]);
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
it("stops and cancels the held channel instead of renewing it after control is lost", async () => {
|
|
786
|
+
vi.useFakeTimers();
|
|
787
|
+
const f = fixture(undefined, true);
|
|
788
|
+
f.queue.enqueue(down(10));
|
|
789
|
+
f.beginGate.resolve({ state, gestureId: "held", nextSequence: 1 });
|
|
790
|
+
await flush();
|
|
791
|
+
f.changeControl({ ...authority, controlToken: "taken-over" });
|
|
792
|
+
await vi.advanceTimersByTimeAsync(2_000);
|
|
793
|
+
await flush();
|
|
794
|
+
expect(f.keptAlive).toEqual([]);
|
|
795
|
+
expect(f.ended).toEqual([
|
|
796
|
+
expect.objectContaining({ gestureId: "held", sequence: 2, cancel: true }),
|
|
797
|
+
]);
|
|
798
|
+
await vi.advanceTimersByTimeAsync(10_000);
|
|
799
|
+
expect(f.keptAlive).toEqual([]);
|
|
800
|
+
expect(f.ended).toHaveLength(1);
|
|
801
|
+
});
|
|
802
|
+
|
|
803
|
+
it("a rejected keep-alive fails closed without retrying", async () => {
|
|
804
|
+
vi.useFakeTimers();
|
|
805
|
+
const f = fixture();
|
|
806
|
+
let attempts = 0;
|
|
807
|
+
f.transport.keepAlive = async () => {
|
|
808
|
+
attempts += 1;
|
|
809
|
+
throw new Error("Browser gesture is unavailable");
|
|
810
|
+
};
|
|
811
|
+
f.queue.enqueue(down(10));
|
|
812
|
+
f.beginGate.resolve({ state, gestureId: "held", nextSequence: 1 });
|
|
813
|
+
await flush();
|
|
814
|
+
await vi.advanceTimersByTimeAsync(10_000);
|
|
815
|
+
expect(attempts).toBe(1);
|
|
816
|
+
expect(f.errors).toEqual([new Error("Browser gesture is unavailable")]);
|
|
817
|
+
});
|
|
818
|
+
});
|
|
716
819
|
});
|
|
717
820
|
|
|
718
821
|
it("keeps keyboard repeat/Unicode edges ordered and a held modifier alive across mouse release", async () => {
|
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
BrowserState,
|
|
15
15
|
beginBrowserGestureRpc,
|
|
16
16
|
endBrowserGestureRpc,
|
|
17
|
+
keepAliveBrowserGestureRpc,
|
|
17
18
|
updateBrowserGestureRpc,
|
|
18
19
|
} from "../shared/browser";
|
|
19
20
|
|
|
@@ -40,6 +41,9 @@ export interface BrowserGestureTransport {
|
|
|
40
41
|
state: BrowserState;
|
|
41
42
|
}
|
|
42
43
|
>;
|
|
44
|
+
keepAlive(
|
|
45
|
+
input: RpcInput<typeof keepAliveBrowserGestureRpc>,
|
|
46
|
+
): Promise<RpcOutput<typeof keepAliveBrowserGestureRpc>>;
|
|
43
47
|
}
|
|
44
48
|
interface QueueOptions {
|
|
45
49
|
transport: BrowserGestureTransport;
|
|
@@ -62,7 +66,7 @@ interface QueueOptions {
|
|
|
62
66
|
/** Resolves only after a different actionable decoded receipt commits, never visual-only pixels or a timer. */
|
|
63
67
|
waitForFrame?(afterFrameId: string, maxWaitMs?: number): Promise<void>;
|
|
64
68
|
}
|
|
65
|
-
type Command = { event: BrowserGestureEvent } | { end: true };
|
|
69
|
+
type Command = { event: BrowserGestureEvent } | { end: true } | { keepAlive: true };
|
|
66
70
|
interface Channel {
|
|
67
71
|
authority: BrowserGestureAuthority;
|
|
68
72
|
pointerKind: "mouse" | "touch";
|
|
@@ -76,6 +80,8 @@ interface Channel {
|
|
|
76
80
|
}
|
|
77
81
|
/** Retire empty client channels before the native service's five-second idle bound. */
|
|
78
82
|
export const BROWSER_INPUT_IDLE_MS = 4_000;
|
|
83
|
+
/** Renew a motionless held press well inside the server's five-second idle bound. */
|
|
84
|
+
export const BROWSER_INPUT_KEEPALIVE_MS = 2_000;
|
|
79
85
|
const MAX_QUEUED_COMMANDS = 64;
|
|
80
86
|
const MAX_WHEEL_DELTA = 4_000;
|
|
81
87
|
const MAX_FRAME_ADMISSION_ATTEMPTS = 3;
|
|
@@ -138,6 +144,12 @@ export function createBrowserInputQueue(options: QueueOptions) {
|
|
|
138
144
|
// Buffer real physical edges while begin is pending. This context grants no
|
|
139
145
|
// reusable admission and publishes nothing until the server acknowledges it.
|
|
140
146
|
let pendingAdmission: { authority: BrowserGestureAuthority; epoch: number } | null = null;
|
|
147
|
+
// Renews only a quiet held channel; real input already renews the server's idle bound.
|
|
148
|
+
let keepAliveTimer: ReturnType<typeof setInterval> | null = null;
|
|
149
|
+
const stopKeepAlive = () => {
|
|
150
|
+
clearInterval(keepAliveTimer ?? undefined);
|
|
151
|
+
keepAliveTimer = null;
|
|
152
|
+
};
|
|
141
153
|
|
|
142
154
|
const cancelChannel = async (old: Channel) => {
|
|
143
155
|
try {
|
|
@@ -159,6 +171,7 @@ export function createBrowserInputQueue(options: QueueOptions) {
|
|
|
159
171
|
pendingAdmission = null;
|
|
160
172
|
const old = channel;
|
|
161
173
|
channel = null;
|
|
174
|
+
stopKeepAlive();
|
|
162
175
|
options.onCursor(null);
|
|
163
176
|
if (old && !running) void cancelChannel(old);
|
|
164
177
|
};
|
|
@@ -176,6 +189,29 @@ export function createBrowserInputQueue(options: QueueOptions) {
|
|
|
176
189
|
return control && decoded && sameAuthority(decoded, control) ? decoded : null;
|
|
177
190
|
};
|
|
178
191
|
|
|
192
|
+
/** Keep a motionless held press alive; stop on release, cancellation or lost control. */
|
|
193
|
+
const syncKeepAlive = () => {
|
|
194
|
+
if (!channel || !hasHeldInput(channel)) {
|
|
195
|
+
stopKeepAlive();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
keepAliveTimer ??= setInterval(() => {
|
|
199
|
+
const held = channel;
|
|
200
|
+
if (!held || !hasHeldInput(held)) {
|
|
201
|
+
stopKeepAlive();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (!sameAuthority(held.authority, currentControl())) {
|
|
205
|
+
cancel();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
// Queued or in-flight input renews the server's idle bound on its own.
|
|
209
|
+
if (running || commands.length) return;
|
|
210
|
+
commands.push({ keepAlive: true });
|
|
211
|
+
void drain();
|
|
212
|
+
}, BROWSER_INPUT_KEEPALIVE_MS);
|
|
213
|
+
};
|
|
214
|
+
|
|
179
215
|
const drain = async () => {
|
|
180
216
|
if (running) return;
|
|
181
217
|
running = true;
|
|
@@ -198,6 +234,24 @@ export function createBrowserInputQueue(options: QueueOptions) {
|
|
|
198
234
|
channel = null;
|
|
199
235
|
options.onFinish();
|
|
200
236
|
}
|
|
237
|
+
if ("keepAlive" in command) {
|
|
238
|
+
if (!owned || !hasHeldInput(owned)) continue;
|
|
239
|
+
const held = owned;
|
|
240
|
+
if (!sameAuthority(held.authority, currentControl())) {
|
|
241
|
+
throw new Error("Browser input context changed. Release the gesture and try again.");
|
|
242
|
+
}
|
|
243
|
+
const startedAt = performance.now();
|
|
244
|
+
const result = await options.transport.keepAlive({
|
|
245
|
+
...transportContext(held.authority),
|
|
246
|
+
gestureId: held.gestureId,
|
|
247
|
+
sequence: held.sequence,
|
|
248
|
+
});
|
|
249
|
+
if (currentEpoch !== epoch) break;
|
|
250
|
+
if (result.gestureId !== held.gestureId || result.nextSequence !== held.sequence)
|
|
251
|
+
throw new Error("Browser gesture identity changed.");
|
|
252
|
+
held.idleNotAfter = startedAt + BROWSER_INPUT_IDLE_MS;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
201
255
|
if ("end" in command) {
|
|
202
256
|
if (!owned) continue;
|
|
203
257
|
// A pointer release must not release a still-held keyboard chord.
|
|
@@ -449,6 +503,7 @@ export function createBrowserInputQueue(options: QueueOptions) {
|
|
|
449
503
|
if (channel === owned) channel = null;
|
|
450
504
|
}
|
|
451
505
|
running = false;
|
|
506
|
+
syncKeepAlive();
|
|
452
507
|
if (commands.length) void drain();
|
|
453
508
|
}
|
|
454
509
|
};
|
|
@@ -32,6 +32,13 @@ export interface BrowserResolutionPickerProps {
|
|
|
32
32
|
onSelect(id: DevicePresetId): void;
|
|
33
33
|
onToggleFavorite(id: DevicePresetId): void;
|
|
34
34
|
onQualityChange(quality: BrowserDisplayPreferences["captureQuality"]): void;
|
|
35
|
+
/** Host-wide encoded video. Omitted while the host setting is unknown. */
|
|
36
|
+
encodedVideo?: {
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
forcedByHost: boolean;
|
|
39
|
+
disabled: boolean;
|
|
40
|
+
onChange(enabled: boolean): void;
|
|
41
|
+
};
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
const STYLES = StyleSheet.create({
|
|
@@ -105,6 +112,43 @@ export function BrowserResolutionPicker(props: BrowserResolutionPickerProps) {
|
|
|
105
112
|
{props.fillViewportDetail} · Follow the visible browser area while controlling
|
|
106
113
|
</Text>
|
|
107
114
|
</View>
|
|
115
|
+
{props.encodedVideo ? (
|
|
116
|
+
<View style={STYLES.group}>
|
|
117
|
+
<Pressable
|
|
118
|
+
accessibilityRole="switch"
|
|
119
|
+
accessibilityLabel="Encoded video"
|
|
120
|
+
accessibilityState={{
|
|
121
|
+
checked: props.encodedVideo.enabled,
|
|
122
|
+
disabled: props.encodedVideo.disabled || props.encodedVideo.forcedByHost,
|
|
123
|
+
}}
|
|
124
|
+
disabled={props.encodedVideo.disabled || props.encodedVideo.forcedByHost}
|
|
125
|
+
onPress={() => props.encodedVideo?.onChange(!props.encodedVideo.enabled)}
|
|
126
|
+
style={({ pressed }) => [
|
|
127
|
+
STYLES.quality,
|
|
128
|
+
baseStyle,
|
|
129
|
+
props.encodedVideo?.enabled ? selectedStyle : null,
|
|
130
|
+
{
|
|
131
|
+
opacity:
|
|
132
|
+
props.encodedVideo?.disabled || props.encodedVideo?.forcedByHost
|
|
133
|
+
? 0.45
|
|
134
|
+
: pressed
|
|
135
|
+
? 0.72
|
|
136
|
+
: 1,
|
|
137
|
+
},
|
|
138
|
+
]}
|
|
139
|
+
>
|
|
140
|
+
<Icon name="Video" size={18} color={colors.foregroundMuted} />
|
|
141
|
+
<Text style={[STYLES.title, { color: colors.foreground }]}>
|
|
142
|
+
Encoded video: {props.encodedVideo.enabled ? "On" : "Off"}
|
|
143
|
+
</Text>
|
|
144
|
+
</Pressable>
|
|
145
|
+
<Text style={[STYLES.detail, { color: colors.foregroundMuted }]}>
|
|
146
|
+
{props.encodedVideo.forcedByHost
|
|
147
|
+
? "Forced on by PASEO_SHARED_BROWSER_VIDEO=1 on the host"
|
|
148
|
+
: "Smoother streaming for every viewer on this host. Changing it restarts open browsers; logins are kept"}
|
|
149
|
+
</Text>
|
|
150
|
+
</View>
|
|
151
|
+
) : null}
|
|
108
152
|
{props.groups.map((group) => (
|
|
109
153
|
<View key={group.id} style={STYLES.group}>
|
|
110
154
|
<Text style={[STYLES.header, { color: colors.foregroundMuted }]}>{group.label}</Text>
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { QueryClient, QueryObserver } from "@tanstack/react-query";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import {
|
|
4
|
+
browserTabsRefetchInterval,
|
|
4
5
|
createBrowserViewerRecovery,
|
|
5
6
|
isBrowserClosedError,
|
|
6
7
|
isBrowserTabUnavailableError,
|
|
7
8
|
isExpiredBrowserViewerError,
|
|
9
|
+
selectViewerRecoveryFailure,
|
|
10
|
+
shouldRetryBrowserTabs,
|
|
8
11
|
} from "./browser-viewer-recovery";
|
|
9
12
|
|
|
10
13
|
const expired = Object.assign(
|
|
@@ -111,6 +114,72 @@ it("the actual capture query observer discards old token errors when its token k
|
|
|
111
114
|
}
|
|
112
115
|
});
|
|
113
116
|
|
|
117
|
+
describe("expired tab list poll", () => {
|
|
118
|
+
const transient = new Error("socket closed");
|
|
119
|
+
|
|
120
|
+
it("lets an expired tab poll claim the one-shot reattachment when capture and video are quiet", () => {
|
|
121
|
+
const claim = createBrowserViewerRecovery();
|
|
122
|
+
const observation = (viewerToken: string) => ({
|
|
123
|
+
identity: "host/workspace",
|
|
124
|
+
viewerToken,
|
|
125
|
+
pending: false,
|
|
126
|
+
...selectViewerRecoveryFailure({
|
|
127
|
+
viewerToken,
|
|
128
|
+
video: { error: null, viewerToken: null },
|
|
129
|
+
captureError: null,
|
|
130
|
+
tabsError: expired,
|
|
131
|
+
}),
|
|
132
|
+
});
|
|
133
|
+
expect(claim(observation("old-viewer"))).toBe(true);
|
|
134
|
+
// The same dead token never loops; the replacement token gets its own single attempt.
|
|
135
|
+
expect(claim(observation("old-viewer"))).toBe(false);
|
|
136
|
+
expect(claim(observation("new-viewer"))).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("keeps video and capture priority and ignores non-expiry tab failures", () => {
|
|
140
|
+
const videoError = new Error("Viewer token is invalid or expired");
|
|
141
|
+
expect(
|
|
142
|
+
selectViewerRecoveryFailure({
|
|
143
|
+
viewerToken: "viewer",
|
|
144
|
+
video: { error: videoError, viewerToken: "viewer" },
|
|
145
|
+
captureError: transient,
|
|
146
|
+
tabsError: expired,
|
|
147
|
+
}),
|
|
148
|
+
).toEqual({ failedViewerToken: "viewer", captureError: videoError });
|
|
149
|
+
expect(
|
|
150
|
+
selectViewerRecoveryFailure({
|
|
151
|
+
viewerToken: "viewer",
|
|
152
|
+
video: { error: videoError, viewerToken: "older" },
|
|
153
|
+
captureError: transient,
|
|
154
|
+
tabsError: transient,
|
|
155
|
+
}),
|
|
156
|
+
).toEqual({ failedViewerToken: "viewer", captureError: transient });
|
|
157
|
+
expect(
|
|
158
|
+
createBrowserViewerRecovery()({
|
|
159
|
+
identity: "scope",
|
|
160
|
+
viewerToken: "viewer",
|
|
161
|
+
pending: false,
|
|
162
|
+
...selectViewerRecoveryFailure({
|
|
163
|
+
viewerToken: "viewer",
|
|
164
|
+
video: { error: null, viewerToken: null },
|
|
165
|
+
captureError: null,
|
|
166
|
+
tabsError: transient,
|
|
167
|
+
}),
|
|
168
|
+
}),
|
|
169
|
+
).toBe(false);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// React Query skips intervals without a window, so the poll decision is checked directly.
|
|
173
|
+
it("stops polling and retrying an expired token but keeps polling through transient failures", () => {
|
|
174
|
+
expect(browserTabsRefetchInterval(expired)).toBe(false);
|
|
175
|
+
expect(shouldRetryBrowserTabs(0, expired)).toBe(false);
|
|
176
|
+
expect(shouldRetryBrowserTabs(0, transient)).toBe(true);
|
|
177
|
+
expect(shouldRetryBrowserTabs(3, transient)).toBe(false);
|
|
178
|
+
expect(browserTabsRefetchInterval(transient)).toBe(2_000);
|
|
179
|
+
expect(browserTabsRefetchInterval(null)).toBe(2_000);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
114
183
|
describe("remembered tab recovery", () => {
|
|
115
184
|
it("recognizes only the unavailable-tab rejection", () => {
|
|
116
185
|
const unavailable = Object.assign(
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Recover viewing after its short-lived viewer token expires during background
|
|
3
|
-
* suspension. Only a viewing capture
|
|
4
|
-
* never trigger action replay, control acquisition or
|
|
3
|
+
* suspension. Only a viewing read (capture, video or the tab list poll) can use this
|
|
4
|
+
* policy; mutation failure must never trigger action replay, control acquisition or
|
|
5
|
+
* lease takeover.
|
|
5
6
|
*/
|
|
6
7
|
const VIEWER_EXPIRED_MESSAGE = "Viewer token is invalid or expired";
|
|
7
8
|
const BROWSER_CLOSED_MESSAGE = "Browser is closed";
|
|
@@ -54,6 +55,44 @@ export interface BrowserViewerRecoveryObservation {
|
|
|
54
55
|
pending: boolean;
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
export interface BrowserViewingFailures {
|
|
59
|
+
viewerToken: string | null;
|
|
60
|
+
/** The video reader reports the exact token it failed with. */
|
|
61
|
+
video: { error: unknown; viewerToken: string | null };
|
|
62
|
+
/** Capture and tab list queries are keyed to the current viewer token. */
|
|
63
|
+
captureError: unknown;
|
|
64
|
+
tabsError: unknown;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Pick the viewing failure that may claim recovery. Video and capture keep their
|
|
69
|
+
* priority; an expired tab poll also qualifies, so a panel whose only live read is
|
|
70
|
+
* the tab list reattaches once instead of polling a dead token forever.
|
|
71
|
+
*/
|
|
72
|
+
export function selectViewerRecoveryFailure(
|
|
73
|
+
failures: BrowserViewingFailures,
|
|
74
|
+
): Pick<BrowserViewerRecoveryObservation, "failedViewerToken" | "captureError"> {
|
|
75
|
+
const { viewerToken, video, captureError, tabsError } = failures;
|
|
76
|
+
if (video.viewerToken === viewerToken && isExpiredBrowserViewerError(video.error))
|
|
77
|
+
return { failedViewerToken: video.viewerToken, captureError: video.error };
|
|
78
|
+
if (!isExpiredBrowserViewerError(captureError) && isExpiredBrowserViewerError(tabsError))
|
|
79
|
+
return { failedViewerToken: viewerToken, captureError: tabsError };
|
|
80
|
+
return { failedViewerToken: viewerToken, captureError };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const TABS_POLL_MS = 2_000;
|
|
84
|
+
/** React Query's default retry budget, kept for every failure except an expired viewer. */
|
|
85
|
+
const TABS_RETRY_LIMIT = 3;
|
|
86
|
+
|
|
87
|
+
/** An expired viewer token never becomes valid again; stop polling it and let recovery reattach. */
|
|
88
|
+
export function browserTabsRefetchInterval(error: unknown): number | false {
|
|
89
|
+
return isExpiredBrowserViewerError(error) ? false : TABS_POLL_MS;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function shouldRetryBrowserTabs(failureCount: number, error: unknown): boolean {
|
|
93
|
+
return !isExpiredBrowserViewerError(error) && failureCount < TABS_RETRY_LIMIT;
|
|
94
|
+
}
|
|
95
|
+
|
|
57
96
|
/**
|
|
58
97
|
* Claim at most one automatic viewing reattachment per expired token. Failure
|
|
59
98
|
* keeps manual Reconnect available. A new token or panel scope permits its own
|
package/client/browser.tsx
CHANGED
|
@@ -34,7 +34,9 @@ import {
|
|
|
34
34
|
detachBrowserRpc,
|
|
35
35
|
didBrowserRuntimeRestart,
|
|
36
36
|
endBrowserGestureRpc,
|
|
37
|
+
getBrowserVideoSettingsRpc,
|
|
37
38
|
isBrowserStateCurrent,
|
|
39
|
+
keepAliveBrowserGestureRpc,
|
|
38
40
|
listBrowserTabsRpc,
|
|
39
41
|
MAX_BROWSER_TABS,
|
|
40
42
|
MAX_VIEWPORT,
|
|
@@ -44,6 +46,7 @@ import {
|
|
|
44
46
|
reopenBrowserRpc,
|
|
45
47
|
resizeBrowserRpc,
|
|
46
48
|
sendBrowserInputRpc,
|
|
49
|
+
setBrowserVideoSettingsRpc,
|
|
47
50
|
setCaptureDensityRpc,
|
|
48
51
|
updateBrowserGestureRpc,
|
|
49
52
|
} from "../shared/browser";
|
|
@@ -88,9 +91,12 @@ import {
|
|
|
88
91
|
import { isFrameCurrent, isVideoSourceCurrent } from "./browser-video-currency";
|
|
89
92
|
import { BrowserVideoSurface } from "./browser-video-surface";
|
|
90
93
|
import {
|
|
94
|
+
browserTabsRefetchInterval,
|
|
91
95
|
isBrowserClosedError,
|
|
92
96
|
isBrowserTabUnavailableError,
|
|
93
97
|
isExpiredBrowserViewerError,
|
|
98
|
+
selectViewerRecoveryFailure,
|
|
99
|
+
shouldRetryBrowserTabs,
|
|
94
100
|
} from "./browser-viewer-recovery";
|
|
95
101
|
import { createFrameLifecycle } from "./frame-lifecycle";
|
|
96
102
|
import { useBrowserAutoCaptureDensity } from "./use-browser-auto-capture-density";
|
|
@@ -222,6 +228,9 @@ export function SharedBrowserPanel({
|
|
|
222
228
|
const beginBrowserGesture = useRpc(beginBrowserGestureRpc);
|
|
223
229
|
const updateBrowserGesture = useRpc(updateBrowserGestureRpc);
|
|
224
230
|
const endBrowserGesture = useRpc(endBrowserGestureRpc);
|
|
231
|
+
const keepAliveBrowserGesture = useRpc(keepAliveBrowserGestureRpc);
|
|
232
|
+
const getVideoSettings = useRpc(getBrowserVideoSettingsRpc);
|
|
233
|
+
const setVideoSettings = useRpc(setBrowserVideoSettingsRpc);
|
|
225
234
|
|
|
226
235
|
const mountedRef = useRef(false);
|
|
227
236
|
const activeViewerTokenRef = useRef<string | null>(null);
|
|
@@ -443,13 +452,43 @@ export function SharedBrowserPanel({
|
|
|
443
452
|
reconnecting || closedView || !attachedTabMatches
|
|
444
453
|
? null
|
|
445
454
|
: (attachQuery.data?.viewerToken ?? null);
|
|
446
|
-
|
|
455
|
+
// Keyed by viewer token, so an expired token's error never outlives the reattachment
|
|
456
|
+
// that replaced it. The previous list stays visible while the new token loads.
|
|
457
|
+
const tabsQueryKey = ["shared-browser", "tabs", host.id, workspaceId, viewerToken];
|
|
447
458
|
const tabsQuery = useQuery({
|
|
448
459
|
queryKey: tabsQueryKey,
|
|
449
460
|
queryFn: () => listTabs({ viewerToken: viewerToken! }),
|
|
450
461
|
enabled: Boolean(viewerToken),
|
|
451
|
-
|
|
462
|
+
placeholderData: (previous, previousQuery) =>
|
|
463
|
+
previousQuery?.queryKey[2] === host.id && previousQuery.queryKey[3] === workspaceId
|
|
464
|
+
? previous
|
|
465
|
+
: undefined,
|
|
466
|
+
refetchInterval: (query) => browserTabsRefetchInterval(query.state.error),
|
|
467
|
+
retry: shouldRetryBrowserTabs,
|
|
452
468
|
});
|
|
469
|
+
const tabsViewerExpired = isExpiredBrowserViewerError(tabsQuery.error);
|
|
470
|
+
const videoSettingsKey = ["shared-browser", "video-settings", host.id];
|
|
471
|
+
const videoSettingsQuery = useQuery({
|
|
472
|
+
queryKey: videoSettingsKey,
|
|
473
|
+
queryFn: () => getVideoSettings({}),
|
|
474
|
+
staleTime: 30_000,
|
|
475
|
+
});
|
|
476
|
+
const [videoSettingsPending, setVideoSettingsPending] = useState(false);
|
|
477
|
+
/** Any current viewer may flip this host-wide option; open browsers then relaunch. */
|
|
478
|
+
const changeEncodedVideo = async (enabled: boolean) => {
|
|
479
|
+
const token = activeViewerTokenRef.current;
|
|
480
|
+
if (!token || videoSettingsPending) return;
|
|
481
|
+
setVideoSettingsPending(true);
|
|
482
|
+
setOperationError(null);
|
|
483
|
+
try {
|
|
484
|
+
const next = await setVideoSettings({ viewerToken: token, enabled });
|
|
485
|
+
queryClient.setQueryData(videoSettingsKey, next);
|
|
486
|
+
} catch (error) {
|
|
487
|
+
setOperationError(errorMessage(error));
|
|
488
|
+
} finally {
|
|
489
|
+
setVideoSettingsPending(false);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
453
492
|
|
|
454
493
|
useEffect(() => {
|
|
455
494
|
const tabs = tabsQuery.data?.tabs;
|
|
@@ -538,6 +577,7 @@ export function SharedBrowserPanel({
|
|
|
538
577
|
|
|
539
578
|
const video = useBrowserVideo({
|
|
540
579
|
viewerToken,
|
|
580
|
+
...(videoSettingsQuery.data ? { hostVideoEnabled: videoSettingsQuery.data.enabled } : {}),
|
|
541
581
|
quality: "high",
|
|
542
582
|
bitrate: preferences.videoBitrate,
|
|
543
583
|
fps: preferences.videoFps,
|
|
@@ -978,7 +1018,12 @@ export function SharedBrowserPanel({
|
|
|
978
1018
|
return input && context ? { ...context, target: input.target } : null;
|
|
979
1019
|
},
|
|
980
1020
|
controlAuthority: gestureControlContext,
|
|
981
|
-
transport: {
|
|
1021
|
+
transport: {
|
|
1022
|
+
begin: beginBrowserGesture,
|
|
1023
|
+
update: updateBrowserGesture,
|
|
1024
|
+
end: endBrowserGesture,
|
|
1025
|
+
keepAlive: keepAliveBrowserGesture,
|
|
1026
|
+
},
|
|
982
1027
|
ownershipKey: JSON.stringify([
|
|
983
1028
|
viewerToken,
|
|
984
1029
|
controlToken,
|
|
@@ -1488,8 +1533,12 @@ export function SharedBrowserPanel({
|
|
|
1488
1533
|
useBrowserViewerRecovery({
|
|
1489
1534
|
identity: JSON.stringify([host.id, workspaceId]),
|
|
1490
1535
|
viewerToken,
|
|
1491
|
-
|
|
1492
|
-
|
|
1536
|
+
...selectViewerRecoveryFailure({
|
|
1537
|
+
viewerToken,
|
|
1538
|
+
video: { error: video.error, viewerToken: video.errorViewerToken },
|
|
1539
|
+
captureError: captureQuery.error,
|
|
1540
|
+
tabsError: tabsQuery.error,
|
|
1541
|
+
}),
|
|
1493
1542
|
pending: reconnecting || attachQuery.isFetching,
|
|
1494
1543
|
reconnect,
|
|
1495
1544
|
});
|
|
@@ -1507,7 +1556,7 @@ export function SharedBrowserPanel({
|
|
|
1507
1556
|
recoveryError ??
|
|
1508
1557
|
state?.error ??
|
|
1509
1558
|
(connectionError ? errorMessage(connectionError) : null) ??
|
|
1510
|
-
(tabsQuery.error ? errorMessage(tabsQuery.error) : null);
|
|
1559
|
+
(tabsQuery.error && !tabsViewerExpired ? errorMessage(tabsQuery.error) : null);
|
|
1511
1560
|
const statusColor =
|
|
1512
1561
|
state?.status === "ready"
|
|
1513
1562
|
? theme.colors.statusSuccess
|
|
@@ -1916,6 +1965,15 @@ export function SharedBrowserPanel({
|
|
|
1916
1965
|
)
|
|
1917
1966
|
}
|
|
1918
1967
|
favoritePresetIds={preferences.favoritePresetIds}
|
|
1968
|
+
{...(videoSettingsQuery.data
|
|
1969
|
+
? {
|
|
1970
|
+
encodedVideo: {
|
|
1971
|
+
...videoSettingsQuery.data,
|
|
1972
|
+
disabled: !viewerToken || videoSettingsPending,
|
|
1973
|
+
onChange: (enabled: boolean) => void changeEncodedVideo(enabled),
|
|
1974
|
+
},
|
|
1975
|
+
}
|
|
1976
|
+
: {})}
|
|
1919
1977
|
selectDisabled={!viewerToken || anyMutationPending}
|
|
1920
1978
|
favoriteDisabled={preferences.disabled}
|
|
1921
1979
|
density={state?.captureScale ?? 1}
|
|
@@ -100,6 +100,7 @@ export function useBrowserCanvasInput(options: CanvasOptions) {
|
|
|
100
100
|
begin: (input) => current.current.transport.begin(input),
|
|
101
101
|
update: (input) => current.current.transport.update(input),
|
|
102
102
|
end: (input) => current.current.transport.end(input),
|
|
103
|
+
keepAlive: (input) => current.current.transport.keepAlive(input),
|
|
103
104
|
},
|
|
104
105
|
authority: () => (alive.current ? current.current.authority() : null),
|
|
105
106
|
controlAuthority: () => {
|