fix: third time screen sharing on macOS (#43767)

Because we used decrementing negative source ids for fake video id when
instantating a native macOS screen share picker, we eventually hit the
`DesktopMediaID::kFakeId = -3` in Chromium source code which displayed a
test green screen.

In this change we reserve our own fake id of `-4` and decrement the
window id integer for uniqueness instead.

Co-authored-by: Fedor Indutny <238531+indutny@users.noreply.github.com>
This commit is contained in:
Fedor Indutny 2024-09-19 18:28:28 -07:00 committed by GitHub
parent d100921289
commit 6aa6bada79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 69 additions and 3 deletions

View file

@ -3,14 +3,16 @@ import { net } from 'electron/main';
const { fromPartition, fromPath, Session } = process._linkedBinding('electron_browser_session');
const { isDisplayMediaSystemPickerAvailable } = process._linkedBinding('electron_browser_desktop_capturer');
// Fake video source that activates the native system picker
// Fake video window that activates the native system picker
// This is used to get around the need for a screen/window
// id in Chrome's desktopCapturer.
let fakeVideoSourceId = -1;
let fakeVideoWindowId = -1;
// See content/public/browser/desktop_media_id.h
const kMacOsNativePickerId = -4;
const systemPickerVideoSource = Object.create(null);
Object.defineProperty(systemPickerVideoSource, 'id', {
get () {
return `window:${fakeVideoSourceId--}:0`;
return `window:${kMacOsNativePickerId}:${fakeVideoWindowId--}`;
}
});
systemPickerVideoSource.name = '';