From 45500701f18602d0d2af0efdd0cea449df193b59 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 12 Jul 2016 19:39:06 +0900 Subject: [PATCH] Do not access default session before app is ready --- lib/browser/api/protocol.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/browser/api/protocol.js b/lib/browser/api/protocol.js index d1c26991d0e3..9d8394f76754 100644 --- a/lib/browser/api/protocol.js +++ b/lib/browser/api/protocol.js @@ -1,4 +1,4 @@ -const {session} = require('electron') +const {app, session} = require('electron') // Global protocol APIs. module.exports = process.atomBinding('protocol') @@ -6,10 +6,18 @@ module.exports = process.atomBinding('protocol') // Fallback protocol APIs of default session. Object.setPrototypeOf(module.exports, new Proxy({}, { get (target, property) { - return (...args) => session.defaultSession.protocol[property](...args) + if (!app.isReady()) return + + const protocol = session.defaultSession.protocol + if (!protocol.hasOwnProperty(property)) return + + // Returning a native function directly would throw error. + return (...args) => protocol[property](...args) }, ownKeys () { + if (!app.isReady()) return [] + return Object.getOwnPropertyNames(session.defaultSession.protocol) },