Skip to content

Instantly share code, notes, and snippets.

@BoogieMonster1O1
Created April 29, 2020 03:28
Show Gist options
  • Save BoogieMonster1O1/6a38db34897ca463b2855d20444345c7 to your computer and use it in GitHub Desktop.
Save BoogieMonster1O1/6a38db34897ca463b2855d20444345c7 to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// Test0
//
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate, UIWebViewDelegate {
var webView: WKWebView!
override func loadView() {
let preferences = WKPreferences()
preferences.javaScriptEnabled = true
preferences.javaScriptCanOpenWindowsAutomatically = true
let webConfiguration = WKWebViewConfiguration()
webConfiguration.preferences = preferences
webView = WKWebView(frame: .zero, configuration: webConfiguration)
let userAgentValue = "random-user-agent-value"
webView.customUserAgent = userAgentValue
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string: "https://www.papertoys.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
webView.navigationDelegate = self
}
override func viewWillDisappear(_ animated: Bool) {
let dataStore = WKWebsiteDataStore.default()
dataStore.httpCookieStore.getAllCookies({ (cookies) in
print(cookies)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment