forked from abrahamjuliot/creepjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creepworker.js
101 lines (94 loc) · 3.06 KB
/
creepworker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const getWorkerData = async () => {
let canvas2d = undefined
try {
const canvasOffscreen2d = new OffscreenCanvas(500, 200)
const context2d = canvasOffscreen2d.getContext('2d')
const str = '!😃🙌🧠👩💻👟👧🏻👩🏻🦱👩🏻🦰👱🏻♀️👩🏻🦳👧🏼👧🏽👧🏾👧🏿🦄🐉🌊🍧🏄♀️🌠🔮♞'
context2d.font = '14px Arial'
context2d.fillText(str, 0, 50)
context2d.fillStyle = 'rgba(100, 200, 99, 0.78)'
context2d.fillRect(100, 30, 80, 50)
const getDataURI = async () => {
const blob = await canvasOffscreen2d.convertToBlob()
const reader = new FileReader()
reader.readAsDataURL(blob)
return new Promise(resolve => {
reader.onloadend = () => resolve(reader.result)
})
}
canvas2d = await getDataURI()
}
catch (error) { }
let webglVendor
let webglRenderer
try {
const canvasOffscreenWebgl = new OffscreenCanvas(256, 256)
const contextWebgl = canvasOffscreenWebgl.getContext('webgl')
const renererInfo = contextWebgl.getExtension('WEBGL_debug_renderer_info')
webglVendor = contextWebgl.getParameter(renererInfo.UNMASKED_VENDOR_WEBGL)
webglRenderer = contextWebgl.getParameter(renererInfo.UNMASKED_RENDERER_WEBGL)
}
catch (error) { }
const computeTimezoneOffset = () => {
const date = new Date().getDate()
const month = new Date().getMonth()
const year = Date().split` `[3] // current year
const format = n => (''+n).length == 1 ? `0${n}` : n
const dateString = `${month+1}/${format(date)}/${year}`
const dateStringUTC = `${year}-${format(month+1)}-${format(date)}`
const utc = Date.parse(
new Date(dateString)
)
const now = +new Date(dateStringUTC)
return +(((utc - now)/60000).toFixed(0))
}
const timezoneOffset = computeTimezoneOffset()
const timezoneLocation = Intl.DateTimeFormat().resolvedOptions().timeZone
const { hardwareConcurrency, language, platform, userAgent, deviceMemory } = navigator
return {
timezoneOffset,
timezoneLocation,
deviceMemory,
hardwareConcurrency,
language,
platform,
userAgent,
canvas2d,
webglRenderer,
webglVendor
}
}
// Tests
const isWorker = !globalThis.document && !!globalThis.WorkerGlobalScope
const isSharedWorker = !!globalThis.SharedWorkerGlobalScope
const isServiceWorker = !!globalThis.ServiceWorkerGlobalScope
// WorkerGlobalScope
const getWorkerGlobalScope = async () => {
const data = await getWorkerData()
postMessage(data)
close()
}
// SharedWorkerGlobalScope
const getSharedWorkerGlobalScope = () => {
onconnect = async message => {
const port = message.ports[0]
const data = await getWorkerData()
port.postMessage(data)
}
}
// ServiceWorkerGlobalScope
const getServiceWorkerGlobalScope = () => {
const broadcast = new BroadcastChannel('creep_service_primary')
broadcast.onmessage = async event => {
if (event.data && event.data.type == 'fingerprint') {
const data = await getWorkerData()
broadcast.postMessage(data)
}
}
}
// WorkerGlobalScope
if (isWorker) {
isServiceWorker ? getServiceWorkerGlobalScope() :
isSharedWorker ? getSharedWorkerGlobalScope() :
getWorkerGlobalScope()
}