feat: 完善RPA编排与本地能力接入
这个提交包含在:
1 父节点
6a2cc24898
当前提交
c03380168d
32 个文件已更改
+2763
-185
没有与搜索条件相匹配的文件
@@ -283,6 +283,33 @@ export class BrowserSession implements BrowserLike {
|
||||
return this.evaluate(script);
|
||||
}
|
||||
|
||||
async download(selector: unknown, folder: string, filename = "", timeoutMs = 10000): Promise<string> {
|
||||
const targetFolder = path.resolve(folder);
|
||||
await fs.mkdir(targetFolder, { recursive: true });
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
let settled = false;
|
||||
const browserSession = this.win.webContents.session;
|
||||
const onDownload = (_event: Electron.Event, item: Electron.DownloadItem) => {
|
||||
const target = path.join(targetFolder, filename || item.getFilename());
|
||||
item.setSavePath(target);
|
||||
item.once("done", (_doneEvent, state) => {
|
||||
if (state === "completed") finish(undefined, target);
|
||||
else finish(new RuntimeError("browser_error", `下载未完成:${state}`));
|
||||
});
|
||||
};
|
||||
const finish = (error?: Error, filePath?: string) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
browserSession.removeListener("will-download", onDownload);
|
||||
error ? reject(error) : resolve(filePath || "");
|
||||
};
|
||||
const timer = setTimeout(() => finish(new RuntimeError("timeout", `下载超时(${timeoutMs}ms)`)), timeoutMs);
|
||||
browserSession.once("will-download", onDownload);
|
||||
void this.click(selector).catch((error) => finish(error instanceof Error ? error : new Error(String(error))));
|
||||
});
|
||||
}
|
||||
|
||||
async screenshot(filePath: string): Promise<string> {
|
||||
const result = await this.cdp<{ data: string }>("Page.captureScreenshot", { format: "png" });
|
||||
const target = path.resolve(filePath);
|
||||
|
||||
在新工单中引用
屏蔽一个用户