Skip to content

Instantly share code, notes, and snippets.

@Plnda
Created September 15, 2020 12:14
Show Gist options
  • Save Plnda/7bcf629c1bb972e2ddfbe1b516b14c9c to your computer and use it in GitHub Desktop.
Save Plnda/7bcf629c1bb972e2ddfbe1b516b14c9c to your computer and use it in GitHub Desktop.
class ViewController: UIViewController {
private var webview: WKWebView!
private var controller: WebController = WebController()
override func viewDidLoad() {
super.viewDidLoad()
let configuration = WKWebViewConfiguration()
configuration.allowsInlineMediaPlayback = false
configuration.mediaTypesRequiringUserActionForPlayback = []
configuration.applicationNameForUserAgent = "Version/13.0.1 Safari/605.1.15"
configuration.userContentController.addScriptMessageHandler(controller, contentWorld: WKContentWorld.page, name: "controller")
webview = WKWebView(frame: view.bounds, configuration: configuration)
webview.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(webview)
webview.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
webview.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
webview.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
webview.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
webview.navigationDelegate = self
webview.load(URLRequest(url: URL(string: "http://accounts.google.com/")!))
//webview.load(URLRequest(url: URL(string: "https://gamepad-tester.com")!))
}
@objc private func goToStadia()
{
webview.customUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
webview.load(URLRequest(url: URL(string: "https://stadia.google.com")!))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment