electrion 为了便于调试,打开控制台

默认这玩意是不开控制台的。

但是为了调试,我们还是要开控制台的。

实际上它底层就是个chrome浏览器。

所以我们也就用常规的方法旧可以打开了,

代码中插一句

window.webContents.openDevTools() 

即可。

具体怎么做

先用asar 解包对方的 asar 包。

解包之后找到对方包里面创建窗口的位置。一般都在 app.js 文件中。

内容大致是这样的。

 1 const {app, BrowserWindow} = require('electron')
 2 const path = require('path')
 3 const url = require('url')
 4 
 5 let window = null
 6 
 7 // Wait until the app is ready
 8 app.once('ready', () => {
 9   // Create a new window
10   window = new BrowserWindow({
11     // Set the initial width to 500px
12      500,
13     // Set the initial height to 400px
14     height: 400,
15     // set the title bar style
16     titleBarStyle: 'hiddenInset',
17     // set the background color to black
18     backgroundColor: "#111",
19     // Don't show the window until it's ready, this prevents any white flickering
20     show: false
21   })
22 
23   window.webContents.openDevTools()
24 
25   window.loadURL(url.format({
26     pathname: path.join(__dirname, 'index.html'),
27     protocol: 'file:',
28     slashes: true
29   }))
30 
31   window.once('ready-to-show', () => {
32     window.show()
33   })
34 })

第23 行的位置就是我加入的代码,这样窗口创建之后,立刻就会有个调试窗口蹦出来,可以直接用。

第23 行的位置原来是没有的。

原文地址:https://www.cnblogs.com/suanguade/p/15190019.html