@omercnet/paseo-shared-browser 4.1.11 → 4.1.12-next.505.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 +36 -5
- package/STREAMING_DESIGN.md +4 -1
- package/client/agent-access-settings.tsx +143 -0
- 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.client.tsx +8 -0
- package/index.server.ts +80 -11
- package/npm-shrinkwrap.json +119 -6
- package/package.json +5 -4
- 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/server/workspace-list.ts +42 -0
- package/shared/agent-access.ts +165 -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
|
|
@@ -147,6 +157,26 @@ The provider launches the stdio adapter on the Paseo daemon host, beside the dae
|
|
|
147
157
|
runtime. Web, desktop, and mobile clients never own or host the adapter or Chromium, and a client
|
|
148
158
|
disconnect does not close or reset either process.
|
|
149
159
|
|
|
160
|
+
### Choosing which agents get the tool
|
|
161
|
+
|
|
162
|
+
By default every new agent gets the adapter. Settings, under Shared Browser, can restrict that:
|
|
163
|
+
|
|
164
|
+
- **Every new agent** (the default) injects the adapter into every new agent, as above.
|
|
165
|
+
- **Only the agents listed** injects it only into a new agent whose provider id is listed, or whose
|
|
166
|
+
workspace id or project id is listed. Separate entries with commas or new lines. An empty
|
|
167
|
+
configuration means no agent.
|
|
168
|
+
|
|
169
|
+
`agent.create` carries the provider and the working directory but no labels and no workspace id, so a
|
|
170
|
+
workspace or project is matched by directory: the workspace whose directory is the agent's directory or
|
|
171
|
+
the deepest one containing it. Both directories are normalized first (separators, `.` and `..` segments),
|
|
172
|
+
so a path that climbs out of a workspace does not match it. The lookup includes background workspaces. If
|
|
173
|
+
the list is longer than 20 pages of 200, or the lookup fails, those lists match nothing. Workspaces that
|
|
174
|
+
share a directory cannot be told apart, so listing any of them matches them all. Matching is lexical: nothing on disk is consulted, so symlinks are not resolved and letter case is not folded. The settings read has a 2 second deadline, and a read that is too slow is treated like an unreadable setting, so every new agent gets the tool. The workspace lookup has its own 2 second deadline, and a timeout there counts as no match. Either timeout logs one line, and a slow lookup never holds up agent creation. The check runs before the adapter, its credential or the supervisor are set up, so
|
|
175
|
+
an agent that is not allowed costs nothing. It applies to agents created after the setting is saved. A
|
|
176
|
+
setting that cannot be read or is invalid falls back to every new agent, and the plugin log gets one line
|
|
177
|
+
saying so. The settings screen reports an entry over 256 characters or a list over 200 entries instead of
|
|
178
|
+
cutting it off.
|
|
179
|
+
|
|
150
180
|
## Runtime environment overrides
|
|
151
181
|
|
|
152
182
|
The plugin recognizes only these deployment overrides:
|
|
@@ -198,11 +228,12 @@ User-supplied `AGENT_BROWSER_*` variables are deliberately ignored.
|
|
|
198
228
|
page instead. Fitting images stay centered without empty scroll ranges; a scrollbar on
|
|
199
229
|
one axis does not force one on the other. Returning to Fit resets local offsets without
|
|
200
230
|
reloading the page or image.
|
|
201
|
-
- With
|
|
231
|
+
- With **Encoded video** on (resolution menu toggle, or `PASEO_SHARED_BROWSER_VIDEO=1` in the
|
|
232
|
+
daemon environment), desktop and web clients
|
|
202
233
|
with WebCodecs play genuine encoded tab video (H264 when supported, otherwise VP8). The
|
|
203
234
|
bundled capture helper, which holds `tabCapture` and `debugger` permissions, is then
|
|
204
235
|
loaded into every workspace Chromium profile and captures the exact workspace tab, not a
|
|
205
|
-
screenshot loop or title-selected window.
|
|
236
|
+
screenshot loop or title-selected window. When encoded video is off the helper is never
|
|
206
237
|
materialized or loaded, and clients show a one-time disabled reply then use JPEG.
|
|
207
238
|
Android and other native apps use JPEG: the plugin SDK this package targets publishes no
|
|
208
239
|
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
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { type PluginSurfaceProps, useSettings } from "@getpaseo/plugin/client";
|
|
2
|
+
import {
|
|
3
|
+
SettingsAction,
|
|
4
|
+
SettingsCard,
|
|
5
|
+
SettingsInput,
|
|
6
|
+
type SettingsInputHandle,
|
|
7
|
+
SettingsSection,
|
|
8
|
+
SettingsSelect,
|
|
9
|
+
} from "@getpaseo/plugin/client/ui";
|
|
10
|
+
import { useRef, useState } from "react";
|
|
11
|
+
import { Text } from "react-native";
|
|
12
|
+
import { type AgentAccessMode, agentAccessSettings, parseEntries } from "../shared/agent-access";
|
|
13
|
+
|
|
14
|
+
const MODE_OPTIONS: readonly { label: string; value: AgentAccessMode }[] = [
|
|
15
|
+
{ label: "Every new agent", value: "all" },
|
|
16
|
+
{ label: "Only the agents listed below", value: "listed" },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
type ListName = "providers" | "workspaces" | "projects";
|
|
20
|
+
const NO_ERRORS: Record<ListName, string | null> = {
|
|
21
|
+
providers: null,
|
|
22
|
+
workspaces: null,
|
|
23
|
+
projects: null,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Settings screen: which new agents get the browser tool. */
|
|
27
|
+
export function AgentAccessSettings({ theme }: PluginSurfaceProps) {
|
|
28
|
+
const settings = useSettings(agentAccessSettings);
|
|
29
|
+
const providers = useRef<SettingsInputHandle>(null);
|
|
30
|
+
const workspaces = useRef<SettingsInputHandle>(null);
|
|
31
|
+
const projects = useRef<SettingsInputHandle>(null);
|
|
32
|
+
// Errors belong to the revision they were found on; a newer revision (another client saved) clears them.
|
|
33
|
+
const [found, setFound] = useState<{
|
|
34
|
+
revision: string | null;
|
|
35
|
+
errors: Record<ListName, string | null>;
|
|
36
|
+
}>({ revision: null, errors: NO_ERRORS });
|
|
37
|
+
const muted = { color: theme.colors.foregroundMuted, fontSize: 13, lineHeight: 19 };
|
|
38
|
+
|
|
39
|
+
if (settings.status === "loading") {
|
|
40
|
+
return (
|
|
41
|
+
<SettingsSection title="Shared Browser: agent access">
|
|
42
|
+
<Text style={muted}>Loading</Text>
|
|
43
|
+
</SettingsSection>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (settings.status !== "ready") {
|
|
47
|
+
return (
|
|
48
|
+
<SettingsSection title="Shared Browser: agent access">
|
|
49
|
+
<Text style={muted}>{settings.error}</Text>
|
|
50
|
+
<SettingsCard>
|
|
51
|
+
<SettingsAction label="Try again" actionLabel="Reload" onPress={settings.reload} />
|
|
52
|
+
{settings.status === "invalid" ? (
|
|
53
|
+
<SettingsAction
|
|
54
|
+
label="Back to the default"
|
|
55
|
+
actionLabel="Reset"
|
|
56
|
+
onPress={settings.reset}
|
|
57
|
+
/>
|
|
58
|
+
) : null}
|
|
59
|
+
</SettingsCard>
|
|
60
|
+
</SettingsSection>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const { values } = settings;
|
|
65
|
+
const listErrors = found.revision === settings.revision ? found.errors : NO_ERRORS;
|
|
66
|
+
const save = (next: typeof values) => void settings.save(next, settings.revision);
|
|
67
|
+
// The lists as typed, parsed the same way for Save and for a mode change, so unsaved text is never
|
|
68
|
+
// lost to the revision remount. A list that does not parse shows its error and nothing is saved.
|
|
69
|
+
const typedLists = () => {
|
|
70
|
+
const parsed = {
|
|
71
|
+
providers: parseEntries(providers.current?.getText() ?? ""),
|
|
72
|
+
workspaces: parseEntries(workspaces.current?.getText() ?? ""),
|
|
73
|
+
projects: parseEntries(projects.current?.getText() ?? ""),
|
|
74
|
+
};
|
|
75
|
+
const errors = {
|
|
76
|
+
providers: parsed.providers.error,
|
|
77
|
+
workspaces: parsed.workspaces.error,
|
|
78
|
+
projects: parsed.projects.error,
|
|
79
|
+
};
|
|
80
|
+
setFound({ revision: settings.revision, errors });
|
|
81
|
+
if (errors.providers || errors.workspaces || errors.projects) return null;
|
|
82
|
+
return {
|
|
83
|
+
providers: parsed.providers.entries,
|
|
84
|
+
workspaces: parsed.workspaces.entries,
|
|
85
|
+
projects: parsed.projects.entries,
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
return (
|
|
89
|
+
<SettingsSection title="Shared Browser: agent access">
|
|
90
|
+
{/* Keyed on the revision, so the text inputs start over from the saved lists when another client changes them. */}
|
|
91
|
+
<SettingsCard key={settings.revision}>
|
|
92
|
+
<SettingsSelect
|
|
93
|
+
label="Browser tool for"
|
|
94
|
+
hint="Applies to agents created from now on. With the lists empty, no agent gets the tool."
|
|
95
|
+
error={settings.saveError}
|
|
96
|
+
value={values.mode}
|
|
97
|
+
options={MODE_OPTIONS}
|
|
98
|
+
disabled={settings.saving}
|
|
99
|
+
onValueChange={(mode) => {
|
|
100
|
+
const lists = typedLists();
|
|
101
|
+
if (lists) save({ ...values, ...lists, mode });
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
<SettingsInput
|
|
105
|
+
ref={providers}
|
|
106
|
+
label="Provider ids"
|
|
107
|
+
hint="Separated by commas or new lines. An agent whose provider is listed gets the tool."
|
|
108
|
+
initialValue={values.providers.join(", ")}
|
|
109
|
+
error={listErrors.providers}
|
|
110
|
+
onChangeText={() => {}}
|
|
111
|
+
disabled={settings.saving}
|
|
112
|
+
/>
|
|
113
|
+
<SettingsInput
|
|
114
|
+
ref={workspaces}
|
|
115
|
+
label="Workspace ids"
|
|
116
|
+
hint="Every new agent in a listed workspace gets the tool."
|
|
117
|
+
initialValue={values.workspaces.join(", ")}
|
|
118
|
+
error={listErrors.workspaces}
|
|
119
|
+
onChangeText={() => {}}
|
|
120
|
+
disabled={settings.saving}
|
|
121
|
+
/>
|
|
122
|
+
<SettingsInput
|
|
123
|
+
ref={projects}
|
|
124
|
+
label="Project ids"
|
|
125
|
+
hint="Every new agent in a workspace of a listed project gets the tool."
|
|
126
|
+
initialValue={values.projects.join(", ")}
|
|
127
|
+
error={listErrors.projects}
|
|
128
|
+
onChangeText={() => {}}
|
|
129
|
+
disabled={settings.saving}
|
|
130
|
+
/>
|
|
131
|
+
<SettingsAction
|
|
132
|
+
label="Save the lists"
|
|
133
|
+
actionLabel="Save"
|
|
134
|
+
disabled={settings.saving}
|
|
135
|
+
onPress={() => {
|
|
136
|
+
const lists = typedLists();
|
|
137
|
+
if (lists) save({ ...values, ...lists });
|
|
138
|
+
}}
|
|
139
|
+
/>
|
|
140
|
+
</SettingsCard>
|
|
141
|
+
</SettingsSection>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -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(
|