I have been trying to set a cookie for WKWebView using Swift 3 in order to pass a device token to a server.
The code I've been trying to get working in order to set the cookie is as follows:
wkWebView.evaluateJavaScript("document.cookie='access_token=your token';domain='your domain';") { (data, error) -> Void in
print("data: \(data)")
print("error2: \(error)")
wkWebView.reload()
}
However, I'm stuck here because this code produces the following error output:
error2: Optional(Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=0, WKJavaScriptExceptionMessage=SecurityError (DOM Exception 18): The operation is insecure., WKJavaScriptExceptionSourceURL=undefined, NSLocalizedDescription=A JavaScript exception occurred, WKJavaScriptExceptionColumnNumber=0})