Repository navigation
fix: do not block indefinitely on thumbnails in desktopCapturer - #51128
Conversation
|
The Fiddle gist works for me on this patch.
The first failure is due to having external screens connected. That's unrelated. The second failure also happens for me on Electron 41.2.0. It's my password manager that won't let Electron record its window. |
|
Hm, we're still getting test failures in CI: Logs
|
05b54bb to
b70aaf6
Compare
|
Local test results on the most recent commit: I do notice that when I have my password manager open, tests take a lot longer to run now, given the 3-second timeout. (Maybe that's something we have to accept.) |
chore: remove unnecessary code
|
The mas tests ran through successfully! |
nikwen
left a comment
There was a problem hiding this comment.
Just reviewed the code. Looks good to me! 👍
Co-authored-by: Niklas Wenzel <[email protected]>
|
@nikwen thanks for all the feedback, it was a great help! |
|
@ckerr Thanks for working on it! If you could merge it, I'd appreciate that. |
|
Release Notes Persisted
|
* fix: timing issue DCHECK crash in DesktopCapturer on macOS (#50960) refactor: use StartUpdating in desktopCapturer Replace the one-shot Update() callback model with the continuous StartUpdating() observer model for NativeDesktopMediaList. Fixes a macOS DCHECK(can_refresh()) crash in UpdateSourceThumbnail(), where ScreenCaptureKit's recurrent thumbnail capturer would post UpdateSourceThumbnail callbacks after the one-shot refresh_callback_ had been consumed. Now, can_refresh() is always true because refresh_callback_ is repopulated via ScheduleNextRefresh(). Each capturer (window, screen) gets its own ListObserver that tracks readiness via OnSourceAdded and OnSourceThumbnailChanged events. Once a list has both sources and thumbnails (or thumbnails aren't requested), its data is snapshotted and the capturer checks if all requested types are ready before resolving to JS. Also remove the "skip_next_refresh_" Chromium patch, which was a workaround for the timing mismatch between the one-shot Update() model and ScreenCaptureKit's asynchronous thumbnail delivery. refactor: simplify state logic in DesktopCapturer (cherry picked from commit dad4ab6) * fix: do not block indefinitely on thumbnails in desktopCapturer (#51128) * fix: do not block indefinitely on thumbnails in desktopCapturer fixes dad4ab6 regression * fix: build error * fixup! fix: do not block indefinitely on thumbnails in desktopCapturer chore: remove unnecessary code * Update shell/browser/api/electron_api_desktop_capturer.cc Co-authored-by: Niklas Wenzel <[email protected]> --------- Co-authored-by: Niklas Wenzel <[email protected]> (cherry picked from commit a1d28e6) * fix: dangling `raw_ptr` regression in `DesktopCapturer` (#51158) fix: dangling raw_ptr in desktopCapturer (cherry picked from commit bef68b6) * fix: do not pass a `DesktopMediaList* to DesktopCapturer::OnListReady()` (#51399) refactor: do not pass a DesktopMediaList* to DesktopCapturer::OnListReady() The list pointer was being used as a proxy for its type, so just pass the type instead. This solves a lifecycle issue occurring in CI where the callack can outlive the DesktopMediaList. Sample error log: [48471:0428/193441.269750:FATAL:base/allocator/partition_alloc_support.cc:798] Detected dangling raw_ptr in unretained with id=0x0000013c02e14378: Task trace: 0 Electron Framework 0x000000012283a0ba electron::api::DesktopCapturer::ListObserver::MaybeNotifyReady() + 170 1 Electron Framework 0x0000000133246dc5 NativeDesktopMediaList::Worker::OnRecurrentCaptureResult(webrtc::DesktopCapturer::Result, std::__Cr::unique_ptr<webrtc::DesktopFrame, std::__Cr::default_delete<webrtc::DesktopFrame>>, long) + 357 2 Electron Framework 0x000000013328dbcf (anonymous namespace)::ScreenshotManagerCapturer::OnRecurrentCaptureTimer() + 1343 Stack trace: 0 Electron Framework 0x000000012ade42f2 base::debug::CollectStackTrace(base::span<void const*, 18446744073709551615ul, void const**>) + 18 1 Electron Framework 0x000000012add00e1 base::debug::StackTrace::StackTrace(unsigned long) + 225 2 Electron Framework 0x000000012ade978a base::allocator::UnretainedDanglingRawPtrDetectedCrash(unsigned long) + 90 3 Electron Framework 0x000000012ae437f7 base::internal::RawPtrBackupRefImpl<true>::ReportIfDanglingInternal(unsigned long) + 391 (cherry picked from commit f8d0412) --------- Co-authored-by: Charles Kerr <[email protected]> Co-authored-by: Niklas Wenzel <[email protected]>
…e stack (#3414) Electron 42's macOS ScreenCaptureKit backend bounds getSources() at ~3s (upstream hang/crash fixes), returning an empty array or empty thumbnails when enumerations run back-to-back. The picker's 3s polling plus the post-selection re-enumeration turned those empty results into a blank "No windows found" list and denied valid share attempts. - Split the desktop capturer cache into per-type buckets: screen-only enumeration is fast (~700ms) and reliable; window enumeration is paced with a 4s post-completion cooldown (cold-start chain bypasses it once) - Never overwrite a non-empty bucket with an empty enumeration result; keep the bucket stale so it retries on the next opportunity - Merge thumbnails by source id so a source arriving with an empty thumbnail keeps its last good preview instead of being dropped - Validate the selected source against the cache (the same list the picker rendered from) instead of re-enumerating on Share; fall back to one direct enumeration only when the cache is empty - Keep the previous source list when a renderer fetch fails Measured on macOS with Electron 42.5.0: tight-loop getSources returned 0 sources in ~75% of calls; screen-only calls never failed; alternating per-type calls with 4s gaps returned complete results every round. Documented in docs/KNOWN_ISSUES.md with upstream refs (electron/electron#51128, electron/electron#50960) and the macOS 15+ useSystemPicker follow-up.
…icker, sidebar tooltip) (#3417) * fix: #3244 sidebar tooltip null in shortcut formatting (#3326) - index.tsx: order <= 9 -> order < 9 (off-by-one, server #10 showed shortcut) - ServerButton.tsx: conditional shortcut string in tooltip (null rendered as '(^+null)') (cherry picked from commit e405a6a) * fix: keep screen picker sources stable under Electron 42 macOS capture stack (#3414) Electron 42's macOS ScreenCaptureKit backend bounds getSources() at ~3s (upstream hang/crash fixes), returning an empty array or empty thumbnails when enumerations run back-to-back. The picker's 3s polling plus the post-selection re-enumeration turned those empty results into a blank "No windows found" list and denied valid share attempts. - Split the desktop capturer cache into per-type buckets: screen-only enumeration is fast (~700ms) and reliable; window enumeration is paced with a 4s post-completion cooldown (cold-start chain bypasses it once) - Never overwrite a non-empty bucket with an empty enumeration result; keep the bucket stale so it retries on the next opportunity - Merge thumbnails by source id so a source arriving with an empty thumbnail keeps its last good preview instead of being dropped - Validate the selected source against the cache (the same list the picker rendered from) instead of re-enumerating on Share; fall back to one direct enumeration only when the cache is empty - Keep the previous source list when a renderer fetch fails Measured on macOS with Electron 42.5.0: tight-loop getSources returned 0 sources in ~75% of calls; screen-only calls never failed; alternating per-type calls with 4s gaps returned complete results every round. Documented in docs/KNOWN_ISSUES.md with upstream refs (electron/electron#51128, electron/electron#50960) and the macOS 15+ useSystemPicker follow-up. (cherry picked from commit dddd2cc) * fix: externalize dependency subpath imports in rollup bundles (#3411) rollup externals matched module ids by exact name only, so subpath entrypoints like `react-dom/client` (used by createRoot in rootWindow.ts, log-viewer-window.tsx, and screenSharePickerMount.tsx) did not match the `react-dom` external and got bundled as build-time-NODE_ENV ReactDOM, while `react` stayed external and resolved to a different (dev) copy from the asar at runtime — mixing incompatible React internals and crashing the renderer (SUP-1072, ReferenceError: exports is not defined). makeExternal() now matches `id === moduleName || id.startsWith(moduleName + '/')` so subpath imports are externalized alongside their base package. scripts/check-bundle-externals.mjs guards the build against regressing back to bundled React internals, wired into `yarn build`. (backported to 4.15.x) Adapted from master commit 0dafe39: 4.15.4 has no `screen-picker-window.js` rollup entry (the screen picker mounts inside the video-call-window bundle via screenSharePickerMount.tsx, not a separate window/entry point in this release), so that entry and its assertions were omitted from check-bundle-externals.mjs. All other bundle configs and the check script are ported as-is. * fix: correct auto-merge artifact in ScreenSharingRequestTracker backport The cherry-pick of dddd2cc (#3414) auto-merged with references to master's entry/finishActive queue API, which doesn't exist in 4.15.4's flat cb/markComplete structure — this failed typecheck. Replaced with 4.15.4's existing cb(...) calling convention, matching the fallback path directly below it in the same function. Also fixed the corresponding cherry-picked spec assertion: it expected cb to be called with `null` (master's deny convention), but 4.15.4's DisplayMediaCallback deny convention is `{ video: false }` throughout this file — updated the assertion to match. * fix: remove leftover merge-conflict marker fragment from KNOWN_ISSUES.md The docs/KNOWN_ISSUES.md merge during the backport left a trailing `>>>>>>> dddd2cc (...)` conflict-marker remnant appended to the last line of the file. Removed; no other content was affected.
Regression test for #51128 and #51329, where asking for screen and window sources with thumbnails several times in a row hung or crashed the main process. The spec makes three back-to-back calls for both source types with a thumbnail size and expects each to resolve. Verified against Linux release builds: hangs on 43.0.0-nightly.20260323, crashes on 43.0.0-nightly.20260418, passes on 43.0.0-nightly.20260420.
Description of Change
Fixes #51125.
Fixes #51124.
Fixes a
desktopCapturerregression introduced in dad4ab6. Only affectsmain.Checklist
npm testpassesRelease Notes
Notes: Fixed
desktopCapturer.getSources()hanging on macOS.