diff --git a/shell/browser/electron_browser_context.cc b/shell/browser/electron_browser_context.cc index f0534ad6d5..77ed1e4e65 100644 --- a/shell/browser/electron_browser_context.cc +++ b/shell/browser/electron_browser_context.cc @@ -580,7 +580,7 @@ void ElectronBrowserContext::DisplayMediaDeviceChosen( blink::MediaStreamDevice video_device(request.video_type, id, name); video_device.display_media_info = DesktopMediaIDToDisplayMediaInformation( nullptr, url::Origin::Create(request.security_origin), - content::DesktopMediaID::Parse(request.requested_video_device_id)); + content::DesktopMediaID::Parse(video_device.id)); devices.video_device = video_device; } else if (result_dict.Get("video", &rfh)) { auto* web_contents = content::WebContents::FromRenderFrameHost(rfh); @@ -592,7 +592,7 @@ void ElectronBrowserContext::DisplayMediaDeviceChosen( base::UTF16ToUTF8(web_contents->GetTitle())); video_device.display_media_info = DesktopMediaIDToDisplayMediaInformation( web_contents, url::Origin::Create(request.security_origin), - content::DesktopMediaID::Parse(request.requested_video_device_id)); + content::DesktopMediaID::Parse(video_device.id)); devices.video_device = video_device; } else { gin_helper::ErrorThrower(args->isolate()) diff --git a/spec/api-media-handler-spec.ts b/spec/api-media-handler-spec.ts index 95e9c4dc83..fe1334adfa 100644 --- a/spec/api-media-handler-spec.ts +++ b/spec/api-media-handler-spec.ts @@ -283,6 +283,29 @@ describe('setDisplayMediaRequestHandler', () => { expect(ok).to.be.true(message); }); + it('returns a MediaStream with BrowserCaptureMediaStreamTrack when the current tab is selected', async () => { + const ses = session.fromPartition('' + Math.random()); + let requestHandlerCalled = false; + ses.setDisplayMediaRequestHandler((request, callback) => { + requestHandlerCalled = true; + callback({ video: w.webContents.mainFrame }); + }); + const w = new BrowserWindow({ show: false, webPreferences: { session: ses } }); + await w.loadURL(serverUrl); + const { ok, message } = await w.webContents.executeJavaScript(` + navigator.mediaDevices.getDisplayMedia({ + preferCurrentTab: true, + video: true, + audio: false, + }).then(stream => { + const [videoTrack] = stream.getVideoTracks(); + return { ok: videoTrack instanceof BrowserCaptureMediaStreamTrack, message: null }; + }, e => ({ok: false, message: e.message})) + `, true); + expect(requestHandlerCalled).to.be.true(); + expect(ok).to.be.true(message); + }); + ifit(!(process.platform === 'darwin' && process.arch === 'x64'))('can supply a screen response to preferCurrentTab', async () => { const ses = session.fromPartition('' + Math.random()); let requestHandlerCalled = false;