运行时元素操作跟随前台标签页\n\n- 点搜索/按钮常开新标签页, 此前运行时元素操作仍附着旧标签页,\n 导致新页上的拾取选择器找不到元素、相似元素列表抓到空\n- evaluate 入口增加前台标签页检查(400ms 节流), 变化时 activateTab 切换附着
This commit is contained in:
parent
21a400e172
commit
36b268f74c
@ -192,7 +192,22 @@ export class BrowserSession implements BrowserLike {
|
||||
return this.transport.send<T>(method, params);
|
||||
}
|
||||
|
||||
private lastFollowCheck = 0;
|
||||
|
||||
/** 运行时跟随前台标签页:点按钮/搜索常开新标签页,元素操作应落在用户眼前看到的页面(节流 400ms) */
|
||||
private async followForegroundTab(): Promise<void> {
|
||||
if (this.win || !this.httpBase) return;
|
||||
const now = Date.now();
|
||||
if (now - this.lastFollowCheck < 400) return;
|
||||
this.lastFollowCheck = now;
|
||||
const pages = await listPageTargets(this.httpBase).catch(() => []);
|
||||
const page = pages[0];
|
||||
if (!page || page.id === this.activeTargetId) return;
|
||||
await this.activateTab(page.id);
|
||||
}
|
||||
|
||||
private async evaluate<T = unknown>(expression: string): Promise<T> {
|
||||
await this.followForegroundTab().catch(() => {});
|
||||
const result = await this.cdp<{ result?: { value?: T }; exceptionDetails?: { exception?: { description?: string }; text?: string } }>(
|
||||
"Runtime.evaluate",
|
||||
{ expression, returnByValue: true, awaitPromise: true }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user