From f5fb44eaf81a7f632b920acb4735d4f31d366d3d Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 29 Apr 2024 19:09:29 -0400 Subject: [PATCH] fix: `requestFullscreen` from `WebContentsView` (#41966) fix: requestFullscreen from WebContentsView --- shell/browser/api/electron_api_web_contents_view.cc | 3 +++ spec/api-web-contents-view-spec.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/shell/browser/api/electron_api_web_contents_view.cc b/shell/browser/api/electron_api_web_contents_view.cc index c780d107ae..bb09e53515 100644 --- a/shell/browser/api/electron_api_web_contents_view.cc +++ b/shell/browser/api/electron_api_web_contents_view.cc @@ -89,6 +89,9 @@ void WebContentsView::OnViewAddedToWidget(views::View* observed_view) { widget->GetNativeWindowProperty(electron::kElectronNativeWindowKey)); if (!native_window) return; + // We don't need to call SetOwnerWindow(nullptr) in OnViewRemovedFromWidget + // because that's handled in the WebContents dtor called prior. + api_web_contents_->SetOwnerWindow(native_window); native_window->AddDraggableRegionProvider(this); } diff --git a/spec/api-web-contents-view-spec.ts b/spec/api-web-contents-view-spec.ts index 8defed7cf3..cbe310b9e9 100644 --- a/spec/api-web-contents-view-spec.ts +++ b/spec/api-web-contents-view-spec.ts @@ -60,6 +60,18 @@ describe('WebContentsView', () => { }); }); + it('can be fullscreened', async () => { + const w = new BaseWindow(); + const v = new WebContentsView(); + w.setContentView(v); + await v.webContents.loadURL('data:text/html,
This is a simple div.
'); + + const enterFullScreen = once(w, 'enter-full-screen'); + await v.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true); + await enterFullScreen; + expect(w.isFullScreen()).to.be.true('isFullScreen'); + }); + describe('visibilityState', () => { it('is initially hidden', async () => { const v = new WebContentsView();