Javascript 调用远程方法时出错';电子浏览器桌面捕获器获取资源;。电子

Javascript 调用远程方法时出错';电子浏览器桌面捕获器获取资源;。电子,javascript,node.js,electron,Javascript,Node.js,Electron,我正在尝试用Electron开发一个小型windows应用程序,我安装了所有东西,然后开始使用教程。我试图做的是在按下按钮时拍摄我的桌面截图,但我得到一个错误,显示调用远程方法“ELECTRON\u BROWSER\u desktop\u CAPTURER\u GET\u SOURCES”时出现错误:获取源失败。 HTML页面: <!DOCTYPE html> <html> <head> <meta charset="utf-8">

我正在尝试用Electron开发一个小型windows应用程序,我安装了所有东西,然后开始使用教程。我试图做的是在按下按钮时拍摄我的桌面截图,但我得到一个错误,显示调用远程方法“ELECTRON\u BROWSER\u desktop\u CAPTURER\u GET\u SOURCES”时出现
错误:获取源失败。

HTML页面:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Hello</title>
    <link href="Content/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
    <div style="padding-top: 75px; text-align:center">
        <label id="screenShotMessage"></label>
        <button id="screenShotTaker" class="btn btn-info">Take screenshot</button>
    </div>
    <script src="render.js">            
    </script>
</body>
</html>
主Js

const { app, BrowserWindow, Menu } = require("electron");
//main process
const path = require("path");
const url = require("url");
let win;

function createWindow() {
    win = new BrowserWindow({
        width: 800, height: 600, webPreferences: {
            nodeIntegration: true
        } });
    win.loadURL(url.format({
        pathname: path.join(__dirname, 'main.html'),
        protocol: 'file',
        slashes: true
    }));

    win.on('close', () => {
        win = null;
    });

    win.openDevTools();
}

app.on('ready', createWindow);

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit();
    }
});

app.on('activate', () => {
    if (win === null) {
        createWindow();
    }
});

desktopCapturer
尝试获取源时,会发生此错误。我不知道为什么,我也没有找到任何其他解决办法。感谢

获取屏幕截图,这里有另一个api
Wincontents.capturePage()
尝试删除
const{screen}=remote这个的目的是什么?@namila007是的,在它没有任何意义之前我就在使用它。Wincontents.CapturePage()允许您捕获整个屏幕还是仅捕获应用程序窗口的内容?它可以在选定的浏览器窗口上捕获。您是指浏览器显示的内容吗@Namila007要获取屏幕截图,还有另一个api
Wincontents.capturePage()
尝试删除
const{screen}=remote这个的目的是什么?@namila007是的,在它没有任何意义之前我就在使用它。Wincontents.CapturePage()允许您捕获整个屏幕还是仅捕获应用程序窗口的内容?它可以在选定的浏览器窗口上捕获。您是指浏览器显示的内容吗@纳米拉007
const { app, BrowserWindow, Menu } = require("electron");
//main process
const path = require("path");
const url = require("url");
let win;

function createWindow() {
    win = new BrowserWindow({
        width: 800, height: 600, webPreferences: {
            nodeIntegration: true
        } });
    win.loadURL(url.format({
        pathname: path.join(__dirname, 'main.html'),
        protocol: 'file',
        slashes: true
    }));

    win.on('close', () => {
        win = null;
    });

    win.openDevTools();
}

app.on('ready', createWindow);

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit();
    }
});

app.on('activate', () => {
    if (win === null) {
        createWindow();
    }
});