Skip to content

Commit 14cb6ff

Browse files
committed
fix(preview): prime hidden native recordings
1 parent 5f9370b commit 14cb6ff

4 files changed

Lines changed: 22 additions & 17 deletions

File tree

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,8 +2146,8 @@ describe("PreviewManager", () => {
21462146
{ sourceId: "tab:41", width: 800, height: 600 },
21472147
{ sourceId: "tab:42", width: 390, height: 844 },
21482148
]);
2149-
expect(firstCapturePage).not.toHaveBeenCalled();
2150-
expect(secondCapturePage).not.toHaveBeenCalled();
2149+
expect(firstCapturePage).toHaveBeenCalledOnce();
2150+
expect(secondCapturePage).toHaveBeenCalledOnce();
21512151
expect(firstSendCommand).not.toHaveBeenCalledWith(
21522152
"Page.startScreencast",
21532153
expect.anything(),
@@ -2440,19 +2440,19 @@ describe("PreviewManager", () => {
24402440
const pictureInPictureFramesBeforeRecording = pictureInPictureSend.mock.calls.length;
24412441

24422442
yield* manager.startRecording("tab_pip");
2443-
expect(capturePage).toHaveBeenCalledOnce();
2443+
expect(capturePage).toHaveBeenCalledTimes(2);
24442444
expect(recordingFrames).toHaveLength(0);
24452445

24462446
yield* TestClock.adjust(100);
2447-
expect(capturePage).toHaveBeenCalledTimes(2);
2447+
expect(capturePage).toHaveBeenCalledTimes(3);
24482448
expect(pictureInPictureSend).toHaveBeenCalledTimes(pictureInPictureFramesBeforeRecording);
24492449
expect(recordingFrames).toHaveLength(0);
24502450

24512451
yield* manager.stopRecording("tab_pip");
24522452
expect(setBackgroundThrottling.mock.calls).toEqual([[false]]);
24532453
const framesBeforePictureInPictureOnlyTick = pictureInPictureSend.mock.calls.length;
24542454
yield* TestClock.adjust(100);
2455-
expect(capturePage).toHaveBeenCalledTimes(3);
2455+
expect(capturePage).toHaveBeenCalledTimes(4);
24562456
expect(pictureInPictureSend.mock.calls.length).toBe(framesBeforePictureInPictureOnlyTick);
24572457
expect(recordingFrames).toHaveLength(0);
24582458

@@ -2470,7 +2470,7 @@ describe("PreviewManager", () => {
24702470
),
24712471
);
24722472

2473-
effectIt.effect("starts picture-in-picture without an extra recording capture", () =>
2473+
effectIt.effect("keeps picture-in-picture capture separate from recording warmup", () =>
24742474
withManager((manager) =>
24752475
Effect.gen(function* () {
24762476
const jpeg = Buffer.from("shared-preview-frame");
@@ -2495,14 +2495,14 @@ describe("PreviewManager", () => {
24952495
yield* manager.startRecording("tab_recording_then_pip");
24962496

24972497
expect(recordingFrames).toHaveLength(0);
2498-
expect(capturePage).not.toHaveBeenCalled();
2499-
yield* manager.openPictureInPicture("tab_recording_then_pip");
25002498
expect(capturePage).toHaveBeenCalledOnce();
2499+
yield* manager.openPictureInPicture("tab_recording_then_pip");
2500+
expect(capturePage).toHaveBeenCalledTimes(2);
25012501
expect(send).toHaveBeenCalledOnce();
25022502

25032503
yield* TestClock.adjust(100);
25042504

2505-
expect(capturePage).toHaveBeenCalledTimes(2);
2505+
expect(capturePage).toHaveBeenCalledTimes(3);
25062506
expect(recordingFrames).toHaveLength(0);
25072507
expect(send).toHaveBeenCalledOnce();
25082508
yield* manager.closePictureInPicture("tab_recording_then_pip");

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,6 +3137,14 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
31373137
webContentsId: wc.id,
31383138
});
31393139
}
3140+
yield* attemptPromise(
3141+
{
3142+
operation: "recording.warmSource",
3143+
tabId,
3144+
webContentsId: wc.id,
3145+
},
3146+
() => wc.capturePage().then(() => undefined),
3147+
);
31403148
const currentWebContents = yield* requireWebContents(tabId);
31413149
if (currentWebContents !== wc || wc.isDestroyed()) {
31423150
return yield* new PreviewWebContentsNotFoundError({

‎apps/web/src/browser/hostedBrowserWebviewStyle.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe("resolveHostedBrowserWebviewWrapperStyle", () => {
6161
});
6262
});
6363

64-
it("keeps an active background task paintable behind the app", () => {
64+
it("keeps an active background task paintable offscreen", () => {
6565
const style = resolveHostedBrowserWebviewWrapperStyle({
6666
active: false,
6767
renderingActive: true,
@@ -70,8 +70,8 @@ describe("resolveHostedBrowserWebviewWrapperStyle", () => {
7070
});
7171

7272
expect(style).toEqual({
73-
left: 0,
74-
top: 0,
73+
left: HIDDEN_BROWSER_WEBVIEW_OFFSET,
74+
top: HIDDEN_BROWSER_WEBVIEW_OFFSET,
7575
width: 1280,
7676
height: 800,
7777
zIndex: -1,

‎apps/web/src/browser/hostedBrowserWebviewStyle.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ export function resolveHostedBrowserWebviewWrapperStyle(input: {
3939
}
4040

4141
return {
42-
// Chromium can cull a guest that has never produced an onscreen frame.
43-
// Keep active background work behind the app so native tab capture can
44-
// start before the user has ever opened this preview.
45-
left: renderingActive ? 0 : HIDDEN_BROWSER_WEBVIEW_OFFSET,
46-
top: renderingActive ? 0 : HIDDEN_BROWSER_WEBVIEW_OFFSET,
42+
left: HIDDEN_BROWSER_WEBVIEW_OFFSET,
43+
top: HIDDEN_BROWSER_WEBVIEW_OFFSET,
4744
width: hiddenSize.width,
4845
height: hiddenSize.height,
4946
zIndex: -1,

0 commit comments

Comments
 (0)