Electron指南 - 调试主进程

调试主进程

浏览器窗口的DevTools只能调试渲染进程的脚本(比如Web页面)。为了提供一种方法来调试主进程中的脚本,Electron提供了 --debug 以及 --debug-brk 的选项开关。

命令行开关

使用下列命令行切换到调试Electron的主进程模式:

--debug=[port]

这个开关将使得Electron使用V8调试协议侦听在指定端口上。默认侦听端口是5858。

--debug-brk=[port]

类似于 --debug 但是这个开关将在脚本的第一行暂停执行。

使用node-inspector来调试

注意: 当前的Electron和node-inspector工作的不是非常好,并且当你在node-inspector的控制台检查 process 对象的时候主进程将会挂掉。

  1. 确信安装了node-gyp及其依赖的工具

  2. 安装node-inspector

    $ npm install node-inspector
  3. 安装 node-pre-gyp 补丁

    $ npm install git+https://git@github.com/enlight/node-pre-gyp.git#detect-electron-runtime-in-find
  4. 重新编译 node-inspector V8 模块 (改变编译目标至你的Electron版本号)

    $ node_modules/.bin/node-pre-gyp --target=0.36.11 --runtime=electron --fallback-to-build --directory node_modules/v8-debug/ --dist-url=https://atom.io/download/atom-shell reinstall
    $ node_modules/.bin/node-pre-gyp --target=0.36.11 --runtime=electron --fallback-to-build --directory node_modules/v8-profiler/ --dist-url=https://atom.io/download/atom-shell reinstall
    查阅[如何安装本地模块](http://electron.atom.io/docs/tutorial/using-native-node-modules#how-to-install-native-modules)
  5. 打开Electron调试模式

    你可以使用一个debug标志来打开Electron,例如:
    $ electron --debug=5858 your/app
    或在脚本第一行暂停
    $ electron --debug-brk=5858 your/app
  6. 使用electron启动node-inspector

    $ ELECTRON_RUN_AS_NODE=true path/to/electron.exe node_modules/node-inspector/bin/inspector.js
  7. 装载调试器UI

    在Chrome浏览器中打开 *http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858*。 如果使用debug-brk来启动的话你必须点击暂停来看的看到完整的行。
    

本文翻译自[这里] (http://electron.atom.io/docs/tutorial/debugging-main-process/)
未经授权,禁止转载。

更多文章请浏览我的博客:@gihub, @coding

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值