1
1
'use strict' ;
2
2
3
3
const {
4
+ StringPrototypeToUpperCase,
5
+ StringPrototypeSlice,
4
6
ObjectDefineProperties,
5
7
Symbol,
6
8
} = primordials ;
@@ -24,6 +26,7 @@ class Navigator {
24
26
// Private properties are used to avoid brand validations.
25
27
#availableParallelism;
26
28
#userAgent = `Node.js/${ nodeVersion . slice ( 1 , nodeVersion . indexOf ( '.' ) ) } ` ;
29
+ #platform;
27
30
28
31
constructor ( ) {
29
32
if ( arguments [ 0 ] === kInitialize ) {
@@ -46,11 +49,41 @@ class Navigator {
46
49
get userAgent ( ) {
47
50
return this . #userAgent;
48
51
}
52
+
53
+ /**
54
+ * @return {string }
55
+ */
56
+ get platform ( ) {
57
+ if ( this . #platform === undefined ) {
58
+ this . #platform = process . platform ;
59
+ if ( process . platform === 'darwin' ) {
60
+ // On macOS, modern browsers return 'MacIntel'even if running on Apple Silicon.
61
+ this . #platform = 'MacIntel' ;
62
+ } else if ( process . platform === 'win32' ) {
63
+ // On Windows, modern browsers return "Win32" even if running on a 64-bit version of Windows.
64
+ // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform#usage_notes
65
+ this . #platform = 'Win32' ;
66
+ } else if ( process . platform === 'linux' ) {
67
+ if ( this . arch === 'ia32' ) {
68
+ this . #platform = 'Linux i686' ;
69
+ } else if ( process . arch === 'x64' ) {
70
+ this . #platform = 'Linux x86_64' ;
71
+ } else {
72
+ this . #platform = `Linux ${ process . arch } ` ;
73
+ }
74
+ } else {
75
+ // For cases like freebsd, openbsd, sunos, aix etc.
76
+ this . #platform = `${ StringPrototypeToUpperCase ( process . platform [ 0 ] ) } ${ StringPrototypeSlice ( process . platform , 1 ) } ${ process . arch } ` ;
77
+ }
78
+ }
79
+ return this . #platform;
80
+ }
49
81
}
50
82
51
83
ObjectDefineProperties ( Navigator . prototype , {
52
84
hardwareConcurrency : kEnumerableProperty ,
53
85
userAgent : kEnumerableProperty ,
86
+ platform : kEnumerableProperty ,
54
87
} ) ;
55
88
56
89
module . exports = {
0 commit comments