Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x-yuri/08f43367eaacb3793b8d33044022571e to your computer and use it in GitHub Desktop.
Save x-yuri/08f43367eaacb3793b8d33044022571e to your computer and use it in GitHub Desktop.
How to make Electron app log to console (terminal)

Use ELECTRON_ENABLE_LOGGING=true.

index.js:

const { app, BrowserWindow } = require('electron');

function createWindow () {
    let win = new BrowserWindow({
        show: false
    });

    win.loadFile('index.html');
}

app.on('ready', createWindow);

index.html:

<!doctype html>
<html>
<body>

<script>
    console.log('test');
</script>

</body>
</html>
$ echo {} > package.json
$ npm i electron

$ npx electron .
[1508635:1207/122734.081064:ERROR:buffer_manager.cc(488)] [.DisplayCompositor]GL ERROR :GL_INVALID_OPERATION : glBufferData: <- error from previous GL command

$ ELECTRON_ENABLE_LOGGING=true npx electron .
[1509121:1207/122800.446651:ERROR:sandbox_linux.cc(369)] InitializeSandbox() called with multiple threads in process gpu-process.
[1509121:1207/122800.470487:ERROR:buffer_manager.cc(488)] [.DisplayCompositor]GL ERROR :GL_INVALID_OPERATION : glBufferData: <- error from previous GL command
[1509084:1207/122800.538143:INFO:CONSOLE(6)] "test", source: file:///home/yuri/_/5/index.html (6)
[1509084:1207/122800.543453:INFO:CONSOLE(2854)] "%cElectron Security Warning (Insecure Content-Security-Policy) font-weight: bold; This renderer process has either no Content Security
    Policy set or a policy with "unsafe-eval" enabled. This exposes users of
    this app to unnecessary security risks.

For more information and help, consult
https://electronjs.org/docs/tutorial/security.
This warning will not show up
once the app is packaged.", source: electron/js2c/renderer_init.js (2854)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment