如何在CurrentWindow中捕获整个WebContent

Lor*_*lor 8 javascript electron

我在窗口内有一个非常长的页面(需要滚动查看全部),当我尝试使用下面的代码捕获整个窗口时,我得到一个压缩图像而不是CurrentWindow中的完整WebContent屏幕截图.

https://github.com/electron/electron/blob/master/docs/api/browser-window.md#wincapturepagerect-callback

        const remote = require('electron').remote;
        const win = remote.getCurrentWindow();
        const win_size = win.getSize();
        const win_height = win_size[0];
        const win_width = win_size[1];

        win.capturePage({
                x: 0,
                y: 0,
                width: win_width,
                height: win_height
            },
            (img) => {
                remote.require('fs')
                    .writeFile(TEMP_URL, img.toPng());
            });
Run Code Online (Sandbox Code Playgroud)

我也试过以下代码但结果是一样的,

        const remote = require('electron').remote;
        const webContents = remote.getCurrentWebContents();

        webContents.capturePage({
            x: 0,
            y: 0,
            width: 1000,
            height: 2000
        }, (img) => {
            remote.require('fs')
                .writeFile(TEMP_URL, img.toPng());
        });
Run Code Online (Sandbox Code Playgroud)

传入capturePage方法的第一个对象应该是绑定,但结果是输出图像的大小.

我已经检查win_size了CurrentWindow中WebContent的正确大小.

在此输入图像描述

在此输入图像描述

Fou*_*898 2

win.getSize()
Run Code Online (Sandbox Code Playgroud)

返回一个带有 的数组[width, height]。您将win_width变量分配给窗口的高度和win_height窗口的宽度。如果您更改这些值,可能会解决您的问题。

 const win_height = win_size[1];
 const win_width = win_size[0];
Run Code Online (Sandbox Code Playgroud)