(action)
| 6 | * since background scripts don't have access to document |
| 7 | */ |
| 8 | export function validateActionXPath(action) { |
| 9 | // This is a background-safe validation that doesn't require DOM access |
| 10 | if (!action.xpath) return action; |
| 11 | |
| 12 | const xpaths = Array.isArray(action.xpath) ? action.xpath : [action.xpath]; |
| 13 | |
| 14 | // Clean up XPaths |
| 15 | const cleanedXpaths = xpaths.map(xpath => { |
| 16 | // Basic validation and cleanup |
| 17 | if (typeof xpath !== 'string') return ''; |
| 18 | |
| 19 | // Remove any extra whitespace |
| 20 | xpath = xpath.trim(); |
| 21 | |
| 22 | // Ensure XPath starts with / or // |
| 23 | if (!xpath.startsWith('/') && !xpath.startsWith('(')) { |
| 24 | xpath = '//' + xpath; |
| 25 | } |
| 26 | |
| 27 | return xpath; |
| 28 | }).filter(xpath => xpath.length > 0); |
| 29 | |
| 30 | return { |
| 31 | ...action, |
| 32 | xpath: cleanedXpaths |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Compare two actions to determine if they should be deduplicated |
no outgoing calls
no test coverage detected