Skip to content

node v21.0.0 breaks with xterm: Cannot read properties of undefined (reading 'includes')Β #4850

@davidfiala

Description

@davidfiala

node v21.0.0 introduces the navigator object where it used to be undefined.

Which causes issues in src/common/Platform.ts:

export const isNode = (typeof navigator === 'undefined') ? true : false;
const userAgent = (isNode) ? 'node' : navigator.userAgent;
const platform = (isNode) ? 'node' : navigator.platform;

export const isFirefox = userAgent.includes('Firefox');

There was discussion on whether using navigator to detect node here: nodejs/node#47769 (comment) but ultimately they concluded that since Deno has introduced a navigator object, so can node.

I often see checks like this instead:

const isNode = (typeof process !== 'undefined');
// or
const isNode = (typeof global !== 'undefined');

which will work for v21 and below.

Metadata

Metadata

Assignees

Labels

type/debtTechnical debt that could slow us down in the long run

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions