electron/lib/browser/api/net-log.js

33 lines
985 B
JavaScript
Raw Normal View History

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