Electron参考手册
调试器 | Debugger
调试器 | Debugger
Chrome远程调试协议的备用传输方式。
过程:主
Chrome开发者工具在JavaScript运行时有一个特殊的绑定,允许与页面进行交互并对它们进行测试。
const {BrowserWindow} = require('electron')
let win = new BrowserWindow()
try {
win.webContents.debugger.attach('1.1')
} catch (err) {
console.log('Debugger attach failed : ', err)
}
win.webContents.debugger.on('detach', (event, reason) => {
console.log('Debugger detached due to : ', reason)
})
win.webContents.debugger.on('message', (event, method, params) => {
if (method === 'Network.requestWillBeSent') {
if (params.request.url === 'https://www.github.com') {
win.webContents.debugger.detach()
}
}
})
win.webContents.debugger.sendCommand('Network.enable')
Instance Methods
debugger.attach([protocolVersion])
-
protocolVersion
字符串(可选) - 请求的调试协议版本。
将调试器附加到webContents
。
debugger.isAttached()
返回Boolean
- 调试器是否附加到webContents
。
debugger.detach()
从调试器中分离出来webContents
。
debugger.sendCommand(method[, commandParams, callback])
-
method
字符串 - 方法名称应该是远程调试协议定义的方法之一。 -
commandParams
对象(可选) - 带请求参数的JSON对象。 -
callback
功能(可选) - 响应-
error
对象 - 指示命令失败的错误消息。 -
result
任何 - 由远程调试协议中的命令描述的“返回”属性定义的响应。
-
将给定的命令发送到调试目标。
Instance Events
Event: ‘detach’
-
event
Event -
reason
String - Reason for detaching debugger.
调试会话终止时发出。这种情况发生在webContents
关闭或devtools被调用时webContents
。
Event: ‘message’
-
event
事件 -
method
字符串 - 方法名称。 -
params
对象 - 由远程调试协议中'参数'属性定义的事件参数。
每当调试目标问题检测仪器事件时发出。
调试器 | Debugger相关
Electron 是一个使用 JavaScript, HTML 和 CSS 等 Web 技术创建原生程序的框架,它负责比较难搞的部分,你只需把精力放在你的应用的核心上即可。
主页 | https://electron.atom.io/ |
源码 | https://github.com/electron/electron |
发布版本 | 1.7.9 |