WKWebView on Mac Catalyst elementFullscreenEnabled set to YES on WKPreferences but it does not work

Setting elementFullscreenEnabled property to YES on WKPreferences is not honored on Mac Catalyst.

 WKWebViewConfiguration *webViewConfig = [[WKWebViewConfiguration alloc]init];
 WKPreferences *prefs = [[WKPreferences alloc]init];
 prefs.elementFullscreenEnabled = YES;
  webViewConfig.preferences = prefs;

//then create the WKWebView..

I load a Youtube url in the WKWebView. Youtube complains that the browser doesn't support full screen. Is there a workaround?

Full screen does work in an AppKit app though using the exact same API...though it causes an Autolayout crash (I will be making another thread about that separate issue shortly).

I filed FB12008627

If anyone has a workaround for this that they are willing to share I'd appreciate it.

Looks like this is still broken in Sonoma.

After looking into this a bit more it seems to be a Mac Catalyst issue. The HTML full screen API doesn't appear to be supported at all. If you load a page with Javascript that calls requestFullscreen on an element you will instead get a Javascript exception. You can confirm this with this simple little bit of javascript:

// Function to open fullscreen mode. Attached to a button's onclick event.
function openFullscreen() 
{
   //The elem is a <video> element.
   var elem = document.getElementById('myvidid');    

  if (elem.requestFullscreen)
  {
      console.log('Calling requestFullscreen');
     elem.requestFullscreen();
  }
  else if (elem.webkitRequestFullscreen)
  {
      console.log('Calling webkitRequestFullscreen');
    elem.webkitRequestFullscreen();
  } 
  else if (elem.msRequestFullscreen)
  {
      console.log('Calling msRequestFullscreen');
      elem.msRequestFullscreen();
  }
  else
  {
      console.log('Calling nothing. Must be Mac Catalyst.');
  }
}

If I run it on iPad the following logs out:

Calling requestFullscreen

If I run it on Mac Catalyst (Optimized for Mac) the following logs out:

Calling nothing. Must be Mac Catalyst.

If I create an AppKit target and run it works.

--

So full screen elements is just stripped out of Mac Catalyst. Doesn't matter if you set elementFullscreenEnabled on WKPreferences to YES. Hopefully it's a bug and not "intentional behavior" to make Catalyst apps less capable.

I have also discovered this issue, and thank you very much for your research

RequestFullscreen is invalid, webkitEnterFullscreen is valid

https://developer.apple.com/documentation/webkitjs/htmlvideoelement/1633500-webkitenterfullscreen

Although it is not truly full screen, at least it occupies the entire application

WKWebView on Mac Catalyst elementFullscreenEnabled set to YES on WKPreferences but it does not work
 
 
Q