Debugging Electron renderer process with VSCode

▼魔方 西西 提交于 2019-12-06 10:43:01

I had that problem too. It appears, it takes time for Chrome Debugger to attach to the Renderer process. By the time it is connected the scripts inside Renderer have already been executed.

I've solved this issue by delaying the script execution inside renderer.js, like this:

async function main() {
  const { ipcRenderer, remote } = require('electron');
  const isDevelopment = require('electron-is-dev');

  console.log(process.env);

  if (isDevelopment) {
    // this is to give Chrome Debugger time to attach to the new window 
    await new Promise(r => setTimeout(r, 1000));
  }

  // breakpoints should work from here on,
  // toggle them with F9 or just use 'debugger'
  debugger;

  // ...
}

main().catch(function (error) {
  console.log(error);
  alert(error);
});

I have a customized version of Minimal Electron Application which solves this and a few other problems I faced when I started developing with Electron.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!