feat: 接入网页批二——文件上传/多标签/窗口状态/停止加载/相似元素数组/弹窗自动关闭
这个提交包含在:
1 父节点
9b8bc0eb1a
当前提交
560134171f
4 个文件已更改
+128
-1
没有与搜索条件相匹配的文件
@@ -768,6 +768,58 @@ export class BrowserSession implements BrowserLike {
|
||||
return result.items;
|
||||
}
|
||||
|
||||
maximize(): void {
|
||||
if (!this.win.isDestroyed()) this.win.maximize();
|
||||
}
|
||||
|
||||
minimize(): void {
|
||||
if (!this.win.isDestroyed()) this.win.minimize();
|
||||
}
|
||||
|
||||
stopLoading(): void {
|
||||
if (!this.win.isDestroyed()) this.win.webContents.stop();
|
||||
}
|
||||
|
||||
async uploadFileToInput(selector: string, filePath: string): Promise<number> {
|
||||
const doc = await this.cdp<{ root?: { nodeId?: number } }>("DOM.getDocument");
|
||||
const rootNodeId = doc.root?.nodeId;
|
||||
if (!rootNodeId) throw new RuntimeError("browser_error", "无法定位页面 DOM 根节点");
|
||||
const css = selector.replace(/^css:/, "").trim();
|
||||
const found = await this.cdp<{ nodeId?: number }>("DOM.querySelector", { nodeId: rootNodeId, selector: css });
|
||||
if (!found.nodeId) {
|
||||
throw new RuntimeError("element_not_found", "未找到文件输入元素:" + css, { recommendation: "确认 input[type=file] 存在且已渲染" });
|
||||
}
|
||||
await this.cdp("DOM.setFileInputFiles", { files: [filePath], nodeId: found.nodeId });
|
||||
return found.nodeId;
|
||||
}
|
||||
|
||||
startAutoCloseDialogs(): boolean {
|
||||
if (!this.win.isDestroyed() && !this.win.webContents.debugger.isAttached()) this.win.webContents.debugger.attach("1.3");
|
||||
this.cdp("Page.enable").catch(() => {});
|
||||
const flags = globalThis as { __rpaAutoCloseDialogs?: boolean; __rpaAutoCloseDialogListener?: unknown };
|
||||
if (flags.__rpaAutoCloseDialogs) return false;
|
||||
flags.__rpaAutoCloseDialogs = true;
|
||||
const listener = (_event: unknown, method: string) => {
|
||||
if (method === "Page.javascriptDialogOpening") {
|
||||
this.cdp("Page.handleJavaScriptDialog", { accept: true }).catch(() => {});
|
||||
}
|
||||
};
|
||||
flags.__rpaAutoCloseDialogListener = listener;
|
||||
this.win.webContents.debugger.on("message", listener);
|
||||
return true;
|
||||
}
|
||||
|
||||
stopAutoCloseDialogs(): boolean {
|
||||
const flags = globalThis as { __rpaAutoCloseDialogs?: boolean; __rpaAutoCloseDialogListener?: unknown };
|
||||
if (!flags.__rpaAutoCloseDialogs) return false;
|
||||
if (flags.__rpaAutoCloseDialogListener) {
|
||||
this.win.webContents.debugger.removeListener("message", flags.__rpaAutoCloseDialogListener as never);
|
||||
}
|
||||
flags.__rpaAutoCloseDialogs = false;
|
||||
flags.__rpaAutoCloseDialogListener = undefined;
|
||||
return true;
|
||||
}
|
||||
|
||||
async currentUrl(): Promise<string> {
|
||||
return this.win.webContents.getURL();
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户