gpt4 book ai didi

javascript - 使用Promises的BrowserWindow.capturePage()示例?

转载 作者:行者123 更新时间:2023-12-03 12:42:00 24 4
gpt4 key购买 nike

我正在尝试将Electron v 4.x.x项目更新为Electron的当前版本,并且脑子冻结了BrowserWindow.capturePage语法。

我捕获页面的方式如下。谁能给我一些关于如何更改它以使用capturePage promise语法(或仅作为语法示例)的意见吗?

更新:,经常提出问题以澄清问题。这似乎可行:

var img = await win.capturePage();

现有代码
var win = BrowserWindow.fromId(test.windowID);
var img = await saveScreen(win, needNewPage)
// do some stuff with the returned image
function saveScreen(win, needNewPage) {
return new Promise(resolve => {
win.capturePage((img) => {
resolve(img)
});
});
}

最佳答案

这是来自的capturePage的声明

Electron v3.1.0


    /**
* Captures a snapshot of the webview's page. Same as
* webContents.capturePage([rect, ]callback).
*/
capturePage(callback: (image: NativeImage) => void): void;
/**
* Captures a snapshot of the webview's page. Same as
* webContents.capturePage([rect, ]callback).
*/
capturePage(rect: Rectangle, callback: (image: NativeImage) => void): void;

这是从

Electron@latest(v7.1.8)


    /**
* Resolves with a NativeImage
*
* Captures a snapshot of the page within `rect`. Omitting `rect` will capture the
* whole visible page.
*/
capturePage(rect?: Rectangle): Promise<Electron.NativeImage>;

正如您在此处看到的,从某种程度上讲是 Electron 版本。我们不能在capturePage函数中使用回调。因此,我们能够将结果图像检索为回调参数。但是从新版本开始,我们只能使用 Promise

关于javascript - 使用Promises的BrowserWindow.capturePage()示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59849601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com