forked from abrahamjuliot/creepjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creepworker.js
1461 lines (1377 loc) · 41.1 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const ask = fn => { try { return fn() } catch (e) { return } }
const createTimer = () => {
let start = 0
const log = []
return {
stop: () => {
if (start) {
log.push(performance.now() - start)
return log.reduce((acc, n) => acc += n, 0)
}
return start
},
start: () => {
start = performance.now()
return start
}
}
}
const queueEvent = timer => {
timer.stop()
return new Promise(resolve => setTimeout(() => resolve(timer.start()), 0))
.catch(e => { })
}
const getPrototypeLies = scope => {
const getEngine = () => {
const mathPI = 3.141592653589793
const compute = n => mathPI ** -100 == +`1.9275814160560${n}e-50`
return {
isChrome: compute(204),
isFirefox: compute(185),
isSafari: compute(206)
}
}
const getRandomValues = () => (
String.fromCharCode(Math.random() * 26 + 97) +
Math.random().toString(36).slice(-7)
)
const randomId = getRandomValues()
// Lie Tests
// object constructor descriptor should return undefined properties
const getUndefinedValueLie = (obj, name) => {
const objName = obj.name
const objNameUncapitalized = self[objName.charAt(0).toLowerCase() + objName.slice(1)]
const hasInvalidValue = !!objNameUncapitalized && (
typeof Object.getOwnPropertyDescriptor(objNameUncapitalized, name) != 'undefined' ||
typeof Reflect.getOwnPropertyDescriptor(objNameUncapitalized, name) != 'undefined'
)
return hasInvalidValue
}
// accessing the property from the prototype should throw a TypeError
const getIllegalTypeErrorLie = (obj, name) => {
const proto = obj.prototype
try {
proto[name]
return true
} catch (error) {
return error.constructor.name != 'TypeError' ? true : false
}
const illegal = [
'',
'is',
'call',
'seal',
'keys',
'bind',
'apply',
'assign',
'freeze',
'values',
'entries',
'toString',
'isFrozen',
'isSealed',
'constructor',
'isExtensible',
'getPrototypeOf',
'preventExtensions',
'propertyIsEnumerable',
'getOwnPropertySymbols',
'getOwnPropertyDescriptors'
]
const hasInvalidError = !!illegal.find(prop => {
try {
prop == '' ? Object(proto[name]) : Object[prop](proto[name])
return true // failed to throw
} catch (error) {
return error.constructor.name != 'TypeError'
}
})
return hasInvalidError
}
// calling the interface prototype on the function should throw a TypeError
const getCallInterfaceTypeErrorLie = (apiFunction, proto) => {
try {
new apiFunction()
apiFunction.call(proto)
return true
} catch (error) {
return error.constructor.name != 'TypeError'
}
}
// applying the interface prototype on the function should throw a TypeError
const getApplyInterfaceTypeErrorLie = (apiFunction, proto) => {
try {
new apiFunction()
apiFunction.apply(proto)
return true
} catch (error) {
return error.constructor.name != 'TypeError'
}
}
// creating a new instance of the function should throw a TypeError
const getNewInstanceTypeErrorLie = apiFunction => {
try {
new apiFunction()
return true
} catch (error) {
return error.constructor.name != 'TypeError'
}
}
// extending the function on a fake class should throw a TypeError and message "not a constructor"
const getClassExtendsTypeErrorLie = apiFunction => {
try {
const { isSafari } = getEngine()
const shouldExitInSafari13 = (
/version\/13/i.test((navigator || {}).userAgent) && isSafari
)
if (shouldExitInSafari13) {
return false
}
// begin tests
class Fake extends apiFunction { }
return true
} catch (error) {
// Native has TypeError and 'not a constructor' message in FF & Chrome
return (
error.constructor.name != 'TypeError' ||
!/not a constructor/i.test(error.message)
)
}
}
// setting prototype to null and converting to a string should throw a TypeError
const getNullConversionTypeErrorLie = apiFunction => {
const nativeProto = Object.getPrototypeOf(apiFunction)
try {
Object.setPrototypeOf(apiFunction, null) + ''
return true
} catch (error) {
return error.constructor.name != 'TypeError'
} finally {
// restore proto
Object.setPrototypeOf(apiFunction, nativeProto)
}
}
// toString() and toString.toString() should return a native string in all frames
const getToStringLie = (apiFunction, name, scope) => {
/*
Accepted strings:
'function name() { [native code] }'
'function name() {\n [native code]\n}'
'function get name() { [native code] }'
'function get name() {\n [native code]\n}'
'function () { [native code] }'
`function () {\n [native code]\n}`
*/
let scopeToString, scopeToStringToString
try {
scopeToString = scope.Function.prototype.toString.call(apiFunction)
} catch (e) { }
try {
scopeToStringToString = scope.Function.prototype.toString.call(apiFunction.toString)
} catch (e) { }
const apiFunctionToString = (
scopeToString ?
scopeToString :
apiFunction.toString()
)
const apiFunctionToStringToString = (
scopeToStringToString ?
scopeToStringToString :
apiFunction.toString.toString()
)
const trust = name => ({
[`function ${name}() { [native code] }`]: true,
[`function get ${name}() { [native code] }`]: true,
[`function () { [native code] }`]: true,
[`function ${name}() {${'\n'} [native code]${'\n'}}`]: true,
[`function get ${name}() {${'\n'} [native code]${'\n'}}`]: true,
[`function () {${'\n'} [native code]${'\n'}}`]: true
})
return (
!trust(name)[apiFunctionToString] ||
!trust('toString')[apiFunctionToStringToString]
)
}
// "prototype" in function should not exist
const getPrototypeInFunctionLie = apiFunction => 'prototype' in apiFunction
// "arguments", "caller", "prototype", "toString" should not exist in descriptor
const getDescriptorLie = apiFunction => {
const hasInvalidDescriptor = (
Object.getOwnPropertyDescriptor(apiFunction, 'arguments') ||
Reflect.getOwnPropertyDescriptor(apiFunction, 'arguments') ||
Object.getOwnPropertyDescriptor(apiFunction, 'caller') ||
Reflect.getOwnPropertyDescriptor(apiFunction, 'caller') ||
Object.getOwnPropertyDescriptor(apiFunction, 'prototype') ||
Reflect.getOwnPropertyDescriptor(apiFunction, 'prototype') ||
Object.getOwnPropertyDescriptor(apiFunction, 'toString') ||
Reflect.getOwnPropertyDescriptor(apiFunction, 'toString')
)
return hasInvalidDescriptor
}
// "arguments", "caller", "prototype", "toString" should not exist as own property
const getOwnPropertyLie = apiFunction => {
const hasInvalidOwnProperty = (
apiFunction.hasOwnProperty('arguments') ||
apiFunction.hasOwnProperty('caller') ||
apiFunction.hasOwnProperty('prototype') ||
apiFunction.hasOwnProperty('toString')
)
return hasInvalidOwnProperty
}
// descriptor keys should only contain "name" and "length"
const getDescriptorKeysLie = apiFunction => {
const descriptorKeys = Object.keys(Object.getOwnPropertyDescriptors(apiFunction))
const hasInvalidKeys = '' + descriptorKeys != 'length,name' && '' + descriptorKeys != 'name,length'
return hasInvalidKeys
}
// own property names should only contain "name" and "length"
const getOwnPropertyNamesLie = apiFunction => {
const ownPropertyNames = Object.getOwnPropertyNames(apiFunction)
const hasInvalidNames = !(
'' + ownPropertyNames == 'length,name' ||
'' + ownPropertyNames == 'name,length'
)
return hasInvalidNames
}
// own keys names should only contain "name" and "length"
const getOwnKeysLie = apiFunction => {
const ownKeys = Reflect.ownKeys(apiFunction)
const hasInvalidKeys = !(
'' + ownKeys == 'length,name' ||
'' + ownKeys == 'name,length'
)
return hasInvalidKeys
}
// calling toString() on an object created from the function should throw a TypeError
const getNewObjectToStringTypeErrorLie = apiFunction => {
try {
const you = () => Object.create(apiFunction).toString()
const cant = () => you()
const hide = () => cant()
hide()
// error must throw
return true
} catch (error) {
const stackLines = error.stack.split('\n')
const validScope = !/at Object\.apply/.test(stackLines[1])
// Stack must be valid
const validStackSize = (
error.constructor.name == 'TypeError' && stackLines.length >= 5
)
// Chromium must throw error 'at Function.toString'... and not 'at Object.apply'
const { isChrome } = getEngine()
if (validStackSize && isChrome && (
!validScope ||
!/at Function\.toString/.test(stackLines[1]) ||
!/at you/.test(stackLines[2]) ||
!/at cant/.test(stackLines[3]) ||
!/at hide/.test(stackLines[4])
)) {
return true
}
return !validStackSize
}
}
/* Proxy Detection */
// arguments or caller should not throw 'incompatible Proxy' TypeError
const tryIncompatibleProxy = fn => {
const { isFirefox } = getEngine()
try {
fn()
return true // failed to throw
} catch (error) {
return (
error.constructor.name != 'TypeError' ||
(isFirefox && /incompatible\sProxy/.test(error.message))
)
}
}
const getIncompatibleProxyTypeErrorLie = apiFunction => {
return (
tryIncompatibleProxy(() => apiFunction.arguments) ||
tryIncompatibleProxy(() => apiFunction.caller)
)
}
const getToStringIncompatibleProxyTypeErrorLie = apiFunction => {
return (
tryIncompatibleProxy(() => apiFunction.toString.arguments) ||
tryIncompatibleProxy(() => apiFunction.toString.caller)
)
}
// checking proxy instanceof proxy should throw a valid TypeError
const getInstanceofCheckLie = apiFunction => {
const proxy = new Proxy(apiFunction, {})
const { isChrome } = getEngine()
if (!isChrome) {
return false
}
const hasValidStack = (error, type = 'Function') => {
const { message, name, stack } = error
const validName = name == 'TypeError'
const validMessage = message == `Function has non-object prototype 'undefined' in instanceof check`
const targetStackLine = ((stack || '').split('\n') || [])[1]
const validStackLine = targetStackLine.startsWith(` at ${type}.[Symbol.hasInstance]`)
return validName && validMessage && validStackLine
}
try {
proxy instanceof proxy
return true // failed to throw
}
catch (error) {
// expect Proxy.[Symbol.hasInstance]
if (!hasValidStack(error, 'Proxy')) {
return true
}
try {
apiFunction instanceof apiFunction
return true // failed to throw
}
catch (error) {
// expect Function.[Symbol.hasInstance]
return !hasValidStack(error)
}
}
}
// defining properties should not throw an error
const getDefinePropertiesLie = (apiFunction) => {
const { isChrome } = getEngine()
if (!isChrome) {
return false // chrome only test
}
try {
const _apiFunction = apiFunction
Object.defineProperty(_apiFunction, '', {})+''
Object.defineProperties(_apiFunction, {})+''
return false
} catch (error) {
return true // failed at Error
}
}
// setPrototypeOf error tests
const spawnError = (apiFunction, method) => {
if (method == 'setPrototypeOf') {
return Object.setPrototypeOf(apiFunction, Object.create(apiFunction)) + ''
} else {
apiFunction.__proto__ = apiFunction
return apiFunction++
}
}
const hasValidError = error => {
const { isChrome, isFirefox } = getEngine()
const { name, message } = error
const hasRangeError = name == 'RangeError'
const hasInternalError = name == 'InternalError'
const chromeLie = isChrome && (
message != `Maximum call stack size exceeded` || !hasRangeError
)
const firefoxLie = isFirefox && (
message != `too much recursion` || !hasInternalError
)
return (hasRangeError || hasInternalError) && !(chromeLie || firefoxLie)
}
const getTooMuchRecursionLie = ({ apiFunction, method = 'setPrototypeOf' }) => {
const nativeProto = Object.getPrototypeOf(apiFunction)
const proxy = new Proxy(apiFunction, {})
try {
spawnError(proxy, method)
return true // failed to throw
} catch (error) {
return !hasValidError(error)
} finally {
Object.setPrototypeOf(proxy, nativeProto) // restore
}
}
const getChainCycleLie = ({ apiFunction, method = 'setPrototypeOf' }) => {
const nativeProto = Object.getPrototypeOf(apiFunction)
try {
spawnError(apiFunction, method)
return true // failed to throw
} catch (error) {
const { isChrome, isFirefox } = getEngine()
const { name, message, stack } = error
const targetStackLine = ((stack || '').split('\n') || [])[1]
const hasTypeError = name == 'TypeError'
const chromeLie = isChrome && (
message != `Cyclic __proto__ value` ||
(method == '__proto__' && !targetStackLine.startsWith(` at Function.set __proto__ [as __proto__]`))
)
const firefoxLie = isFirefox && (
message != `can't set prototype: it would cause a prototype chain cycle`
)
if (!hasTypeError || chromeLie || firefoxLie) {
return true // failed Error
}
} finally {
Object.setPrototypeOf(apiFunction, nativeProto) // restore
}
}
const getReflectSetProtoLie = ({ apiFunction, randomId }) => {
if (!randomId) {
randomId = getRandomValues()
}
const nativeProto = Object.getPrototypeOf(apiFunction)
try {
if (Reflect.setPrototypeOf(apiFunction, Object.create(apiFunction))) {
return true // failed value (expected false)
} else {
try {
randomId in apiFunction
return false
} catch (error) {
return true // failed at Error
}
}
} catch (error) {
return true // failed at Error
} finally {
Object.setPrototypeOf(apiFunction, nativeProto) // restore
}
}
const getReflectSetProtoProxyLie = ({ apiFunction, randomId }) => {
if (!randomId) {
randomId = getRandomValues()
}
const nativeProto = Object.getPrototypeOf(apiFunction)
const proxy = new Proxy(apiFunction, {})
try {
if (!Reflect.setPrototypeOf(proxy, Object.create(proxy))) {
return true // failed value (expected true)
} else {
try {
randomId in apiFunction
return true // failed to throw
} catch (error) {
return !hasValidError(error)
}
}
} catch (error) {
return true // failed at Error
} finally {
Object.setPrototypeOf(proxy, nativeProto) // restore
}
}
// API Function Test
const getLies = ({ apiFunction, proto, obj = null, lieProps }) => {
if (typeof apiFunction != 'function') {
return {
lied: false,
lieTypes: []
}
}
const name = apiFunction.name.replace(/get\s/, '')
let lies = {
// custom lie string names
[`failed illegal error`]: obj ? getIllegalTypeErrorLie(obj, name) : false,
[`failed undefined properties`]: obj ? getUndefinedValueLie(obj, name) : false,
[`failed call interface error`]: getCallInterfaceTypeErrorLie(apiFunction, proto),
[`failed apply interface error`]: getApplyInterfaceTypeErrorLie(apiFunction, proto),
[`failed new instance error`]: getNewInstanceTypeErrorLie(apiFunction),
[`failed class extends error`]: getClassExtendsTypeErrorLie(apiFunction),
[`failed null conversion error`]: getNullConversionTypeErrorLie(apiFunction),
[`failed toString`]: getToStringLie(apiFunction, name, scope),
[`failed "prototype" in function`]: getPrototypeInFunctionLie(apiFunction),
[`failed descriptor`]: getDescriptorLie(apiFunction),
[`failed own property`]: getOwnPropertyLie(apiFunction),
[`failed descriptor keys`]: getDescriptorKeysLie(apiFunction),
[`failed own property names`]: getOwnPropertyNamesLie(apiFunction),
[`failed own keys names`]: getOwnKeysLie(apiFunction),
[`failed object toString error`]: getNewObjectToStringTypeErrorLie(apiFunction),
// Proxy Detection
[`failed at incompatible proxy error`]: getIncompatibleProxyTypeErrorLie(apiFunction),
[`failed at toString incompatible proxy error`]: getToStringIncompatibleProxyTypeErrorLie(apiFunction),
[`failed at too much recursion error`]: getChainCycleLie({ apiFunction })
}
// conditionally use advanced detection
const detectProxies = (
name == 'toString' || !!lieProps['Function.toString']
)
if (detectProxies) {
lies = {
...lies,
// Advanced Proxy Detection
[`failed at too much recursion __proto__ error`]: getChainCycleLie({ apiFunction, method: '__proto__' }),
[`failed at chain cycle error`]: getTooMuchRecursionLie({ apiFunction }),
[`failed at chain cycle __proto__ error`]: getTooMuchRecursionLie({ apiFunction, method: '__proto__' }),
[`failed at reflect set proto`]: getReflectSetProtoLie({ apiFunction, randomId }),
[`failed at reflect set proto proxy`]: getReflectSetProtoProxyLie({ apiFunction, randomId }),
[`failed at instanceof check error`]: getInstanceofCheckLie(apiFunction),
[`failed at define properties`]: getDefinePropertiesLie(apiFunction)
}
}
const lieTypes = Object.keys(lies).filter(key => !!lies[key])
return {
lied: lieTypes.length,
lieTypes
}
}
// Lie Detector
const createLieDetector = () => {
const isSupported = obj => typeof obj != 'undefined' && !!obj
const props = {} // lie list and detail
let propsSearched = [] // list of properties searched
return {
getProps: () => props,
getPropsSearched: () => propsSearched,
searchLies: (fn, {
target = [],
ignore = []
} = {}) => {
let obj
// check if api is blocked or not supported
try {
obj = fn()
if (!isSupported(obj)) {
return
}
} catch (error) {
return
}
const interfaceObject = !!obj.prototype ? obj.prototype : obj
Object.getOwnPropertyNames(interfaceObject)
;[...new Set([
...Object.getOwnPropertyNames(interfaceObject),
...Object.keys(interfaceObject) // backup
])].sort().forEach(name => {
const skip = (
name == 'constructor' ||
(target.length && !new Set(target).has(name)) ||
(ignore.length && new Set(ignore).has(name))
)
if (skip) {
return
}
const objectNameString = /\s(.+)\]/
const apiName = `${
obj.name ? obj.name : objectNameString.test(obj) ? objectNameString.exec(obj)[1] : undefined
}.${name}`
propsSearched.push(apiName)
try {
const proto = obj.prototype ? obj.prototype : obj
let res // response from getLies
// search if function
try {
const apiFunction = proto[name] // may trigger TypeError
if (typeof apiFunction == 'function') {
res = getLies({
apiFunction: proto[name],
proto,
lieProps: props
})
if (res.lied) {
return (props[apiName] = res.lieTypes)
}
return
}
// since there is no TypeError and the typeof is not a function,
// handle invalid values and ingnore name, length, and constants
if (
name != 'name' &&
name != 'length' &&
name[0] !== name[0].toUpperCase()) {
const lie = [`failed descriptor.value undefined`]
return (
props[apiName] = lie
)
}
} catch (error) { }
// else search getter function
const getterFunction = Object.getOwnPropertyDescriptor(proto, name).get
res = getLies({
apiFunction: getterFunction,
proto,
obj,
lieProps: props
}) // send the obj for special tests
if (res.lied) {
return (props[apiName] = res.lieTypes)
}
return
} catch (error) {
console.log(error)
const lie = `failed prototype test execution`
return (
props[apiName] = [lie]
)
}
})
}
}
}
const lieDetector = createLieDetector()
const {
searchLies
} = lieDetector
// search lies: remove target to search all properties
// test Function.toString first to determine the depth of the search
searchLies(() => Function, {
target: [
'toString',
],
ignore: [
'caller',
'arguments'
]
})
// other APIs
searchLies(() => Intl.DateTimeFormat, {
target: [
'formatRange',
'formatToParts',
'resolvedOptions'
]
})
searchLies(() => FontFace, {
target: [
'family',
'load',
'status'
]
})
searchLies(() => String, {
target: [
'fromCodePoint'
]
})
searchLies(() => WorkerNavigator, {
target: [
'appVersion',
'deviceMemory',
'hardwareConcurrency',
'language',
'languages',
'platform',
'userAgent'
]
})
searchLies(() => OffscreenCanvasRenderingContext2D, {
target: [
'getImageData',
'getLineDash',
'isPointInPath',
'isPointInStroke',
'measureText',
'quadraticCurveTo',
'font'
]
})
searchLies(() => OffscreenCanvas, {
target: [
'convertToBlob',
'getContext'
]
})
searchLies(() => Intl.RelativeTimeFormat, {
target: [
'resolvedOptions'
]
})
searchLies(() => WebGLRenderingContext, {
target: [
'bufferData',
'getParameter',
'readPixels'
]
})
searchLies(() => WebGL2RenderingContext, {
target: [
'bufferData',
'getParameter',
'readPixels'
]
})
// return lies list and detail
const props = lieDetector.getProps()
const propsSearched = lieDetector.getPropsSearched()
return {
lieDetector,
lieList: Object.keys(props).sort(),
lieDetail: props,
lieCount: Object.keys(props).reduce((acc, key) => acc + props[key].length, 0),
propsSearched
}
}
const getEmojis = () => [
[128512],[9786],[129333, 8205, 9794, 65039],[9832],[9784],[9895],[8265],[8505],[127987, 65039, 8205, 9895, 65039],[129394],[9785],[9760],[129489, 8205, 129456],[129487, 8205, 9794, 65039],[9975],[129489, 8205, 129309, 8205, 129489],[9752],[9968],[9961],[9972],[9992],[9201],[9928],[9730],[9969],[9731],[9732],[9976],[9823],[9937],[9000],[9993],[9999],
[128105, 8205, 10084, 65039, 8205, 128139, 8205, 128104],
[128104, 8205, 128105, 8205, 128103, 8205, 128102],
[128104, 8205, 128105, 8205, 128102],
// android 11
[128512],
[169], [174], [8482],
[128065, 65039, 8205, 128488, 65039],
// other
[10002],[9986],[9935],[9874],[9876],[9881],[9939],[9879],[9904],[9905],[9888],[9762],[9763],[11014],[8599],[10145],[11013],[9883],[10017],[10013],[9766],[9654],[9197],[9199],[9167],[9792],[9794],[10006],[12336],[9877],[9884],[10004],[10035],[10055],[9724],[9642],[10083],[10084],[9996],[9757],[9997],[10052],[9878],[8618],[9775],[9770],[9774],[9745],[10036],[127344],[127359]
].map(emojiCode => String.fromCodePoint(...emojiCode))
const codecs = [
'audio/ogg; codecs=vorbis',
'audio/ogg; codecs=flac',
'audio/mp4; codecs="mp4a.40.2"',
'audio/mpeg; codecs="mp3"',
'video/ogg; codecs="theora"',
'video/mp4; codecs="avc1.42E01E"'
]
const getMediaConfig = (codec, video, audio) => ({
type: 'file',
video: !/^video/.test(codec) ? undefined : {
contentType: codec,
...video
},
audio: !/^audio/.test(codec) ? undefined : {
contentType: codec,
...audio
}
})
const getMediaCapabilities = async () => {
const video = {
width: 1920,
height: 1080,
bitrate: 120000,
framerate: 60
}
const audio = {
channels: 2,
bitrate: 300000,
samplerate: 5200
}
try {
const decodingInfo = codecs.map(codec => {
const config = getMediaConfig(codec, video, audio)
const info = navigator.mediaCapabilities.decodingInfo(config)
.then(support => ({
codec,
...support
}))
.catch(error => console.error(codec, error))
return info
})
const data = await Promise.all(decodingInfo).catch(error => console.error(error))
const codecsSupported = data.reduce((acc, support) => {
const { codec, supported, smooth, powerEfficient } = support || {}
if (!supported) { return acc }
return {
...acc,
[codec]: [
...(smooth ? ['smooth'] : []),
...(powerEfficient ? ['efficient'] : [])
]
}
}, {})
return codecsSupported
}
catch (error) {
return
}
}
const getPermissionState = name => {
if (!('permissions' in navigator)) {
return
}
return navigator.permissions.query({ name })
.then(res => ({ name, state: res.state }))
.catch(error => ({ name, state: 'unknown' }))
}
const getUserAgentData = async navigator => {
if (!('userAgentData' in navigator)) {
return
}
const data = await navigator.userAgentData.getHighEntropyValues(
['platform', 'platformVersion', 'architecture', 'bitness', 'model', 'uaFullVersion']
)
const { brands, mobile } = navigator.userAgentData || {}
const compressedBrands = (brands, captureVersion = false) => brands
.filter(obj => !/Not/.test(obj.brand)).map(obj => `${obj.brand}${captureVersion ? ` ${obj.version}` : ''}`)
const removeChromium = brands => (
brands.length > 1 ? brands.filter(brand => !/Chromium/.test(brand)) : brands
)
// compress brands
if (!data.brands) {
data.brands = brands
}
data.brandsVersion = compressedBrands(data.brands, true)
data.brands = compressedBrands(data.brands)
data.brandsVersion = removeChromium(data.brandsVersion)
data.brands = removeChromium(data.brands)
if (!data.mobile) {
data.mobile = mobile
}
const dataSorted = Object.keys(data).sort().reduce((acc, key) => {
acc[key] = data[key]
return acc
},{})
return dataSorted
}
const getWindowsFontMap = () => ({
// https://docs.microsoft.com/en-us/typography/fonts/windows_11_font_list
'7': [
'Cambria Math',
'Lucida Console'
],
'8': [
'Aldhabi',
'Gadugi',
'Myanmar Text',
'Nirmala UI'
],
'8.1': [
'Leelawadee UI',
'Javanese Text',
'Segoe UI Emoji'
],
'10': [
'HoloLens MDL2 Assets', // 10 (v1507) +
'Segoe MDL2 Assets', // 10 (v1507) +
'Bahnschrift', // 10 (v1709) +-
'Ink Free', // 10 (v1803) +-
],
'11': ['Segoe Fluent Icons']
})
const getMacOSFontMap = () => ({
// Mavericks and below
'10.9': [
'Helvetica Neue',
'Geneva' // mac (not iOS)
],
// Yosemite
'10.10': [
'Kohinoor Devanagari Medium',
'Luminari'
],
// El Capitan
'10.11': [
'PingFang HK Light'
],
// Sierra: https://support.apple.com/en-ie/HT206872
'10.12': [
'American Typewriter Semibold',
'Futura Bold',
'SignPainter-HouseScript Semibold'
],
// High Sierra: https://support.apple.com/en-me/HT207962
// Mojave: https://support.apple.com/en-us/HT208968
'10.13-10.14': [
'InaiMathi Bold'
],
// Catalina: https://support.apple.com/en-us/HT210192
// Big Sur: https://support.apple.com/en-sg/HT211240
'10.15-11': [
'Galvji',
'MuktaMahee Regular'
],
// Monterey: https://www.apple.com/my/macos/monterey/features/
// https://apple.stackexchange.com/questions/429548/request-for-list-of-fonts-folder-contents-on-monterey
//'12': []
})
const getDesktopAppFontMap = () => ({
// docs.microsoft.com/en-us/typography/font-list/ms-outlook
'Microsoft Outlook': ['MS Outlook'],
// https://community.adobe.com/t5/postscript-discussions/zwadobef-font/m-p/3730427#M785
'Adobe Acrobat': ['ZWAdobeF'],
// https://wiki.documentfoundation.org/Fonts
'LibreOffice': [
'Amiri',
'KACSTOffice',
'Liberation Mono',
'Source Code Pro'
],
// https://superuser.com/a/611804
'OpenOffice': [
'DejaVu Sans',
'Gentium Book Basic',
'OpenSymbol'
]
})
const getAppleFonts = () => {
const macOSFontMap = getMacOSFontMap()
return Object.keys(macOSFontMap).map(key => macOSFontMap[key]).flat()
}
const getWindowsFonts = () => {
const windowsFontMap = getWindowsFontMap()
return Object.keys(windowsFontMap).map(key => windowsFontMap[key]).flat()
}
const getDesktopAppFonts = () => {
const desktopAppFontMap = getDesktopAppFontMap()
return Object.keys(desktopAppFontMap).map(key => desktopAppFontMap[key]).flat()
}
const getLinuxFonts = () => [
'Arimo', // ubuntu, chrome os
'Chilanka', // ubuntu (not TB)
'Cousine', // ubuntu, chrome os
'Jomolhari', // chrome os
'MONO', // ubuntu, chrome os (not TB)
'Noto Color Emoji', // Linux
'Ubuntu', // ubuntu (not TB)
]
const getAndroidFonts = () => [
'Dancing Script', // android
'Droid Sans Mono', // Android
'Roboto' // Android, Chrome OS
]
const getFontList = () => [
...getAppleFonts(),
...getWindowsFonts(),
...getLinuxFonts(),
...getAndroidFonts(),
...getDesktopAppFonts()
].sort()
const getFontFaceLoadFonts = async fontList => {
// Crashes in Safari 15 (stable in Safari 15.4)
const isSafari15VersionError = (
'BigInt64Array' in self && // Safari 15
!('reportError' in self) && // Safari 15.4
(3.141592653589793 ** -100 == 1.9275814160560206e-50) && // Webkit
!/(Cr|Fx)iOS/.test(navigator.userAgent) // Safari
)
if (!self.FontFace || isSafari15VersionError) {
return
}
try {
const fontFaceList = fontList.map(font => new FontFace(font, `local("${font}")`))
const responseCollection = await Promise
.allSettled(fontFaceList.map(font => font.load()))
const fonts = responseCollection.reduce((acc, font) => {
if (font.status == 'fulfilled') {
return [...acc, font.value.family]
}
return acc
}, [])
return fonts
} catch (error) {
console.error(error)
return []
}
}
const getPlatformVersion = fonts => {