mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Patch out unsafe usage of navigator and window in node envs
This commit is contained in:
+1
-5
@@ -173,11 +173,7 @@ if (config.addon) {
|
||||
outConfig = {
|
||||
...outConfig,
|
||||
entryPoints: [
|
||||
`src/browser/public/Terminal.ts`,
|
||||
`src/headless/public/Terminal.ts`,
|
||||
`src/browser/**/*.test.ts`,
|
||||
`src/common/**/*.test.ts`,
|
||||
`src/headless/**/*.test.ts`
|
||||
`src/**/*.ts`
|
||||
],
|
||||
outdir: 'out-esbuild/'
|
||||
};
|
||||
|
||||
@@ -29,6 +29,7 @@ describe('Terminal', () => {
|
||||
term = new TestTerminal(termOptions);
|
||||
term.refresh = () => { };
|
||||
(term as any).renderer = new MockRenderer();
|
||||
(term as any).viewport = new MockViewport();
|
||||
(term as any)._compositionHelper = new MockCompositionHelper();
|
||||
(term as any).element = {
|
||||
classList: {
|
||||
|
||||
@@ -98,7 +98,7 @@ export function isFullscreen(targetWindow: Window): boolean {
|
||||
}
|
||||
export const onDidChangeFullscreen = WindowManager.INSTANCE.onDidChangeFullscreen;
|
||||
|
||||
const userAgent = navigator.userAgent;
|
||||
const userAgent = typeof navigator === 'object' ? navigator.userAgent : '';
|
||||
|
||||
export const isFirefox = (userAgent.indexOf('Firefox') >= 0);
|
||||
export const isWebKit = (userAgent.indexOf('AppleWebKit') >= 0);
|
||||
|
||||
@@ -13,6 +13,8 @@ export const enum KeyboardSupport {
|
||||
None
|
||||
}
|
||||
|
||||
const safeNavigator = typeof navigator === 'object' ? navigator : {} as { [key: string]: any };
|
||||
|
||||
/**
|
||||
* Browser feature we can support in current platform, browser and environment.
|
||||
*/
|
||||
@@ -21,11 +23,11 @@ export const BrowserFeatures = {
|
||||
writeText: (
|
||||
platform.isNative
|
||||
|| (document.queryCommandSupported && document.queryCommandSupported('copy'))
|
||||
|| !!(navigator && navigator.clipboard && navigator.clipboard.writeText)
|
||||
|| !!(safeNavigator && safeNavigator.clipboard && safeNavigator.clipboard.writeText)
|
||||
),
|
||||
readText: (
|
||||
platform.isNative
|
||||
|| !!(navigator && navigator.clipboard && navigator.clipboard.readText)
|
||||
|| !!(safeNavigator && safeNavigator.clipboard && safeNavigator.clipboard.readText)
|
||||
)
|
||||
},
|
||||
keyboard: (() => {
|
||||
@@ -33,7 +35,7 @@ export const BrowserFeatures = {
|
||||
return KeyboardSupport.Always;
|
||||
}
|
||||
|
||||
if ((<any>navigator).keyboard || browser.isSafari) {
|
||||
if ((<any>safeNavigator).keyboard || browser.isSafari) {
|
||||
return KeyboardSupport.FullScreen;
|
||||
}
|
||||
|
||||
@@ -42,6 +44,6 @@ export const BrowserFeatures = {
|
||||
|
||||
// 'ontouchstart' in window always evaluates to true with typescript's modern typings. This causes `window` to be
|
||||
// `never` later in `window.navigator`. That's why we need the explicit `window as Window` cast
|
||||
touch: 'ontouchstart' in mainWindow || navigator.maxTouchPoints > 0,
|
||||
touch: 'ontouchstart' in mainWindow || safeNavigator.maxTouchPoints > 0,
|
||||
pointerEvents: mainWindow.PointerEvent && ('ontouchstart' in mainWindow || navigator.maxTouchPoints > 0)
|
||||
};
|
||||
|
||||
@@ -11,4 +11,4 @@ export function ensureCodeWindow(targetWindow: Window, fallbackWindowId: number)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
export const mainWindow = window as CodeWindow;
|
||||
export const mainWindow = (typeof window === 'object' ? window : globalThis) as CodeWindow;
|
||||
|
||||
Reference in New Issue
Block a user