Merge pull request #960 from Ryan0204/main

bug fix: screenshot in transparent website
This commit is contained in:
Mohammad S 2023-06-17 18:40:09 +05:30 committed by GitHub
commit 3fd5e7e4be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,11 +22,28 @@ export interface ScreenshotAllArgs {
export interface ScreenshotResult {
done: boolean;
}
const captureImage = async (
webContentsId: number
): Promise<Electron.NativeImage | undefined> => {
const Image = await webContents.fromId(webContentsId)?.capturePage();
const WebContents = webContents.fromId(webContentsId);
const isExecuted = await WebContents?.executeJavaScript(`
if (window.isExecuted) {
true;
}
`);
if (!isExecuted) {
await WebContents?.executeJavaScript(`
const bgColor = window.getComputedStyle(document.body).backgroundColor;
if (bgColor === 'rgba(0, 0, 0, 0)') {
document.body.style.backgroundColor = 'white';
}
window.isExecuted = true;
`);
}
const Image = await WebContents?.capturePage();
return Image;
};