From 2ca0ccbe0c57acfcf5cc61ac2e6922577331a130 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 15 Aug 2023 06:46:35 -0700 Subject: [PATCH] Workaround crash that can happen in Electron/Chromium Part of microsoft/vscode#189753 --- src/browser/renderer/dom/StyleSheet.ts | 13 +++++++++---- src/common/Platform.ts | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/browser/renderer/dom/StyleSheet.ts b/src/browser/renderer/dom/StyleSheet.ts index 574615f46b..a4c52da468 100644 --- a/src/browser/renderer/dom/StyleSheet.ts +++ b/src/browser/renderer/dom/StyleSheet.ts @@ -3,6 +3,8 @@ * @license MIT */ +import { isElectron } from 'common/Platform'; + export interface IStyleSheet { dispose: () => void; setCss: (value: string) => void; @@ -37,9 +39,12 @@ const createStyleElement = (parent: HTMLElement): IStyleSheet => { }; export const createStyle = (parent: HTMLElement): IStyleSheet => { - try { - return createCssStyleSheet(parent.ownerDocument); - } catch { - return createStyleElement(parent); + // The combination of the CSP workaround and the DOM renderer can trigger a crash in electron + // https://github.com/microsoft/vscode/issues/189753 + if (!isElectron) { + try { + return createCssStyleSheet(parent.ownerDocument); + } catch { /* Fall through */ } } + return createStyleElement(parent); }; diff --git a/src/common/Platform.ts b/src/common/Platform.ts index 41d8552e49..27dc97cfb6 100644 --- a/src/common/Platform.ts +++ b/src/common/Platform.ts @@ -17,6 +17,7 @@ export const isNode = (typeof navigator === 'undefined') ? true : false; const userAgent = (isNode) ? 'node' : navigator.userAgent; const platform = (isNode) ? 'node' : navigator.platform; +export const isElectron = userAgent.includes('Electron'); export const isFirefox = userAgent.includes('Firefox'); export const isLegacyEdge = userAgent.includes('Edge'); export const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);