diff --git a/src/main.js b/src/main.js index 3e4618e3474..c320af38ab2 100644 --- a/src/main.js +++ b/src/main.js @@ -46,6 +46,7 @@ import allowProtocolDialog from './main/allowProtocolDialog'; import PermissionManager from './main/PermissionManager'; import permissionRequestHandler from './main/permissionRequestHandler'; import AppStateManager from './main/AppStateManager'; +import initCookieManager from './main/cookieManager'; import SpellChecker from './main/SpellChecker'; @@ -423,6 +424,8 @@ app.on('ready', () => { } } + initCookieManager(session.defaultSession); + mainWindow = createMainWindow(config, { hideOnStartup, linuxAppIcon: path.join(assetsDir, 'appicon.png'), diff --git a/src/main/cookieManager.js b/src/main/cookieManager.js new file mode 100644 index 00000000000..66c76f5aaa0 --- /dev/null +++ b/src/main/cookieManager.js @@ -0,0 +1,22 @@ +import {app} from 'electron'; + +function flushCookiesStore(session) { + session.cookies.flushStore((err) => { + if (err) { + console.log(err); + } + }); +} + +export default function initCookieManager(session) { + // Somehow cookies are not immediately saved to disk. + // So flush cookie store to disk manually. + // https://github.com/electron/electron/issues/8416 + app.on('before-quit', () => { + flushCookiesStore(session); + }); + + app.on('browser-window-blur', () => { + flushCookiesStore(session); + }); +}