Skip to content
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

Workaround crash that can happen in Electron/Chromium #4678

Merged
merged 1 commit into from
Aug 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/browser/renderer/dom/StyleSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @license MIT
*/

import { isElectron } from 'common/Platform';

export interface IStyleSheet {
dispose: () => void;
setCss: (value: string) => void;
Expand Down Expand Up @@ -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);
};
1 change: 1 addition & 0 deletions src/common/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down