net-log.js 802 B

12345678910111213141516171819202122232425262728
  1. 'use strict'
  2. // TODO(deepak1556): Deprecate and remove standalone netLog module,
  3. // it is now a property of sessio module.
  4. const { app, session } = require('electron')
  5. // Fallback to default session.
  6. Object.setPrototypeOf(module.exports, new Proxy({}, {
  7. get (target, property) {
  8. if (!app.isReady()) return
  9. const netLog = session.defaultSession.netLog
  10. if (!Object.getPrototypeOf(netLog).hasOwnProperty(property)) return
  11. // Returning a native function directly would throw error.
  12. return (...args) => netLog[property](...args)
  13. },
  14. ownKeys () {
  15. if (!app.isReady()) return []
  16. return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession.netLog))
  17. },
  18. getOwnPropertyDescriptor (target) {
  19. return { configurable: true, enumerable: true }
  20. }
  21. }))