Skip to content

Enable the webgl renderer on safari 16 and above #4255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions addons/xterm-addon-webgl/src/WebglAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IRender
import { ITerminal } from 'browser/Types';
import { EventEmitter, forwardEvent } from 'common/EventEmitter';
import { Disposable, toDisposable } from 'common/Lifecycle';
import { isSafari } from 'common/Platform';
import { getSafariVersion, isSafari } from 'common/Platform';
import { ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
import { ICoreTerminal } from 'common/Types';
import { ITerminalAddon, Terminal } from 'xterm';
Expand All @@ -33,8 +33,8 @@ export class WebglAddon extends Disposable implements ITerminalAddon {
}

public activate(terminal: Terminal): void {
if (isSafari) {
throw new Error('Webgl is not currently supported on Safari');
if (isSafari && getSafariVersion() < 16) {
throw new Error('Webgl2 is only supported on Safari 16 and above');
}

const core = (terminal as any)._core as ITerminal;
Expand Down
10 changes: 10 additions & 0 deletions src/common/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ const platform = (isNode) ? 'node' : navigator.platform;
export const isFirefox = userAgent.includes('Firefox');
export const isLegacyEdge = userAgent.includes('Edge');
export const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
export function getSafariVersion(): number {
if (!isSafari) {
return 0;
}
const majorVersion = userAgent.match(/Version\/(\d+)/);
if (majorVersion === null || majorVersion.length < 2) {
return 0;
}
return parseInt(majorVersion[1]);
}

// Find the users platform. We use this to interpret the meta key
// and ISO third level shifts.
Expand Down