UNPKG

@lynker-desktop/devtron

Version:

Electron DevTools Extension to track IPC events

170 lines (159 loc) 6.61 kB
/******/ var __webpack_modules__ = ([ /* 0 */, /* 1 */ /***/ ((module) => { module.exports = require("electron"); /***/ }), /* 2 */, /* 3 */, /* 4 */ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ MSG_TYPE: () => (/* binding */ MSG_TYPE), /* harmony export */ PORT_NAME: () => (/* binding */ PORT_NAME) /* harmony export */ }); const PORT_NAME = { PANEL: 'Lynker', CONTENT_SCRIPT: 'lynker-content-script', }; const MSG_TYPE = { PING: 'ping', PONG: 'pong', KEEP_ALIVE: 'keep-alive', GET_ALL_EVENTS: 'get-all-events', RENDER_EVENT: 'render-event', CLEAR_EVENTS: 'clear-events', EVENTS_CLEARED_ACK: 'events-cleared-ack', ADD_IPC_EVENT: 'add-ipc-event', SEND_TO_PANEL: 'send-to-panel', }; /***/ }) /******/ ]); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ (() => { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = (module) => { /******/ var getter = module && module.__esModule ? /******/ () => (module['default']) : /******/ () => (module); /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports /******/ __webpack_require__.r = (exports) => { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. (() => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ monitorMain: () => (/* binding */ monitorMain) /* harmony export */ }); /* harmony import */ var electron__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); /* harmony import */ var electron__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(electron__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _common_constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4); /** * This file patches the Electron IPCMain methods to track events * and send them to the renderer process. * It is required in the main process of the Electron app. */ function monitorMain() { function trackIpcEvent(direction, channel, args) { const eventData = { direction, channel, args, timestamp: Date.now(), }; /** * webContents.getAllWebContents() returns an array of all webContents instances. * This will contain web contents for all windows, webviews, opened devtools, and devtools extension background pages. * We send event to renderer process, which then sends it to the devtools. */ electron__WEBPACK_IMPORTED_MODULE_0__.webContents.getAllWebContents().forEach((wc) => { wc.send(_common_constants__WEBPACK_IMPORTED_MODULE_1__.MSG_TYPE.RENDER_EVENT, eventData); }); } // Patch ipcMain.on const originalOn = electron__WEBPACK_IMPORTED_MODULE_0__.ipcMain.on.bind(electron__WEBPACK_IMPORTED_MODULE_0__.ipcMain); electron__WEBPACK_IMPORTED_MODULE_0__.ipcMain.on = function (channel, listener) { return originalOn(channel, (event, ...args) => { trackIpcEvent('renderer-to-main', channel, args); listener(event, ...args); }); }; // Patch ipcMain.once const originalOnce = electron__WEBPACK_IMPORTED_MODULE_0__.ipcMain.once.bind(electron__WEBPACK_IMPORTED_MODULE_0__.ipcMain); electron__WEBPACK_IMPORTED_MODULE_0__.ipcMain.once = function (channel, listener) { return originalOnce(channel, (event, ...args) => { trackIpcEvent('renderer-to-main', channel, args); listener(event, ...args); }); }; // Patch ipcMain.handle const originalHandle = electron__WEBPACK_IMPORTED_MODULE_0__.ipcMain.handle.bind(electron__WEBPACK_IMPORTED_MODULE_0__.ipcMain); electron__WEBPACK_IMPORTED_MODULE_0__.ipcMain.handle = function (channel, listener) { originalHandle(channel, async (event, ...args) => { trackIpcEvent('renderer-to-main', channel, args); return await listener(event, ...args); }); }; } })(); const __webpack_exports__monitorMain = __webpack_exports__.monitorMain; export { __webpack_exports__monitorMain as monitorMain };