跳到主要内容

Electron FAQ

  • ASAR
提示
  • Electronn 28 支持 ESM

无边控窗口偶尔无法拖动

如何检测运行在 electron

window && window.process && window.process.type;

process.versions['electron'];

// Electron/
navigator.userAgent;

// 如果 contextBridge.exposeInMainWorld
globalThis.electron;

BrowserView vs webview

  • BrowserWindow - 用于替代 webview 标签
    • Electron 接口 - 非 DOM - 位置相对于父窗口,需要自行管理
    • 不开启额外渲染进程 - 主进程控制
  • webview - 不推荐使用
    • html tag - 好使用,好布局
    • 额外渲染进程 - out-of-process iframe - 所有通讯都是 IPC
    • 速度慢于 iframe

Chrome 扩展支持情况

支持部分扩展

Failed to fetch extension, trying 4 more times

最好启动时开代理,比如一般会加载 react devtool

  • fmkadmapgofadopljbjfkapdkoienihi - React Developer Tools
ls "$HOME/Library/Application Support/Electron/extensions/"

ExtensionLoadWarning: Warnings loading extension at

electron 高版本 插件加载失败

安全相关问题

Electron Helper (Renderer) CoreText note: Client requested name ".PingFangSC-Semibold", it will get Times-Roman rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].

不影响使用

Extension server error: Object not found: top"

did-frame-finish-load 之后 打开 devtool

partition vs session

electron Failed to load URL: with error: ERR_UNKNOWN_URL_SCHEME

尝试不用 file 协议 或者自行处理

import { protocol } from "electron";


protocol.registerFileProtocol('file', (request, cb) => {
const url = request.url.replace('file:///', '');
const decodedUrl = decodeURIComponent(url);
try {
return cb(decodedUrl);
} catch (error) {
console.error('ERROR: registerLocalResourceProtocol: Could not get file path:', error);
}
});