I have a really long page inside a window (need to scroll to view all), when I try to capture the entire window using the code below, I get a squeezed image instead of full WebContent screenshot inside the CurrentWindow.
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());
});
I have also tried the following code but the result is the same,
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());
});
The first object passed in into capturePage
method should be the bound but turns out to be the size of the output image.
I have inspected the win_size
which is the correct size of the WebContent in the CurrentWindow.
win.getSize()
Returns an array with [width, height]
. You are assigning the win_width
variable to the height of the window and win_height
to the width of the window. If you change these values, this may resolve your issue.
const win_height = win_size[1];
const win_width = win_size[0];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With