Created
September 15, 2020 12:12
-
-
Save Plnda/bd731104983cae8b41b1c9388439844d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import WebKit | |
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")!)) | |
} | |
} | |
extension ViewController: WKNavigationDelegate { | |
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
if webview.url?.absoluteString == "https://stadia.google.com/home" | |
{ | |
controller.setup(webview: webview) | |
} | |
} | |
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { | |
if let url = navigationAction.request.url?.absoluteString | |
{ | |
if url == "https://myaccount.google.com/" | |
{ | |
decisionHandler(.cancel) | |
goToStadia() | |
return | |
} | |
} | |
decisionHandler(.allow) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment