From 7f916a62b83c2ccd6078dcc680865f8b0a7f8b76 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 24 Apr 2024 22:43:21 -0400 Subject: [PATCH] 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 c780d107ae65a..bb09e53515113 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 8defed7cf3d03..cbe310b9e9d6c 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();