remove sensory tools
This commit is contained in:
160
daemon/daemon.go
160
daemon/daemon.go
@@ -2021,25 +2021,6 @@ func (d *Daemon) handleCommand(w http.ResponseWriter, r *http.Request) {
|
||||
response = Response{Success: true, Data: result}
|
||||
}
|
||||
|
||||
case "detect-sensory-characteristics":
|
||||
tabID := cmd.Params["tab"]
|
||||
timeoutStr := cmd.Params["timeout"]
|
||||
|
||||
// Parse timeout (default to 10 seconds)
|
||||
timeout := 10
|
||||
if timeoutStr != "" {
|
||||
if parsedTimeout, err := strconv.Atoi(timeoutStr); err == nil && parsedTimeout > 0 {
|
||||
timeout = parsedTimeout
|
||||
}
|
||||
}
|
||||
|
||||
result, err := d.detectSensoryCharacteristics(tabID, timeout)
|
||||
if err != nil {
|
||||
response = Response{Success: false, Error: err.Error()}
|
||||
} else {
|
||||
response = Response{Success: true, Data: result}
|
||||
}
|
||||
|
||||
case "detect-animation-flash":
|
||||
tabID := cmd.Params["tab"]
|
||||
timeoutStr := cmd.Params["timeout"]
|
||||
@@ -10330,147 +10311,6 @@ func (d *Daemon) analyzePageConsistency(tabID, url string, timeout int) (*PageCo
|
||||
return &analysis, nil
|
||||
}
|
||||
|
||||
// SensoryCharacteristicsResult represents the result of sensory characteristics detection
|
||||
type SensoryCharacteristicsResult struct {
|
||||
TotalElements int `json:"total_elements"`
|
||||
ElementsWithIssues int `json:"elements_with_issues"`
|
||||
Violations int `json:"violations"`
|
||||
Warnings int `json:"warnings"`
|
||||
Elements []SensoryCharacteristicsElement `json:"elements"`
|
||||
PatternMatches map[string]int `json:"pattern_matches"`
|
||||
}
|
||||
|
||||
// SensoryCharacteristicsElement represents an element with potential sensory-only instructions
|
||||
type SensoryCharacteristicsElement struct {
|
||||
TagName string `json:"tag_name"`
|
||||
Text string `json:"text"`
|
||||
MatchedPatterns []string `json:"matched_patterns"`
|
||||
Severity string `json:"severity"` // "violation", "warning"
|
||||
Recommendation string `json:"recommendation"`
|
||||
}
|
||||
|
||||
// detectSensoryCharacteristics detects instructions that rely only on sensory characteristics
|
||||
func (d *Daemon) detectSensoryCharacteristics(tabID string, timeout int) (*SensoryCharacteristicsResult, error) {
|
||||
d.debugLog("Detecting sensory characteristics for tab: %s", tabID)
|
||||
|
||||
page, err := d.getTab(tabID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get page: %v", err)
|
||||
}
|
||||
|
||||
// Define sensory characteristic patterns (WCAG 1.3.3)
|
||||
// These patterns indicate instructions that rely solely on sensory characteristics
|
||||
sensoryPatterns := map[string]string{
|
||||
"color_only": `(?i)\b(red|green|blue|yellow|orange|purple|pink|black|white|gray|grey)\s+(button|link|icon|text|box|area|section|field|item)`,
|
||||
"shape_only": `(?i)\b(round|square|circular|rectangular|triangle|diamond|star)\s+(button|link|icon|box|area|section|item)`,
|
||||
"size_only": `(?i)\b(large|small|big|tiny|huge)\s+(button|link|icon|text|box|area|section|field|item)`,
|
||||
"location_visual": `(?i)\b(above|below|left|right|top|bottom|beside|next to|under|over)\s+(the|this)`,
|
||||
"location_specific": `(?i)\b(click|tap|press|select)\s+(above|below|left|right|top|bottom)`,
|
||||
"sound_only": `(?i)\b(hear|listen|sound|beep|tone|chime|ring)\b`,
|
||||
"click_color": `(?i)\bclick\s+(the\s+)?(red|green|blue|yellow|orange|purple|pink|black|white|gray|grey)`,
|
||||
"see_shape": `(?i)\bsee\s+(the\s+)?(round|square|circular|rectangular|triangle|diamond|star)`,
|
||||
}
|
||||
|
||||
// JavaScript code to find all text elements and check for sensory patterns
|
||||
jsCode := `() => {
|
||||
const result = {
|
||||
elements: []
|
||||
};
|
||||
|
||||
// Find all elements with text content
|
||||
const textElements = document.querySelectorAll('p, span, div, label, button, a, li, td, th, h1, h2, h3, h4, h5, h6');
|
||||
|
||||
textElements.forEach(element => {
|
||||
const text = element.textContent.trim();
|
||||
if (text.length > 10 && text.length < 500) { // Reasonable text length
|
||||
result.elements.push({
|
||||
tagName: element.tagName.toLowerCase(),
|
||||
text: text
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return JSON.stringify(result);
|
||||
}`
|
||||
|
||||
jsResult, err := page.Eval(jsCode)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find text elements: %v", err)
|
||||
}
|
||||
|
||||
// Parse the JavaScript result
|
||||
var elementsData struct {
|
||||
Elements []struct {
|
||||
TagName string `json:"tagName"`
|
||||
Text string `json:"text"`
|
||||
} `json:"elements"`
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(jsResult.Value.Str()), &elementsData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse elements data: %v", err)
|
||||
}
|
||||
|
||||
result := &SensoryCharacteristicsResult{
|
||||
TotalElements: len(elementsData.Elements),
|
||||
Elements: make([]SensoryCharacteristicsElement, 0),
|
||||
PatternMatches: make(map[string]int),
|
||||
}
|
||||
|
||||
// Check each element against sensory patterns
|
||||
for _, elem := range elementsData.Elements {
|
||||
matchedPatterns := make([]string, 0)
|
||||
|
||||
for patternName, patternRegex := range sensoryPatterns {
|
||||
matched, _ := regexp.MatchString(patternRegex, elem.Text)
|
||||
if matched {
|
||||
matchedPatterns = append(matchedPatterns, patternName)
|
||||
result.PatternMatches[patternName]++
|
||||
}
|
||||
}
|
||||
|
||||
if len(matchedPatterns) > 0 {
|
||||
element := SensoryCharacteristicsElement{
|
||||
TagName: elem.TagName,
|
||||
Text: elem.Text,
|
||||
MatchedPatterns: matchedPatterns,
|
||||
}
|
||||
|
||||
// Determine severity
|
||||
criticalPatterns := []string{"color_only", "shape_only", "sound_only", "click_color", "see_shape"}
|
||||
isCritical := false
|
||||
for _, pattern := range matchedPatterns {
|
||||
for _, critical := range criticalPatterns {
|
||||
if pattern == critical {
|
||||
isCritical = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if isCritical {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if isCritical {
|
||||
element.Severity = "violation"
|
||||
element.Recommendation = "Provide additional non-sensory cues (e.g., text labels, ARIA labels, or position in DOM)"
|
||||
result.Violations++
|
||||
} else {
|
||||
element.Severity = "warning"
|
||||
element.Recommendation = "Review to ensure non-sensory alternatives are available"
|
||||
result.Warnings++
|
||||
}
|
||||
|
||||
result.Elements = append(result.Elements, element)
|
||||
result.ElementsWithIssues++
|
||||
}
|
||||
}
|
||||
|
||||
d.debugLog("Successfully detected sensory characteristics for tab: %s (elements: %d, issues: %d)",
|
||||
tabID, result.TotalElements, result.ElementsWithIssues)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// AnimationFlashResult represents the result of animation/flash detection
|
||||
type AnimationFlashResult struct {
|
||||
TotalAnimations int `json:"total_animations"`
|
||||
|
||||
Reference in New Issue
Block a user