electron/lib/browser/api/protocol.js
Cheng Zhao fcd3357fb8 Use Proxy to provide protocol APIs
In this way we can avoid initializing defaultSession when protocol
module is used.
2016-07-13 12:23:14 +09:00

19 lines
512 B
JavaScript

const {session} = require('electron')
// Global protocol APIs.
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)
},
ownKeys () {
return Object.getOwnPropertyNames(session.defaultSession.protocol)
},
getOwnPropertyDescriptor (target) {
return { configurable: true, enumerable: true }
}
}))