File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -629,6 +629,21 @@ logical processors available to the current Node.js instance.
629629console .log (` This process is running on ${ navigator .hardwareConcurrency } ` );
630630```
631631
632+ ### ` navigator.userAgent `
633+
634+ <!-- YAML
635+ added: REPLACEME
636+ -->
637+
638+ * {string}
639+
640+ The ` navigator.userAgent ` read-only property returns user agent
641+ consisting of the runtime name and major version number.
642+
643+ ``` js
644+ console .log (` The user-agent is ${ navigator .userAgent } ` ); // Prints "Node.js/21"
645+ ```
646+
632647## ` PerformanceEntry `
633648
634649<!-- YAML
Original file line number Diff line number Diff line change @@ -18,10 +18,12 @@ const {
1818} = internalBinding ( 'os' ) ;
1919
2020const kInitialize = Symbol ( 'kInitialize' ) ;
21+ const nodeVersion = process . version ;
2122
2223class Navigator {
2324 // Private properties are used to avoid brand validations.
2425 #availableParallelism;
26+ #userAgent = `Node.js/${ nodeVersion . slice ( 1 , nodeVersion . indexOf ( '.' ) ) } ` ;
2527
2628 constructor ( ) {
2729 if ( arguments [ 0 ] === kInitialize ) {
@@ -37,10 +39,18 @@ class Navigator {
3739 this . #availableParallelism ??= getAvailableParallelism ( ) ;
3840 return this . #availableParallelism;
3941 }
42+
43+ /**
44+ * @return {string }
45+ */
46+ get userAgent ( ) {
47+ return this . #userAgent;
48+ }
4049}
4150
4251ObjectDefineProperties ( Navigator . prototype , {
4352 hardwareConcurrency : kEnumerableProperty ,
53+ userAgent : kEnumerableProperty ,
4454} ) ;
4555
4656module . exports = {
Original file line number Diff line number Diff line change @@ -13,3 +13,5 @@ const is = {
1313is . number ( + navigator . hardwareConcurrency , 'hardwareConcurrency' ) ;
1414is . number ( navigator . hardwareConcurrency , 'hardwareConcurrency' ) ;
1515assert . ok ( navigator . hardwareConcurrency > 0 ) ;
16+ assert . strictEqual ( typeof navigator . userAgent , 'string' ) ;
17+ assert . match ( navigator . userAgent , / ^ N o d e \. j s \/ \d + $ / ) ;
You can’t perform that action at this time.
0 commit comments