【问题标题】:Debugging Electron-Atom script with Visual Studio Code使用 Visual Studio Code 调试 Electron-Atom 脚本
【发布时间】:2015-10-04 10:25:17
【问题描述】:

Electron 是否在 Visual Studio Code 上运行?

如果是,如何设置一个简单的环境,我可以使用 Visual Studio Code 编写/webbug Atom Electron 脚本?

例如我用这个 Test.js 脚本;

var app = require('app');

process.on('uncaughtException', function(error) {
    console.error("ERROR Exception => " + error.stack);
})

app.on('ready', function() {
    console.log('ready!');
    aksjdflkasjdf(); // Caught Exception
})

对于 Visual Studio Code,有一个 launch.json 配置文件,但我没有说明如何设置 Visual Studio Code 以供 Electron 工作。

【问题讨论】:

    标签: javascript visual-studio-code electron


    【解决方案1】:

    答案取决于您是要调试 Main 进程还是 Renderer 进程。

    主进程:

    可以使用 Visual Studio Code 调试主进程。您必须在启动时将 --debug=<port> 传递给 Electron,然后在 launch.json 中配置调试器以附加到它。附加需要一点时间,因此您可能需要等待调试在启动时运行的部件。你的 launch.json 文件应该有这个:

        {
            "name": "Attach",
            "type": "node",
            "address": "localhost",
            "port": <port>,
        }
    

    另外,还有一种方法可以将 Visual Studio Code 配置为运行 Electron 并在同一进程中附加调试器。在此处查看此线程:Can Visual Studio Code be configured to launch electron。我还在我的博客上写了如何设置它:https://mylifeforthecode.github.io/getting-started-with-electron-in-visual-studio-code/ 和这里:https://mylifeforthecode.github.io/a-better-way-to-launch-electron-from-visual-studio-code/

    渲染进程:

    我不知道使用 Visual Studio Code 调试渲染器进程的方法。根据他们的文档:

    今天,我们在所有平台上为 Node.js(JavaScript 和 TypeScript)提供了良好的调试支持,并在 OS X 和 Linux 上为 mono(C# 和 F#)提供了实验性支持。在 //build 中,我们强调了我们正在为 ASP.NET 5 添加的支持,并且我们计划添加更多支持。

    查看https://code.visualstudio.com/docs/debugging。请注意,浏览器中没有提及 JavaScript。

    但是,您可以使用 Chrome 的 DevTools 来调试这些进程。在 BrowserWindow 上调用 openDevTools()toggleDevTools() 方法,您将获得与在 Chrome 中按 F12 相同的工具集。您需要解决一些时间问题才能连接调试器。请参阅此线程:Atom Electron - Detect Dev Tools ready 以解决此问题。我也在我的博客上写过这个:https://mylifeforthecode.github.io/debugging-renderer-process-in-electron/

    【讨论】:

    【解决方案2】:

    我写了一篇关于这个话题的博文:http://code.matsu.io/1

    我介绍了调试 Main 和 Renderer 进程,我使用的方法适用于所有平台,包括 Windows。

    代码在:https://github.com/octref/vscode-electron-debug

    【讨论】:

    • 首先:感谢您的博客。据我了解(我是新手),这个解释适用于 node.js。但是node2呢? Node 似乎或多或少地被弃用了。也许对于像我这样的新手来说,获取有关如何设置 Visual Studio Code 以与 Electron 一起工作(和调试)的简单信息可能会有所帮助?我还找到了 Devtron 的链接。这似乎是一个有用的扩展。但这甚至让我更加困惑。
    • @user3350279 Node2 是实验性的。我认为该博客非常清楚,因为我包含了两个示例项目以及我如何设置它们。我对 Devtron 不熟悉。
    猜你喜欢
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    • 2018-12-17
    • 2021-02-01
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    相关资源
    最近更新 更多