Workaround crash that can happen in Electron/Chromium
Part of microsoft/vscode#189753
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { isElectron } from 'common/Platform';
|
||||||
|
|
||||||
export interface IStyleSheet {
|
export interface IStyleSheet {
|
||||||
dispose: () => void;
|
dispose: () => void;
|
||||||
setCss: (value: string) => void;
|
setCss: (value: string) => void;
|
||||||
@@ -37,9 +39,12 @@ const createStyleElement = (parent: HTMLElement): IStyleSheet => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const createStyle = (parent: HTMLElement): IStyleSheet => {
|
export const createStyle = (parent: HTMLElement): IStyleSheet => {
|
||||||
try {
|
// The combination of the CSP workaround and the DOM renderer can trigger a crash in electron
|
||||||
return createCssStyleSheet(parent.ownerDocument);
|
// https://github.com/microsoft/vscode/issues/189753
|
||||||
} catch {
|
if (!isElectron) {
|
||||||
return createStyleElement(parent);
|
try {
|
||||||
|
return createCssStyleSheet(parent.ownerDocument);
|
||||||
|
} catch { /* Fall through */ }
|
||||||
}
|
}
|
||||||
|
return createStyleElement(parent);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export const isNode = (typeof navigator === 'undefined') ? true : false;
|
|||||||
const userAgent = (isNode) ? 'node' : navigator.userAgent;
|
const userAgent = (isNode) ? 'node' : navigator.userAgent;
|
||||||
const platform = (isNode) ? 'node' : navigator.platform;
|
const platform = (isNode) ? 'node' : navigator.platform;
|
||||||
|
|
||||||
|
export const isElectron = userAgent.includes('Electron');
|
||||||
export const isFirefox = userAgent.includes('Firefox');
|
export const isFirefox = userAgent.includes('Firefox');
|
||||||
export const isLegacyEdge = userAgent.includes('Edge');
|
export const isLegacyEdge = userAgent.includes('Edge');
|
||||||
export const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
|
export const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
|
||||||
|
|||||||
Reference in New Issue
Block a user