zoukankan      html  css  js  c++  java
  • 升级到electron10以后的版本remote失效

    有个electron-vue项目,通过使用remote来实现主进程和渲染进程之间的值传递

    // 主进程使用了global.sharedObject来传递路径信息到渲染进程
    global.sharedObject = {
      extra: storage.getStoragePath(),
    };
    
    // 渲染进程
    let remote = require('electron').remote
    storage.setStoragePath(remote.getGlobal('sharedObject').extra);
    const app = require('electron').remote.app
    原本使用的是低版本的electron,一直正常使用,但是升级到electron10.1.2之后,项目中报“getGlobal”未定义:
    Uncaught TypeError: Cannot read property 'getGlobal' of undefined

    打印remote对象,发现是undefined

    解决方案
    实际是在electron 10下,remote模块默认关闭, 必须手动设置webPreferences中的enableRemoteModule为true之后才能使用

    找到项目中的BrowserWindow部分,添加如下:

    mainWindow = new BrowserWindow({
        webPreferences: {
          nodeIntegration: true,
          // 在electron 10.0.0之后,remote模块默认关闭
          // 必须手动设置webPreferences中的enableRemoteModule为true之后才能使用
          enableRemoteModule: true, // 这里是关键设置
        },
        // 其他设置...
      });
  • 相关阅读:
    Trie树
    递归函数两种方式的区别
    揭开HTTPS的神秘面纱
    补码到底是个什么东西
    浮点数的运算精度丢失
    PHP的stdClass
    2019-10-24
    MySQL存储引擎
    代码整洁之道小结
    NFS4 挂载同主机多个目录
  • 原文地址:https://www.cnblogs.com/418836844qqcom/p/15018892.html
Copyright © 2011-2022 走看看