net-log.js 962 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. // TODO(deepak1556): Deprecate and remove standalone netLog module,
  3. // it is now a property of session 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. // check for properties on the prototype chain that aren't functions
  12. if (typeof netLog[property] !== 'function') return netLog[property];
  13. // Returning a native function directly would throw error.
  14. return (...args) => netLog[property](...args);
  15. },
  16. ownKeys () {
  17. if (!app.isReady()) return [];
  18. return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession.netLog));
  19. },
  20. getOwnPropertyDescriptor (target) {
  21. return { configurable: true, enumerable: true };
  22. }
  23. }));