asarfuckery/electronasar/ptb/browser/api/net-log.js

28 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-10-01 13:49:56 +00:00
'use strict';
2019-01-17 18:22:05 +00:00
// TODO(deepak1556): Deprecate and remove standalone netLog module,
2019-10-01 13:49:56 +00:00
// it is now a property of session module.
const { app, session } = require('electron');
2019-01-17 18:22:05 +00:00
// Fallback to default session.
Object.setPrototypeOf(module.exports, new Proxy({}, {
2019-10-01 13:49:56 +00:00
get(target, property) {
if (!app.isReady())
return;
const netLog = session.defaultSession.netLog;
if (!Object.getPrototypeOf(netLog).hasOwnProperty(property))
return;
// check for properties on the prototype chain that aren't functions
if (typeof netLog[property] !== 'function')
return netLog[property];
// 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 };
}
}));