From 36b268f74caccb0ba5f25fe77d19320dd5954828 Mon Sep 17 00:00:00 2001 From: yu <1919727607@qq.com> Date: Thu, 5 Nov 2026 13:01:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=B6=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E8=B7=9F=E9=9A=8F=E5=89=8D=E5=8F=B0=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E9=A1=B5\n\n-=20=E7=82=B9=E6=90=9C=E7=B4=A2/=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E5=B8=B8=E5=BC=80=E6=96=B0=E6=A0=87=E7=AD=BE=E9=A1=B5?= =?UTF-8?q?,=20=E6=AD=A4=E5=89=8D=E8=BF=90=E8=A1=8C=E6=97=B6=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E6=93=8D=E4=BD=9C=E4=BB=8D=E9=99=84=E7=9D=80=E6=97=A7?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E9=A1=B5,\n=20=20=E5=AF=BC=E8=87=B4=E6=96=B0?= =?UTF-8?q?=E9=A1=B5=E4=B8=8A=E7=9A=84=E6=8B=BE=E5=8F=96=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=99=A8=E6=89=BE=E4=B8=8D=E5=88=B0=E5=85=83=E7=B4=A0=E3=80=81?= =?UTF-8?q?=E7=9B=B8=E4=BC=BC=E5=85=83=E7=B4=A0=E5=88=97=E8=A1=A8=E6=8A=93?= =?UTF-8?q?=E5=88=B0=E7=A9=BA\n-=20evaluate=20=E5=85=A5=E5=8F=A3=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=89=8D=E5=8F=B0=E6=A0=87=E7=AD=BE=E9=A1=B5=E6=A3=80?= =?UTF-8?q?=E6=9F=A5(400ms=20=E8=8A=82=E6=B5=81),=20=E5=8F=98=E5=8C=96?= =?UTF-8?q?=E6=97=B6=20activateTab=20=E5=88=87=E6=8D=A2=E9=99=84=E7=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/browser/session.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/browser/session.ts b/src/main/browser/session.ts index d32d4a6..8d446f2 100644 --- a/src/main/browser/session.ts +++ b/src/main/browser/session.ts @@ -192,7 +192,22 @@ export class BrowserSession implements BrowserLike { return this.transport.send(method, params); } + private lastFollowCheck = 0; + + /** 运行时跟随前台标签页:点按钮/搜索常开新标签页,元素操作应落在用户眼前看到的页面(节流 400ms) */ + private async followForegroundTab(): Promise { + 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(expression: string): Promise { + 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 }