Starting on iOS 15.4
and macOS 12.3
WKPreferences
has the new property isElementFullscreenEnabled, part of WKWebViewConfiguration
, which enables JavaScript to make elements full-screen in a WKWebView
, but it comes with some caveats.
macOS
On macOS is simple; set it true
to play videos on full-screen and make any other HTML element full-screen via JavaScript.
myWebView.configuration.preferences.isElementFullscreenEnabled = true
iOS
On iOS, though, setting `isElementFullscreenEnabled = true
` disables screen rotation while playing videos on full-screen for apps that only support Portrait Orientation.
This is important if you have an app that only supports portrait orientation but wants screen rotation when playing a video on full-screen (going back to portrait when the video finishes).
With isElementFullscreenEnabled = false
, you can still play videos on full-screen (at least on YouTube), and rotate videos, but disables making other HTML elements full-screen.