javascript - Electron Chrome 检测仪

标签 javascript electron

我有一个非常基本的 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/

相关文章:

php - 保护 public_html 中的文件夹

javascript - 如何从脚本标签和/或控制台中抓取值

javascript - 将 CSS Transition 与点击事件联系起来

node.js - 如何将 sqlite3 模块与 Electron 一起使用?

javascript - Electron-Builder Updater仅卸载当前安装

webpack - 如何让 Electron-builder 为安装程序打包非代码文件以将它们安装在用户主目录 (app-data) 中

javascript - JQuery中两个div的切换位置

javascript - 如何仅使用一个提交按钮将文件发送到 MVC 操作

javascript - sqlite3更新查询刷新 Electron 渲染器进程

windows - 如何在Electron Builder创建的应用程序的快捷方式中更改 “Start in”路径?