2019-02-06 20:27:58 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
// TODO(deepak1556): Deprecate and remove standalone netLog module,
|
2019-04-05 18:06:38 +00:00
|
|
|
// it is now a property of session module.
|
2019-02-06 20:27:58 +00:00
|
|
|
const { app, session } = require('electron')
|
|
|
|
|
|
|
|
// Fallback to default session.
|
|
|
|
Object.setPrototypeOf(module.exports, new Proxy({}, {
|
|
|
|
get (target, property) {
|
|
|
|
if (!app.isReady()) return
|
|
|
|
|
|
|
|
const netLog = session.defaultSession.netLog
|
2019-04-05 18:06:38 +00:00
|
|
|
|
2019-02-06 20:27:58 +00:00
|
|
|
if (!Object.getPrototypeOf(netLog).hasOwnProperty(property)) return
|
|
|
|
|
2019-04-05 18:06:38 +00:00
|
|
|
// check for properties on the prototype chain that aren't functions
|
|
|
|
if (typeof netLog[property] !== 'function') return netLog[property]
|
|
|
|
|
2019-02-06 20:27:58 +00:00
|
|
|
// Returning a native function directly would throw error.
|
|
|
|
return (...args) => netLog[property](...args)
|
|
|
|
},
|
|
|
|
|
|
|
|
ownKeys () {
|
|
|
|
if (!app.isReady()) return []
|
|
|
|
|
|
|
|
return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession.netLog))
|
|
|
|
},
|
|
|
|
|
|
|
|
getOwnPropertyDescriptor (target) {
|
|
|
|
return { configurable: true, enumerable: true }
|
|
|
|
}
|
|
|
|
}))
|