Last active
January 28, 2022 12:31
-
-
Save yagopv/4f38157dd8f062d459316f7ed74c6f3a to your computer and use it in GitHub Desktop.
third-party-cookies-test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Third Party Cookies Test</title> | |
</head> | |
<body> | |
<script> | |
const checkCookiesEnable = () => { | |
let isCookieEnabled = window.navigator.cookieEnabled ? true : false | |
if (typeof window.navigator.cookieEnabled == 'undefined' && !isCookieEnabled) { | |
document.cookie = 'testcookie' | |
isCookieEnabled = document.cookie.indexOf('testcookie') != -1 ? true : false | |
} | |
try { | |
localStorage.getItem('test') | |
} catch { | |
isCookieEnabled = false | |
} | |
return isCookieEnabled | |
} | |
;(function () { | |
window.addEventListener('message', (event) => { | |
try { | |
let data = event.data | |
if (data.test !== 'cookie') return | |
let result = checkCookiesEnable() | |
parent.postMessage( | |
JSON.stringify({ | |
result: result, | |
}), | |
event.origin, | |
) | |
} catch (e) { | |
console.error(e) | |
} | |
}) | |
})() | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment