<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <script>
      // redirect console to main process
      var electron = require('electron')
      var localLog = console.log
      var localError = console.error
      var remoteLog = electron.remote.getGlobal('console').log
      var remoteError = electron.remote.getGlobal('console').error

      console.log = function (...args) {
        localLog.apply(console, args)
        remoteLog(...args)
      }

      console.error = function (...args) {
        localError.apply(console, args)
        remoteError(...args)
      }

      process.exit = electron.remote.app.quit
      // redirect errors to stderr
      window.addEventListener('error', function (e) {
        e.preventDefault()
        console.error(e.error.stack || 'Uncaught ' + e.error)
      })
    </script>
  </body>
</html>


<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <script>
      // redirect console to main process
      const { log: remoteLog, error: remoteErr } = require('console')
      const { log: localLog, error: localErr } = console

      console.log = function (...args) {
        localLog(...args)
        remoteLog(...args)
      }

      console.error = function (...args) {
        localErr(...args)
        remoteErr(...args)
      }

      // redirect errors to stderr
      window.addEventListener('error', function (e) {
        e.preventDefault()
        console.error(e.error.stack || 'Uncaught ' + e.error)
      })
    </script>
  </body>
</html>


Send logs to stdout with console require
Send logs to stdout with console require
