From bfa09205794650bd898d5f02a167f5fc1b205513 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 12 Jun 2026 08:18:24 +0000 Subject: [PATCH] =?UTF-8?q?feat(ai-assistant):=20=E9=87=87=E9=9B=86?= =?UTF-8?q?=E5=99=A8=E8=A1=A5=20tabindex/ARIA=20=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E8=A6=86=E7=9B=96=20+=20label=20=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 借鉴 browser-use clickable_elements 规则补齐页面元素采集边界: - 用已定义但闲置的 INTERACTIVE_ROLES 补全所有 ARIA 可交互角色选择器(原仅扫部分 role) - 选择器加 [tabindex]:not([tabindex="-1"]),捕捉自定义可聚焦/可交互元素 - 第二遍扫描跳过 label[for]/包裹控件的 label,避免与其表单控件重复采集 纯 DOM 增量、零风险(只多采不误删);真机验证无报错、label 去重生效。 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../components/AIAssistant/page-context-collector.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/resources/assets/js/components/AIAssistant/page-context-collector.js b/resources/assets/js/components/AIAssistant/page-context-collector.js index db457c162..8890214fd 100644 --- a/resources/assets/js/components/AIAssistant/page-context-collector.js +++ b/resources/assets/js/components/AIAssistant/page-context-collector.js @@ -302,6 +302,13 @@ export function collectElements(options = {}) { 'tr[onclick]', ]; + // 基于 INTERACTIVE_ROLES 补全所有 ARIA 可交互角色(与上面重复的选择器会被 querySelectorAll 按元素自动去重) + for (const role of INTERACTIVE_ROLES) { + selectors.push(`[role="${role}"]`); + } + // 可聚焦 / 自定义可交互元素(显式 tabindex 且非 -1) + selectors.push('[tabindex]:not([tabindex="-1"])'); + // 如果不仅限交互元素,添加内容元素选择器 if (!interactiveOnly) { selectors.push( @@ -339,6 +346,9 @@ export function collectElements(options = {}) { for (const el of potentialClickables) { if (processedElements.has(el)) continue; + // label[for] 或包裹表单控件的 label:点击等价于其控件(已单独采集),跳过避免重复 + if (el.tagName === 'LABEL' && (el.htmlFor || el.querySelector('input, textarea, select'))) continue; + // 检查是否有 cursor: pointer 样式 const computedStyle = (el.ownerDocument.defaultView || window).getComputedStyle(el); if (computedStyle.cursor !== 'pointer') continue;