diff --git a/lib/browser/api/session.js b/lib/browser/api/session.js index 49b169bd3ac5..dc1c529878fb 100644 --- a/lib/browser/api/session.js +++ b/lib/browser/api/session.js @@ -1,16 +1,26 @@ const {EventEmitter} = require('events') +const electron = require('electron') const bindings = process.atomBinding('session') const PERSIST_PREFIX = 'persist:' +// Wrapper of binding.fromPartition that checks for ready event. +const fromPartition = function (partition, persist) { + if (!electron.app.isReady()) { + throw new Error('session module can only be used when app is ready') + } + + return bindings.fromPartition(partition, persist) +} + // Returns the Session from |partition| string. exports.fromPartition = function (partition = '') { if (partition === '') return exports.defaultSession if (partition.startsWith(PERSIST_PREFIX)) { - return bindings.fromPartition(partition.substr(PERSIST_PREFIX.length), false) + return fromPartition(partition.substr(PERSIST_PREFIX.length), false) } else { - return bindings.fromPartition(partition, true) + return fromPartition(partition, true) } } @@ -18,7 +28,7 @@ exports.fromPartition = function (partition = '') { Object.defineProperty(exports, 'defaultSession', { enumerable: true, get: function () { - return bindings.fromPartition('', false) + return fromPartition('', false) } })