From 79a096b604a0dfd99bb9d0fa1ee56cc1df8be462 Mon Sep 17 00:00:00 2001 From: rhysd Date: Tue, 25 Apr 2017 01:27:07 +0900 Subject: [PATCH] add workaround for bug of sandbox and CSP in Electron --- main/window.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/main/window.ts b/main/window.ts index be5d1f0..a8cd857 100644 --- a/main/window.ts +++ b/main/window.ts @@ -140,7 +140,7 @@ function startNormalWindow(account: Account, config: Config): Promise { autoHideMenuBar: !!config.hide_menu, webPreferences: { nodeIntegration: false, - sandbox: !!config.chromium_sandbox, + sandbox: sandboxFlag(config, account), preload: PRELOAD_JS, partition: partitionForAccount(account), zoomFactor: config.zoom_factor, @@ -171,6 +171,20 @@ function startNormalWindow(account: Account, config: Config): Promise { }); } +function sandboxFlag(config: Config, account: Account) { + // XXX: + // Electron has a bug that CSP prevents preload script from being loaded. + // mstdn.jp enables CSP. So currently we need to disable native sandbox to load preload script. + // + // Ref: https://github.com/electron/electron/issues/9276 + // + const electronBugIssue9276 = account.host === 'mstdn.jp' || account.host === 'https://mstdn.jp'; + if (electronBugIssue9276) { + return false; + } + return !!config.chromium_sandbox; +} + function startMenuBar(account: Account, config: Config, bar: Menubar.MenubarApp | null): Promise { log.debug('Setup a menubar window'); return new Promise(resolve => { @@ -190,7 +204,7 @@ function startMenuBar(account: Account, config: Config, bar: Menubar.MenubarApp showDockIcon: true, webPreferences: { nodeIntegration: false, - sandbox: !!config.chromium_sandbox, + sandbox: sandboxFlag(config, account), preload: PRELOAD_JS, partition: partitionForAccount(account), zoomFactor: config.zoom_factor,