GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(preview): preserve browser sharpness while scrolling · nckrtl/conn@7fc4897

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/preview
    • ServerBrowser.test.ts
    • ServerBrowser.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/preview/ServerBrowser.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/preview/ServerBrowser.test.ts
+36-1Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ vi.mock("./ServerBrowserContexts.ts", () => ({
6161
}));
6262

6363
function makeSession() {
64+
const events = new NodeEvents.EventEmitter();
6465
return {
65-
on: vi.fn(),
66+
on: vi.fn((name: string, callback: (...args: unknown[]) => void) => events.on(name, callback)),
67+
emit: (name: string, ...args: unknown[]) => events.emit(name, ...args),
6668
detach: vi.fn(async () => {}),
6769
send: vi.fn(async (method: string, _input?: unknown): Promise<Record<string, unknown>> => {
6870
if (method === "Page.getNavigationHistory") return { currentIndex: 0, entries: [{}] };
@@ -279,6 +281,39 @@ beforeEach(() => {
279281
desktopConnections.length = 0;
280282
});
281283

284+
it.live("keeps the requested frame resolution and quality during scroll bursts", () =>
285+
Effect.scoped(
286+
Effect.gen(function* () {
287+
const { browser, tabId } = yield* ready;
288+
const viewer = yield* browser.attachViewer(viewerInput(tabId, true));
289+
yield* viewer.input({ type: "takeControl" });
290+
const session = contexts[0]!.sessions.at(-1)!;
291+
const clock = vi.spyOn(Date, "now").mockReturnValue(1_000_000);
292+
yield* Effect.addFinalizer(() => Effect.sync(() => clock.mockRestore()));
293+
294+
for (let index = 0; index < 8; index++) {
295+
yield* viewer.input({ type: "wheel", x: 10, y: 10, deltaX: 0, deltaY: 100 });
296+
session.emit("Page.screencastFrame", {
297+
data: "ZnJhbWU=",
298+
sessionId: index + 1,
299+
});
300+
}
301+
yield* viewer.input({ type: "wheel", x: 10, y: 10, deltaX: 0, deltaY: 100 });
302+
303+
const starts = session.send.mock.calls.filter(
304+
([method]) => method === "Page.startScreencast",
305+
);
306+
expect(starts).toEqual([
307+
["Page.startScreencast", { format: "jpeg", quality: 70, maxWidth: 1280, maxHeight: 800 }],
308+
]);
309+
expect(session.send).toHaveBeenCalledWith(
310+
"Input.dispatchMouseEvent",
311+
expect.objectContaining({ type: "mouseWheel", deltaY: 100 }),
312+
);
313+
}),
314+
).pipe(Effect.provide(layer)),
315+
);
316+
282317
it.live("readiness none responds immediately but takeover input waits for navigation commit", () =>
283318
Effect.scoped(
284319
Effect.gen(function* () {
Collapse file

‎apps/server/src/preview/ServerBrowser.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/preview/ServerBrowser.ts
+7-38Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ const RENDER_SCALE = 2;
9090
// Chromium allows three unacked frames, so 100 ms pacing caps viewers near 30 fps.
9191
const SCREENCAST_ACK_PACE_MS = 100;
9292
const SCREENCAST_SETTLE_MS = 200;
93-
// Only scrolling triggers reduced-quality motion frames; animations stay sharp.
94-
const SCREENCAST_MOTION_FRAMES = 4;
95-
const SCREENCAST_MOTION_WINDOW_MS = 300;
96-
const SCREENCAST_MOTION_QUALITY = 50;
9793
const HOST_RECONNECT_DELAY = "1 second";
9894
/** How long a new tab waits for the desktop app to mount it before running headless. */
9995
const DESKTOP_ATTACH_TIMEOUT = "10 seconds";
@@ -264,7 +260,6 @@ interface ViewerState {
264260
readonly push: (output: ServerBrowserViewerOutput) => void;
265261
readonly pause: () => Promise<void>;
266262
readonly resume: () => Promise<void>;
267-
scrolledAt: number;
268263
/** Last input from this viewer; page copies reach its clipboard only right after. */
269264
inputAt: number;
270265
/** Panel bounds, retained in fixed mode; passive viewers never request a size. */
@@ -2149,7 +2144,6 @@ const make = Effect.gen(function* () {
21492144
return;
21502145
}
21512146
case "wheel":
2152-
viewer.scrolledAt = Date.now();
21532147
await session.send("Input.dispatchMouseEvent", {
21542148
type: "mouseWheel",
21552149
x: num(message.x),
@@ -2288,22 +2282,18 @@ const make = Effect.gen(function* () {
22882282
// Chromium may drop the final frame during a burst; send a still when it settles.
22892283
let framesInFlight = 0;
22902284
let mayHaveDropped = false;
2291-
let motion = false;
2292-
const recentFrames: Array<number> = [];
22932285
let screencastParams = Promise.resolve();
2294-
let screencastScale = 1;
2295-
const startScreencast = (scale: number) => {
2296-
screencastScale = scale;
2286+
const startScreencast = () => {
22972287
screencastParams = screencastParams.then(async () => {
22982288
// A scaled capture is rendering; its resume starts the stream.
22992289
if (tab.capturing > 0) return;
23002290
await session.send("Page.stopScreencast").catch(constVoid);
23012291
await session
23022292
.send("Page.startScreencast", {
23032293
format: "jpeg",
2304-
quality: screencastScale < 1 ? Math.min(quality, SCREENCAST_MOTION_QUALITY) : quality,
2305-
maxWidth: Math.max(1, Math.round(input.maxWidth * screencastScale)),
2306-
maxHeight: Math.max(1, Math.round(input.maxHeight * screencastScale)),
2294+
quality,
2295+
maxWidth: Math.max(1, Math.round(input.maxWidth)),
2296+
maxHeight: Math.max(1, Math.round(input.maxHeight)),
23072297
})
23082298
.catch(constVoid);
23092299
});
@@ -2336,8 +2326,7 @@ const make = Effect.gen(function* () {
23362326
);
23372327
return screencastParams;
23382328
},
2339-
resume: () => startScreencast(screencastScale),
2340-
scrolledAt: 0,
2329+
resume: startScreencast,
23412330
inputAt: 0,
23422331
requestedSize: null,
23432332
};
@@ -2383,31 +2372,11 @@ const make = Effect.gen(function* () {
23832372
if (framesInFlight > 0) mayHaveDropped = true;
23842373
framesInFlight += 1;
23852374
const arrivedAt = Date.now();
2386-
recentFrames.push(arrivedAt);
2387-
while (recentFrames[0]! < arrivedAt - SCREENCAST_MOTION_WINDOW_MS) recentFrames.shift();
2388-
if (
2389-
!motion &&
2390-
recentFrames.length >= SCREENCAST_MOTION_FRAMES &&
2391-
arrivedAt - viewer.scrolledAt < SCREENCAST_MOTION_WINDOW_MS
2392-
) {
2393-
motion = true;
2394-
void startScreencast(0.5);
2395-
} else if (motion && arrivedAt - viewer.scrolledAt > SCREENCAST_SETTLE_MS) {
2396-
// The page keeps animating after the scroll; its own frames are sharp again.
2397-
motion = false;
2398-
recentFrames.length = 0;
2399-
void startScreencast(1);
2400-
}
24012375
if (settleTimer !== null) clearTimeout(settleTimer);
24022376
settleTimer = setTimeout(() => {
24032377
settleTimer = null;
2404-
if (!motion && !mayHaveDropped) return;
2378+
if (!mayHaveDropped) return;
24052379
mayHaveDropped = false;
2406-
if (motion) {
2407-
motion = false;
2408-
recentFrames.length = 0;
2409-
void startScreencast(1);
2410-
}
24112380
void pushStill();
24122381
}, SCREENCAST_SETTLE_MS);
24132382
viewer.push({
@@ -2424,7 +2393,7 @@ const make = Effect.gen(function* () {
24242393
});
24252394
});
24262395
broadcastViewport(tab);
2427-
yield* Effect.promise(() => startScreencast(1));
2396+
yield* Effect.promise(startScreencast);
24282397
// An idle page does not repaint for a new screencast, so the viewer
24292398
// starts from a still unless a live frame beat it.
24302399
if (!screencastStarted) yield* Effect.promise(pushStill);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.