Won ixer
Won ixer

Reputation: 21

"Your browser doesn't support full screen" - WKWebview, macOS

I am currently developing a cocoa web browser application like google chrome. I was testing it until I came across the problem that the wkwebview doesn't support full screen on videos. When I open a video, I get this message...

enter image description here

I thought I had to make the wkwebview a subview of the view, using this code

view.addSubview(webView)

I tried it and it still show the image above.

Can you please assist me on supporting full screen.

Upvotes: 1

Views: 1663

Answers (3)

Alex Titarenko
Alex Titarenko

Reputation: 595

let config = WKWebViewConfiguration()
if #available(macOS 12.3, *) {
    config.preferences.isElementFullscreenEnabled = true
}

let webView = WKWebView(frame: .zero, configuration: config)

Upvotes: 3

s137
s137

Reputation: 41

You should be able to just put the following in the Swift-File where the WebView is created:

webView.configuration.preferences.setValue(true, forKey: "fullScreenEnabled")

Upvotes: 0

Karamat Ali Jeelani
Karamat Ali Jeelani

Reputation: 41

Open your project. Right click on prject app grade folder from sidebar and click new file. in choose a template click objective-C file. name it for example WKPreferences and enter. Now next window press create. On next create Bridging-Header. Now you can see two new files in your sidebar. Paste following code in WKPreferences.m

#import <Foundation/Foundation.h>

Paste following code in Bridge-Bridging-Header.h

#import <WebKit/WebKit.h>

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

Now Paste following code in viewcontroller.swift

webView.configuration.preferences._setFullScreenEnabled(true)

Thats it.

Upvotes: 3

Related Questions