B4J Code Snippet [Server][WebSockets][ABMaterial] Check if browser has cookies enabled

You can check if browser has cookies enabled using this code based on the navigator object:
B4X:
Dim cookieCheck As Future = ws.EvalWithResult("return navigator.cookieEnabled;", Null)
Log(cookieCheck.Value)

If you don't want to rely on the navigator object (ie browser sometimes returns true even if cookies are disabled) then you can use this:
B4X:
Dim jsScript As String = $"var hasCookies = ("cookie" in document && (document.cookie.length > 0 || (document.cookie = "testCookie").indexOf.call(document.cookie, "testCookie") > -1)); return hasCookies;"$
Dim cookieCheck As Future = ws.EvalWithResult(jsScript, Null)
Log(cookieCheck.Value)
 
Top