我有一个非常基本的 Electron 应用程序,其中有一个简单的 package.json,如下所示:
{
"name": "app",
"version": "1.0.0",
"main": "main.js"
}
和 main.js 文件如下:
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()
}
})
但是当我启动应用程序时,Chromium 的检查器会与我的 index.html 页面一起出现在屏幕上。为什么检查员会自动出现?
最佳答案
从技术上讲,它并不称为“Inspector”,而是“DevTools”,是 Chromium 上“开发人员工具”的缩写。它在应用程序启动时打开的原因是因为您使用以下行打开 DevTools:
win.webContents.openDevTools()
BrowserWindow.webContents
已记录 here ,带有openDevTools
的描述:
contents.openDevTools([options])
Opens the devtools.
删除此选项可阻止 DevTools 打开。
关于javascript - Electron Chrome 检测仪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41333438/