Commit 5a52c51 1 parent a362c27 commit 5a52c51 Copy full SHA for 5a52c51
File tree 3 files changed +27
-0
lines changed
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.
629
629
console .log (` This process is running on ${ navigator .hardwareConcurrency } ` );
630
630
```
631
631
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
+
632
647
## ` PerformanceEntry `
633
648
634
649
<!-- YAML
Original file line number Diff line number Diff line change @@ -18,10 +18,12 @@ const {
18
18
} = internalBinding ( 'os' ) ;
19
19
20
20
const kInitialize = Symbol ( 'kInitialize' ) ;
21
+ const nodeVersion = process . version ;
21
22
22
23
class Navigator {
23
24
// Private properties are used to avoid brand validations.
24
25
#availableParallelism;
26
+ #userAgent = `Node.js/${ nodeVersion . slice ( 1 , nodeVersion . indexOf ( '.' ) ) } ` ;
25
27
26
28
constructor ( ) {
27
29
if ( arguments [ 0 ] === kInitialize ) {
@@ -37,10 +39,18 @@ class Navigator {
37
39
this . #availableParallelism ??= getAvailableParallelism ( ) ;
38
40
return this . #availableParallelism;
39
41
}
42
+
43
+ /**
44
+ * @return {string }
45
+ */
46
+ get userAgent ( ) {
47
+ return this . #userAgent;
48
+ }
40
49
}
41
50
42
51
ObjectDefineProperties ( Navigator . prototype , {
43
52
hardwareConcurrency : kEnumerableProperty ,
53
+ userAgent : kEnumerableProperty ,
44
54
} ) ;
45
55
46
56
module . exports = {
Original file line number Diff line number Diff line change @@ -13,3 +13,5 @@ const is = {
13
13
is . number ( + navigator . hardwareConcurrency , 'hardwareConcurrency' ) ;
14
14
is . number ( navigator . hardwareConcurrency , 'hardwareConcurrency' ) ;
15
15
assert . 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