Home Reference Source

lib/utils/electron.js

  1. const isEmpty = require('lodash/isEmpty')
  2.  
  3. /**
  4. * @desc Electron requires the use of the debugger to retrieve the requests response body
  5. * @param {string} requestId - the request to fetch the response body for
  6. * @param {Object} wcDebugger - the Electron debugger to use to get the response body
  7. * @see https://electron.atom.io/docs/api/debugger/
  8. * @return {Promise<?Buffer>} body - the response body as a node buffer
  9. */
  10. function getResBody (requestId, wcDebugger) {
  11. return new Promise((resolve) => {
  12. wcDebugger.sendCommand(
  13. 'Network.getResponseBody',
  14. { requestId },
  15. (error, body) => {
  16. resolve(!isEmpty(error) ? null : body)
  17. }
  18. )
  19. })
  20. }
  21.  
  22. /**
  23. * @desc Electron requires the use of the debugger to retrieve the requests post data
  24. * @param {string} requestId - the request to fetch the post data for
  25. * @param {Object} wcDebugger - the Electron debugger to use to get the post data
  26. * @see https://electron.atom.io/docs/api/debugger/
  27. * @return {Promise<?Buffer>} body - the response body as a node buffer
  28. */
  29. function getPostData (requestId, wcDebugger) {
  30. return new Promise((resolve) => {
  31. wcDebugger.sendCommand(
  32. 'Network.getRequestPostData',
  33. { requestId },
  34. (error, body) => {
  35. resolve(!isEmpty(error) ? null : body)
  36. }
  37. )
  38. })
  39. }
  40.  
  41. module.exports = {
  42. /**
  43. * @type {function(string, Object): Promise<?Buffer>}
  44. */
  45. getResBody,
  46. /**
  47. * @type {function(string, Object): Promise<?Buffer>}
  48. */
  49. getPostData
  50. }