Skip to content

Fix normalizeSelector to validate input type and reject arrays#24

Merged
konard merged 4 commits intomainfrom
issue-23-4ea2027e76ed
Jan 13, 2026
Merged

Fix normalizeSelector to validate input type and reject arrays#24
konard merged 4 commits intomainfrom
issue-23-4ea2027e76ed

Conversation

@konard
Copy link
Member

@konard konard commented Jan 13, 2026

Summary

  • Add input type validation to normalizeSelector to prevent downstream querySelectorAll errors
  • Return null with a warning for arrays and invalid object types
  • Only accept strings and valid Puppeteer text selector objects
  • Add comprehensive test coverage for the new validation behavior

Problem

When normalizeSelector received an array input (which should be invalid), it returned the array unchanged instead of throwing an error or returning null. This caused downstream querySelectorAll calls to fail with:

SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '[data-qa="vacancy-serp__vacancy_response"],' is not a valid selector

Solution

Added explicit type validation at the start of normalizeSelector:

  • Arrays are now detected and rejected with a warning
  • Non-string, non-_isPuppeteerTextSelector objects are rejected
  • Valid inputs (strings and Puppeteer text selector objects) continue to work as before

Test plan

  • Run npm run test:unit - all 368 tests pass
  • Run npm run lint - no new errors
  • Added tests for array, number, and invalid object rejection
  • Added test for valid Puppeteer text selector object acceptance

Fixes #23

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #23
@konard konard self-assigned this Jan 13, 2026
konard and others added 2 commits January 13, 2026 21:17
Previously, normalizeSelector had a fallback that returned any selector
unchanged if it didn't match expected types. This caused issues when
arrays were accidentally passed, leading to downstream querySelectorAll
errors with invalid selector syntax (trailing comma).

Changes:
- Add explicit type validation at the start of normalizeSelector
- Return null with a warning for arrays and invalid object types
- Only accept strings and valid Puppeteer text selector objects
- Add tests for array, number, and invalid object rejection
- Add test for valid Puppeteer text selector object acceptance

Fixes #23

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] normalizeSelector should validate input type and reject arrays Fix normalizeSelector to validate input type and reject arrays Jan 13, 2026
@konard konard marked this pull request as ready for review January 13, 2026 20:23
@konard
Copy link
Member Author

konard commented Jan 13, 2026

⚠️ Solution Draft Finished with Errors

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $3.432332 USD
  • Calculated by Anthropic: $0.000000 USD
  • Difference: $-3.432332 (-100.00%)

Note: The session encountered errors during execution, but some work may have been completed. Please review the changes carefully.

📎 Log file uploaded as Gist (518KB)
🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit 0cb3768 into main Jan 13, 2026
9 checks passed
konard added a commit to konard/hh-job-application-automation that referenced this pull request Jan 13, 2026
…#148

The v0.5.4 release of browser-commander (link-foundation/browser-commander#24)
adds input validation to normalizeSelector that rejects arrays and other
invalid types, preventing the trailing comma error in querySelectorAll.

This is the proper upstream fix for the issue we filed at:
link-foundation/browser-commander#23

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

normalizeSelector should validate input type and reject arrays

1 participant