11'use strict' ;
22
33const {
4+ StringPrototypeToUpperCase,
5+ StringPrototypeSlice,
46 ObjectDefineProperties,
57 Symbol,
68} = primordials ;
@@ -24,6 +26,7 @@ class Navigator {
2426 // Private properties are used to avoid brand validations.
2527 #availableParallelism;
2628 #userAgent = `Node.js/${ nodeVersion . slice ( 1 , nodeVersion . indexOf ( '.' ) ) } ` ;
29+ #platform;
2730
2831 constructor ( ) {
2932 if ( arguments [ 0 ] === kInitialize ) {
@@ -46,11 +49,40 @@ class Navigator {
4649 get userAgent ( ) {
4750 return this . #userAgent;
4851 }
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+ // freebsd, openbsd, sunos, aix etc.
76+ this . #platform = `${ StringPrototypeToUpperCase ( process . platform [ 0 ] ) } ${ StringPrototypeSlice ( process . platform , 1 ) } ${ process . arch } ` ;
77+ }
78+ }
79+ }
4980}
5081
5182ObjectDefineProperties ( Navigator . prototype , {
5283 hardwareConcurrency : kEnumerableProperty ,
5384 userAgent : kEnumerableProperty ,
85+ platform : kEnumerableProperty ,
5486} ) ;
5587
5688module . exports = {
0 commit comments