admin管理员组文章数量:1393052
I tried this document -- Electron debugging (main and renderer process) -- but hit a problem.
I went through the guide one by one and it is all fine until "1. Update the contents of renderer.js to" in "Debugging of the renderer process" section.
But when I try "2. While your debug session is....", VSCode shows the image like below and I cannot attach the debugger to the Electron process.
The list in the image shows the tabs of my browser but there's no option corresponding to the electron process launched by the Main debugger.
How do I solve this issue?
I tried this document -- Electron debugging (main and renderer process) -- but hit a problem.
I went through the guide one by one and it is all fine until "1. Update the contents of renderer.js to" in "Debugging of the renderer process" section.
But when I try "2. While your debug session is....", VSCode shows the image like below and I cannot attach the debugger to the Electron process.
The list in the image shows the tabs of my browser but there's no option corresponding to the electron process launched by the Main debugger.
How do I solve this issue?
3 Answers
Reset to default 4I 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.
I solved this problem by letting the Renderer wait untill the main is ready.
So adding this into your main.js:
// ...
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.send('main-process-loaded');
});
// ...
And this into your renders index.js:
correctly
ipcRenderer.on('main-process-loaded', () => {
root.render(<App />);
});
For whom still face that problem and don't want to change the code, you can edit launch.json at the render section and increase the timeout :
{
"name": "Electron: Renderer",
"type": "chrome",
"request": "attach",
"port": 9223,
"webRoot": "${workspaceFolder}",
"timeout": <increased-timeout>
}
本文标签: javascriptDebugging Electron renderer process with VSCodeStack Overflow
版权声明:本文标题:javascript - Debugging Electron renderer process with VSCode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744657586a2618059.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论