-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Stabilize preview browser surfaces, automation, and recording #3565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
25e1e40
Guard browser surface updates with leases
juliusmarminge 3360f82
Keep recording webviews paintable before screencast
juliusmarminge 81d245e
Prevent preview recording from starting after cancellation
juliusmarminge 6549894
Pin preview automation to opened tabs
juliusmarminge 35a5ef9
Support explicit preview tab targeting
juliusmarminge b73f28b
Fix preview recording tab and browser recording races
juliusmarminge 17d7e94
Preserve preview tab routing and dedupe recording stops
juliusmarminge 1d01891
Wait for recording startup before releasing the slot
juliusmarminge 9d013ed
Switch preview to native surface handling
juliusmarminge 4082d9e
Refactor preview webview registration and config flow
juliusmarminge eca28d2
Fix offscreen browser automation regressions
juliusmarminge 5d15645
Keep recording slot during startup timeout cleanup
juliusmarminge 08bca50
Discard timed-out recording startup cleanup
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| const { events, onFrame, registrySet, save, startScreencast, stopScreencast } = vi.hoisted(() => { | ||
| const events: string[] = []; | ||
| return { | ||
| events, | ||
| onFrame: vi.fn(() => vi.fn()), | ||
| registrySet: vi.fn((_atom: unknown, value: string | null) => { | ||
| events.push(value === null ? "clear" : `publish:${value}`); | ||
| }), | ||
| save: vi.fn(async () => ({ | ||
| id: "recording-test", | ||
| tabId: "recording-tab", | ||
| path: "/tmp/recording-test.webm", | ||
| mimeType: "video/webm" as const, | ||
| sizeBytes: 0, | ||
| createdAt: "2026-06-26T00:00:00.000Z", | ||
| })), | ||
| startScreencast: vi.fn(async () => { | ||
| events.push("start-screencast"); | ||
| }), | ||
| stopScreencast: vi.fn(async () => undefined), | ||
| }; | ||
| }); | ||
|
|
||
| vi.mock("~/components/preview/previewBridge", () => ({ | ||
| previewBridge: { | ||
| recording: { onFrame, save, startScreencast, stopScreencast }, | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("~/rpc/atomRegistry", () => ({ | ||
| appAtomRegistry: { set: registrySet }, | ||
| })); | ||
|
|
||
| vi.mock("./browserSurfaceStore", () => ({ | ||
| useBrowserSurfaceStore: { | ||
| getState: () => ({ byTabId: {} }), | ||
| }, | ||
| })); | ||
|
|
||
| import { startBrowserRecording, stopBrowserRecording } from "./browserRecording"; | ||
|
|
||
| class FakeMediaRecorder { | ||
| static isTypeSupported(): boolean { | ||
| return true; | ||
| } | ||
|
|
||
| state: RecordingState = "inactive"; | ||
| private readonly listeners = new Map<string, Set<EventListenerOrEventListenerObject>>(); | ||
|
|
||
| addEventListener(type: string, listener: EventListenerOrEventListenerObject): void { | ||
| const listeners = this.listeners.get(type) ?? new Set(); | ||
| listeners.add(listener); | ||
| this.listeners.set(type, listeners); | ||
| } | ||
|
|
||
| start(): void { | ||
| this.state = "recording"; | ||
| } | ||
|
|
||
| stop(): void { | ||
| this.state = "inactive"; | ||
| for (const listener of this.listeners.get("stop") ?? []) { | ||
| if (typeof listener === "function") listener(new Event("stop")); | ||
| else listener.handleEvent(new Event("stop")); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| describe("browser recording surface preparation", () => { | ||
| beforeEach(() => { | ||
| events.length = 0; | ||
| vi.clearAllMocks(); | ||
| vi.stubGlobal("window", globalThis); | ||
| vi.stubGlobal("MediaRecorder", FakeMediaRecorder as unknown as typeof MediaRecorder); | ||
| vi.stubGlobal("document", { | ||
| createElement: () => ({ | ||
| width: 0, | ||
| height: 0, | ||
| captureStream: () => ({}), | ||
| getContext: () => ({ drawImage: vi.fn() }), | ||
| }), | ||
| }); | ||
| let frameId = 0; | ||
| vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) => { | ||
| const id = ++frameId; | ||
| queueMicrotask(() => { | ||
| events.push(`paint:${id}`); | ||
| callback(id); | ||
| }); | ||
| return id; | ||
| }); | ||
| vi.stubGlobal("cancelAnimationFrame", vi.fn()); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| it("makes an inactive guest paintable before starting its screencast", async () => { | ||
| await startBrowserRecording("recording-tab"); | ||
|
|
||
| expect(events).toEqual([ | ||
| "publish:recording-tab", | ||
| "paint:1", | ||
| "paint:2", | ||
| "start-screencast", | ||
| "publish:recording-tab", | ||
| ]); | ||
|
|
||
| await stopBrowserRecording("recording-tab"); | ||
| }); | ||
| }); |
|
macroscopeapp[bot] marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.