fix(preview): restore recording and macOS rendering after Electron 43 #9001
MergedStiensWout(GitHub profile, opens in a new tab)merged 17 commits into
main fromrefs/pull/9001/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
- apps/web/src/browser/HostedBrowserWebview.tsx lines 240 to 247OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -237,4 +237,11 @@237237238238 if (!config) return null;239239240- const renderingActive = active || backgroundActivity || pictureInPicture || recordingActive;240+ // Electron 43 can leave a macOS webview blank after `visibility: hidden`.241+ // Keep macOS guests paintable offscreen until Electron can reliably resume them.242+ const renderingActive =243+ active ||244+ backgroundActivity ||245+ pictureInPicture ||246+ recordingActive ||247+ isMacPlatform(navigator.platform);
StiensWout(GitHub profile, opens in a new tab) changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
StiensWout(GitHub profile, opens in a new tab) changed the title
- apps/desktop/src/preview/Manager.ts line 3306Resolvedby StiensWout(GitHub profile, opens in a new tab)@@ -3152,17 +3220,5 @@31523220 webContentsId: wc.id,31533221 });31543222 }3155- const sourceId = yield* attempt(3156- {3157- operation: "recording.getMediaSourceId",3158- tabId,3159- webContentsId: wc.id,3160- },3161- () => wc.getMediaSourceId(requestWebContents),3162- );3163- return {3164- sourceId,3165- width: measuredSize.width,3166- height: measuredSize.height,3167- } satisfies DesktopPreviewRecordingSource;3168- }).pipe(Effect.onError(() => stopFrameCapture(tabId, "recording").pipe(Effect.ignore))),3223+ installDisplayMediaRequestHandler(requestWebContents.session);3224+ yield* armPendingRecording(tabId, wc, requestWebContents.mainFrame.frameTreeNodeId);
- apps/web/src/browser/HostedBrowserWebview.tsx lines 244 to 246OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -241,3 +241,6 @@241241 const wrapperStyle = resolveHostedBrowserWebviewWrapperStyle({242242 active,243243 renderingActive,244+ // Electron 43 can leave a macOS webview blank after `visibility: hidden`.245+ // Keep it paintable offscreen without reporting it as active to automation.246+ keepPaintableWhenInactive: isMacPlatform(navigator.platform),
- apps/web/src/browser/browserRecording.ts line 390OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -402,6 +386,5 @@402386 () => getClientSettings().browserRecordingFrameRate,403387 );404388 const [frameRate] = await Promise.all([frameRatePromise, waitForBrowserRecordingPaint()]);405- let source: DesktopPreviewRecordingSource;406389 try {407- source = await bridge.recording.startScreencast(tabId);390+ await bridge.recording.startScreencast(tabId);
StiensWout(GitHub profile, opens in a new tab) changed the title
- apps/web/src/browser/browserRecording.ts line 589OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -455,0 +439,21 @@439+ await throwIfStartupCancelled();440+ try {441+ recording.stream = await captureTabMediaStreamWithTimeout(tabId, frameRate);442+ return recording.stream;443+ } catch (cause) {444+ const cleanupCause = await cleanupFailedRecordingStart(bridge, recording);445+ if (isBrowserRecordingCaptureTimeoutError(cause) && cleanupCause === undefined) throw cause;446+ throw new BrowserRecordingOperationError({447+ operation: "capture-media-stream",448+ tabId,449+ cause:450+ cleanupCause === undefined451+ ? cause452+ : new AggregateError(453+ [cause, cleanupCause],454+ `Browser media capture and cleanup failed for tab ${tabId}.`,455+ { cause },456+ ),457+ });458+ }459+ });
- apps/web/src/browser/browserRecording.ts line 783Resolvedby StiensWout(GitHub profile, opens in a new tab)@@ -639,3 +676,4 @@639676 const recording = activeRecordings.get(tabId);640677 if (!bridge || !recording) return Promise.resolve(null);641678 if (recording.lifecycle.phase === "stopping") return recording.lifecycle.stopPromise;679+ if (recording.lifecycle.phase === "starting") recording.lifecycle.cancelBeforeGrant();
- apps/web/src/browser/browserRecording.ts line 419OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -382,3 +416,4 @@382416 const startupSettled = new Promise<void>((resolve) => {383417 settleStartup = resolve;384418 });419+ const startingLifecycle = makeStartingBrowserRecordingLifecycle(displayMediaGrantQueueDepth > 0);
- apps/web/src/browser/browserRecording.ts lines 92 to 94OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -82,3 +89,6 @@82898390 const isBrowserRecordingOperationError = Schema.is(BrowserRecordingOperationError);8491 const isBrowserRecordingCaptureTimeoutError = Schema.is(BrowserRecordingCaptureTimeoutError);92+const matchesBrowserRecordingStartCancelledError = Schema.is(BrowserRecordingStartCancelledError);93+export const isBrowserRecordingStartCancelledError = (error: unknown): boolean =>94+ matchesBrowserRecordingStartCancelledError(error);
- apps/web/src/browser/browserRecording.ts lines 254 to 257Resolvedby StiensWout(GitHub profile, opens in a new tab)@@ -184,8 +242,7 @@184242 return mimeType ? new MediaRecorder(stream, { mimeType }) : new MediaRecorder(stream);185243 };186244187-const captureTabMediaStream = (188- source: DesktopPreviewRecordingSource,189- frameRate: number,190-): Promise<MediaStream> =>191- navigator.mediaDevices.getUserMedia({245+const captureTabMediaStream = (frameRate: number): Promise<MediaStream> =>246+ // The desktop main process routes this request to the tab that `startScreencast` armed, so the247+ // stream already arrives at that tab's native size and needs no source or dimension constraints.248+ navigator.mediaDevices.getDisplayMedia({
- apps/web/src/browser/browserRecording.ts line 582OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -455,0 +562,21 @@562+ try {563+ recording.stream = await captureTabMediaStreamWithTimeout(tabId, capture.capturePromise);564+ return recording.stream;565+ } catch (cause) {566+ const cleanupCause = await cleanupFailedRecordingStart(bridge, recording);567+ if (isBrowserRecordingCaptureTimeoutError(cause) && cleanupCause === undefined) throw cause;568+ throw new BrowserRecordingOperationError({569+ operation: "capture-media-stream",570+ tabId,571+ cause:572+ cleanupCause === undefined573+ ? cause574+ : new AggregateError(575+ [cause, cleanupCause],576+ `Browser media capture and cleanup failed for tab ${tabId}.`,577+ { cause },578+ ),579+ });580+ }581+ });582+ startingLifecycle.queuedForGrant = grant.queued;
- apps/desktop/src/preview/Manager.ts lines 3241 to 3245OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -3158,11 +3233,13 @@3233+ operation: "recording.requestCapture",31583234 tabId,3159- webContentsId: wc.id,3235+ webContentsId: requestWebContents.id,31603236 },3161- () => wc.getMediaSourceId(requestWebContents),3237+ () =>3238+ requestWebContents.executeJavaScript(requestRecordingCaptureExpression(tabId), true),31623239 );3163- return {3164- sourceId,3165- width: measuredSize.width,3166- height: measuredSize.height,3167- } satisfies DesktopPreviewRecordingSource;3168- }).pipe(Effect.onError(() => stopFrameCapture(tabId, "recording").pipe(Effect.ignore))),3240+ if (captureRequested !== true) {3241+ return yield* new PreviewOperationError({3242+ operation: "recording.requestCapture",3243+ tabId,3244+ webContentsId: requestWebContents.id,3245+ cause: new Error("The preview recording capture handler is unavailable."),
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
juliusmarminge merged thisef7014d
juliusmarminge closed this
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed