TypeError:无法读取未定义的属性'getPrimaryDisplay'(screen.getPrimaryDisplay())

时间:2019-08-02 13:05:27

标签: javascript electron screen screenshot

我正在尝试使用此屏幕尺寸。在旧版本上运行正常。无法在电子版6.0.0上工作

const {remote} = require('electron');
const {desktopCapturer, screen} = require('electron');

var mainScreen = screen.getPrimaryDisplay();
var dimensions = mainScreen.size;

1 个答案:

答案 0 :(得分:1)

如果要从渲染器进程访问诸如screen之类的主流程模块,则必须使用remote模块。

const {remote, desktopCapturer} = require('electron'); // Renderer process modules
const {screen} = require('electron').remote; // Main process modules