Skip to content

Commit c52d8fb

Browse files
authored
Fix platform detection after Node.js 21 (microsoft#200935)
Node.js 21 added `navigator.userAgent`, which breaks the previous detection.
1 parent 9525bc1 commit c52d8fb

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/vs/base/common/platform.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,8 @@ interface INavigator {
7575
}
7676
declare const navigator: INavigator;
7777

78-
// Web environment
79-
if (typeof navigator === 'object' && !isElectronRenderer) {
80-
_userAgent = navigator.userAgent;
81-
_isWindows = _userAgent.indexOf('Windows') >= 0;
82-
_isMacintosh = _userAgent.indexOf('Macintosh') >= 0;
83-
_isIOS = (_userAgent.indexOf('Macintosh') >= 0 || _userAgent.indexOf('iPad') >= 0 || _userAgent.indexOf('iPhone') >= 0) && !!navigator.maxTouchPoints && navigator.maxTouchPoints > 0;
84-
_isLinux = _userAgent.indexOf('Linux') >= 0;
85-
_isMobile = _userAgent?.indexOf('Mobi') >= 0;
86-
_isWeb = true;
87-
88-
const configuredLocale = nls.getConfiguredDefaultLocale(
89-
// This call _must_ be done in the file that calls `nls.getConfiguredDefaultLocale`
90-
// to ensure that the NLS AMD Loader plugin has been loaded and configured.
91-
// This is because the loader plugin decides what the default locale is based on
92-
// how it's able to resolve the strings.
93-
nls.localize({ key: 'ensureLoaderPluginIsLoaded', comment: ['{Locked}'] }, '_')
94-
);
95-
96-
_locale = configuredLocale || LANGUAGE_DEFAULT;
97-
_language = _locale;
98-
_platformLocale = navigator.language;
99-
}
100-
10178
// Native environment
102-
else if (typeof nodeProcess === 'object') {
79+
if (typeof nodeProcess === 'object') {
10380
_isWindows = (nodeProcess.platform === 'win32');
10481
_isMacintosh = (nodeProcess.platform === 'darwin');
10582
_isLinux = (nodeProcess.platform === 'linux');
@@ -124,6 +101,29 @@ else if (typeof nodeProcess === 'object') {
124101
_isNative = true;
125102
}
126103

104+
// Web environment
105+
else if (typeof navigator === 'object' && !isElectronRenderer) {
106+
_userAgent = navigator.userAgent;
107+
_isWindows = _userAgent.indexOf('Windows') >= 0;
108+
_isMacintosh = _userAgent.indexOf('Macintosh') >= 0;
109+
_isIOS = (_userAgent.indexOf('Macintosh') >= 0 || _userAgent.indexOf('iPad') >= 0 || _userAgent.indexOf('iPhone') >= 0) && !!navigator.maxTouchPoints && navigator.maxTouchPoints > 0;
110+
_isLinux = _userAgent.indexOf('Linux') >= 0;
111+
_isMobile = _userAgent?.indexOf('Mobi') >= 0;
112+
_isWeb = true;
113+
114+
const configuredLocale = nls.getConfiguredDefaultLocale(
115+
// This call _must_ be done in the file that calls `nls.getConfiguredDefaultLocale`
116+
// to ensure that the NLS AMD Loader plugin has been loaded and configured.
117+
// This is because the loader plugin decides what the default locale is based on
118+
// how it's able to resolve the strings.
119+
nls.localize({ key: 'ensureLoaderPluginIsLoaded', comment: ['{Locked}'] }, '_')
120+
);
121+
122+
_locale = configuredLocale || LANGUAGE_DEFAULT;
123+
_language = _locale;
124+
_platformLocale = navigator.language;
125+
}
126+
127127
// Unknown environment
128128
else {
129129
console.error('Unable to resolve platform.');

0 commit comments

Comments
 (0)