WKWebView Mac Browser Enable fullscreen html5?

I made a simple browser with the latest Swift and xcode 8.3.3. I want to be able to enter full screen when there is an html5 video (like on YouTube). Now I am getting "full screen not available" on youtube. Same problem with old WebView ... on iOS this works.

EDIT. Maybe it just isn't possible. I tried to take a look at JavaFX WebView and WPF WebBrowser and they have the same limitations. Actually one guy was able to allow full screen for YouTube videos on WPF WebBrowser, but only by creating a full html page: Play youtube in full screen in WebBrowser control

And of course, I cannot create a webpage for every video on the page (at least I don't know how, if you know, tell me).


ORIGINAL MESSAGE: I made a simple browser with latest Swift and xcode 8.3.3. Everything works, but I cannot activate the plugins, how can I do with the old WebView. Since I am on a mac I should be able to activate plugins (I understand this is not possible on iOS), am I wrong?

Also (and here I have the same problem in the old WebView) there is no way to activate full screen mode for html5 video (at least I don't know how).

@IBOutlet weak var webView: WKWebView!
let urlString = "http://myurl.com/"
self.webView.load(NSURLRequest(url: NSURL(string: urlString)! as URL) as URLRequest!)
self.webView.configuration.preferences.plugInsEnabled = true

      

This is really basic code to work with a basic browser. But there is no way to enable the plugin in Interface Builder for WKWebView and I really don't know how to enable full screen view of html5 videos (like youtube).

EDIT. Ok I finally found the answer for the plugin part: self.webView.configuration.preferences.plugInsEnabled = true

very easy, but it was hard to figure out where to find it, I needed to go here: https://developer.apple.com/documentation/webkit/webpreferences and guess ...

+4


source to share


2 answers


The answer is there is no answer. There is no API right now on Mac to get fullscreen html5. I tried to do the same application in windows and the current WebView UWP will be able to run in full screen mode (the old WebBrowser from WPF cannot run in full screen mode).



I think this is the only way to get this to send apple feedback.

0


source


To allow WKWebView

fullscreen HTML you need to access the private API (see https://github.com/WebKit/webkit/blob/master/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm#L232-L240 ) in WKPreferences

. Since you are using Swift in your connecting header add:

#import <WebKit/WebKit.h>

@interface WKPreferences ()
-(void)_setFullScreenEnabled:(BOOL)fullScreenEnabled;
@end


      

And just call it:

let webView = WKWebView(frame: view.frame)
webView.configuration.preferences._setFullScreenEnabled(true)

      



If you noticed a strange resizing of the webview after exiting full screen mode, I found that this solves the problem for me:

webView.autoresizingMask = [.width, .height]
view.addSubview(webView)

webView.translatesAutoresizingMaskIntoConstraints = false
webView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
webView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true

      

Note. Since you have access to the private API, it will be rejected in the Mac App Store.

0


source







All Articles