Skip to content


Browse files Browse the repository at this point in the history from an iframe doesn't exit fullscreen for parent document

Reviewed by Tim Nguyen.

Currently, invoking `` from an `iframe` that has a parent document
is fullscreen does not exit fullscreen, while invoking `` from
the main frame does.

On macOS, the user is taken to a new tab, which is made visible, while the
fullscreen content remains in its own space. On iOS, the user is taken to a new
tab, but the existing content remains in fullscreen, leaving the user unaware
of what has happened.

WebKit's existing behavior in this scenario on macOS differs from both Chrome
and Firefox, which completely exit fullscreen regardless of which frame invoked
``. Additionally, the iOS behavior is confusing, as the user will
suddenly viewing another page after they decide to exit fullscreen.

To fix, ensure any successful call to `` always exits fullscreen.

* LayoutTests/fullscreen/enter-fullscreen-main-frame-window-open-iframe-expected.txt: Added.
* LayoutTests/fullscreen/enter-fullscreen-main-frame-window-open-iframe.html: Added.
* LayoutTests/fullscreen/resources/window-open-iframe.html: Added.
* LayoutTests/platform/mac-wk1/TestExpectations:

Skip test on WK1, similar to another "exit fullscreen from iframe" test.

* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp:

Call `FullscreenManager::cancelFullscreen` unconditionally, rather than checking
if the frame's document has a fullscreen element, which would be false if the
fullscreen element is in another document.

`cancelFullscreen` already accounts for the top document, and is a no-op if there
is no fullscreen element in any document.

Canonical link:
  • Loading branch information
pxlcoder committed Apr 22, 2023
1 parent 7684dab commit 0aa6c90
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
@@ -0,0 +1,8 @@
To test manually, click the "Open window" button - the page should exit fullscreen mode.

TEST(document.fullscreenElement===document.body) OK
TEST(document.fullscreenElement===null) OK

@@ -0,0 +1,20 @@
<p>To test manually, click the "Open window" button - the page should exit fullscreen mode.</p>
<script src="full-screen-test.js"></script>
function runTest() {
waitForEventOnce(document, 'fullscreenchange', function() {
waitForEventOnce(document, 'fullscreenchange', function() {

runWithKeyDown(function() {
<iframe id="frame" src="resources/window-open-iframe.html" width="300" height="100" onload="runTest()">
11 changes: 11 additions & 0 deletions LayoutTests/fullscreen/resources/window-open-iframe.html
@@ -0,0 +1,11 @@
window.exitFullscreen = function(args) {
if (!window.internals)

internals.withUserGesture(function() {'about:blank');
<button onclick="'about:blank')">Open window</button>
2 changes: 2 additions & 0 deletions LayoutTests/platform/mac-wk1/TestExpectations
Expand Up @@ -1002,6 +1002,8 @@ media/auto-play-in-sandbox-with-allow-scripts.html [ Pass Ti fullscreen/exit-full-screen-iframe.html [ Skip ] fullscreen/enter-fullscreen-main-frame-window-open-iframe.html [ Skip ] editing/spelling/grammar-edit-word.html [ Skip ] compositing/scrolling/touch-scroll-to-clip.html [ Pass Failure ]
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
Expand Up @@ -309,8 +309,8 @@ OptionSet<WebEventModifier> modifiersForNavigationAction(const NavigationAction&
Page* WebChromeClient::createWindow(LocalFrame& frame, const WindowFeatures& windowFeatures, const NavigationAction& navigationAction)
if (frame.document() && frame.document()->fullscreenManager().currentFullscreenElement())
if (auto* document = frame.document())

auto& webProcess = WebProcess::singleton();
Expand Down

0 comments on commit 0aa6c90

Please sign in to comment.