diff options
Diffstat (limited to 'lib/internal')
| -rw-r--r-- | lib/internal/bootstrap/node.js | 9 | ||||
| -rw-r--r-- | lib/internal/navigator.js | 36 |
2 files changed, 45 insertions, 0 deletions
diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 41a833885f..e25e0405c7 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -224,6 +224,15 @@ defineLazyProperties( ['structuredClone'], ); +// https://html.spec.whatwg.org/multipage/system-state.html#the-navigator-object +ObjectDefineProperty(globalThis, 'navigator', { + __proto__: null, + enumerable: true, + configurable: true, + writable: false, + value: require('internal/navigator'), +}); + // Set the per-Environment callback that will be called // when the TrackingTraceStateObserver updates trace state. // Note that when NODE_USE_V8_PLATFORM is true, the observer is diff --git a/lib/internal/navigator.js b/lib/internal/navigator.js new file mode 100644 index 0000000000..7bf0779b90 --- /dev/null +++ b/lib/internal/navigator.js @@ -0,0 +1,36 @@ +'use strict'; + +const { + ObjectDefineProperties, +} = primordials; + +const { + kEnumerableProperty, +} = require('internal/util'); + +const { + getOSInformation, +} = internalBinding('os'); + +class Navigator { + /** + * Chromium: https://github.com/chromium/chromium/blob/main/ui/webui/resources/js/platform.ts + * @return {string} + */ + get platform() { + switch (process.platform) { + case 'win32': return 'Win32'; + case 'android': return 'Android'; + case 'darwin': + // It should return MacIntel for both M1 and Intel mac devices. + return 'MacIntel'; + default: return getOSInformation()[0]; + } + } +} + +ObjectDefineProperties(Navigator.prototype, { + platform: kEnumerableProperty, +}); + +module.exports = new Navigator(); |
