![](/img/trans.png)
[英]Attach Visual Studio debugger to an electron-edge app through node.js
[英]Attach visual studio debugger to electron app
我正試圖從頭開始從Visual Studio 2017(而不是vscode)調試電子應用程序。
我創建了一個控制台nodejs項目,安裝並保存電子。 項目結構:
app.js
內容(取自電子網站):
'use strict';
const { app, BrowserWindow } = require('electron')
const path = require('path')
const url = require('url')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
function createWindow() {
// Create the browser window.
win = new BrowserWindow({ width: 800, height: 600 })
// and load the index.html of the app.
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
// Open the DevTools.
win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
和index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
We are using node
<script>document.write(process.versions.node)</script>,
Chrome
<script>document.write(process.versions.chrome)</script>,
and Electron
<script>document.write(process.versions.electron)</script>.
</body>
</html>
但是,當我點擊開始時,電子應用程序啟動,但調試過程似乎自行分離。 當我嘗試手動將調試器連接到所有電子過程(調試 - >附加到過程 - >選擇所有電子過程)時,斷點聲稱不會被命中,因為沒有加載符號。
我錯過了一步嗎? 由於可以在VSCode上進行調試,我認為它也可以在VS2017中完成?
非常感謝。
注意:我確實檢查了抑制JIT優化並取消選中僅啟用我的代碼。
這實際上很容易做到。
轉到Debug> Attach to process ...並輸入Webkit websocket連接類型和http://127.0.0.1:5858作為目標。
您的斷點現已啟用。
在“Node.exe選項”字段中, --debug=$DEBUG_PORT
v6及更低版本添加--debug=$DEBUG_PORT
或--inspect=$DEBUG_PORT
v7或更高版本添加--inspect=$DEBUG_PORT
,其中$DEBUG_PORT
用於表示您在調試配置中指定的端口。
如果您沒有傳遞端口並且只傳遞--debug
或--inspect
標志,則Node調試器分別偵聽端口5858和9229 ......在更高版本的節點中,它們將默認端口更改為9229。
如果這有幫助,請告訴我!
附加和調試Electron - >要啟動調試會話,請打開PowerShell / CMD並執行Electron的調試版本,使用應用程序作為參數打開。
$ ./out/D/electron.exe ~/my-electron-app/
有關完整文檔,請閱讀此處
要查看符號未加載的原因,請在Windbg中鍵入以下命令。
> !sym noisy
> .reload /f electron.exe
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.