I have an application that needs to check whether the client browser has third-party-cookies enabled. Does anyone know how to do this in JavaScript?
Third Party Cookie detection with Whitelisting of URLs
Alan H & Gojko Adzic are good enough for majority of use cases, but these solutions won't work if you want your users to do whitelisting of third party cookies only to certain domains.
I'm presenting a slightly modified version of Gojko Adzic's answer
For this we need two domains :
tpc=pending, then it redirects to Domain 2tpc=true and redirects back to Domain 1tpc and checks if its true, if we get value as true, third party cookies are allowed if it is still in pending third party cookies are blocked blocked.Now, you might ask your users to whitelist (allow third party cookies) ONLY for Domain 1, also by this technique third party detection will be accurate if the users had white listed your domain.
This is tested in Chrome 74, 75, 76 & Edge 78
Unfortunately, Mozilla doesn't provide whitelisting of urls like Chrome does and Safari has it own mechanisms of detecting third party cookies (ITP).
P.S. Will upload this demo in my github when I get time.