fingerprintjs
29 строк · 1.4 Кб
1/**
2* navigator.cookieEnabled cannot detect custom or nuanced cookie blocking configurations. For example, when blocking
3* cookies via the Advanced Privacy Settings in IE9, it always returns true. And there have been issues in the past with
4* site-specific exceptions. Don't rely on it.
5*
6* @see https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cookies.js Taken from here
7*/
8export default function areCookiesEnabled(): boolean {
9const d = document
10
11// Taken from here: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cookies.js
12// navigator.cookieEnabled cannot detect custom or nuanced cookie blocking configurations. For example, when blocking
13// cookies via the Advanced Privacy Settings in IE9, it always returns true. And there have been issues in the past
14// with site-specific exceptions. Don't rely on it.
15
16// try..catch because some in situations `document.cookie` is exposed but throws a
17// SecurityError if you try to access it; e.g. documents created from data URIs
18// or in sandboxed iframes (depending on flags/context)
19try {
20// Create cookie
21d.cookie = 'cookietest=1; SameSite=Strict;'
22const result = d.cookie.indexOf('cookietest=') !== -1
23// Delete cookie
24d.cookie = 'cookietest=1; SameSite=Strict; expires=Thu, 01-Jan-1970 00:00:01 GMT'
25return result
26} catch (e) {
27return false
28}
29}
30