Do not access default session before app is ready

This commit is contained in:
Cheng Zhao 2016-07-12 19:39:06 +09:00
parent fcd3357fb8
commit 45500701f1

View file

@ -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)
},