Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling cookies in WKWebView

Is it possible at all to disable cookies and local storage in a WKWebView?

Let's say that this is my setup, and I want to add something that disables them:

import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {

    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let myURL = URL(string: "http://bla.com")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }


}
like image 314
Luoruize Avatar asked Feb 02 '26 03:02

Luoruize


1 Answers

To disable cookies:

override func viewDidLoad() {
    super.viewDidLoad()
    let myURL = URL(string: "http://bla.com")
    var myRequest = URLRequest(url: myURL!)
    myRequest.httpShouldHandleCookies = false
    webView.load(myRequest)
}
like image 198
Santhosh R Avatar answered Feb 03 '26 20:02

Santhosh R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!