mirror of
https://github.com/kuaifan/dootask.git
synced 2026-07-01 20:05:05 +00:00
feat(ai-assistant): 采集器补 tabindex/ARIA 角色覆盖 + label 去重
借鉴 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) <noreply@anthropic.com>
This commit is contained in:
parent
88fed0744c
commit
bfa0920579
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user