Skip to content

feat: add isTimeoutError function for detecting timeout errors#10

Merged
konard merged 4 commits intomainfrom
issue-9-337c4cdf1be2
Dec 28, 2025
Merged

feat: add isTimeoutError function for detecting timeout errors#10
konard merged 4 commits intomainfrom
issue-9-337c4cdf1be2

Conversation

@konard
Copy link
Member

@konard konard commented Dec 28, 2025

Summary

  • Adds new isTimeoutError function to detect timeout errors from selector waiting operations
  • Exports the function from the main package entry point alongside isNavigationError
  • Includes 14 comprehensive unit tests covering various timeout error scenarios from both Playwright and Puppeteer

Why This Is Needed

Timeout errors are distinct from navigation errors and should be handled differently:

  • Navigation errors (isNavigationError): Page context destroyed, frame detached - usually unrecoverable for current operation
  • Timeout errors (isTimeoutError): Element not found within timeout - automation can continue with next item

Both functions are complementary and work together to provide robust error handling in browser automation.

Implementation Details

The function checks:

  1. Error name === 'TimeoutError' (most reliable)
  2. Error message patterns (case-insensitive): 'waiting for selector', 'timeout', 'timeouterror', 'timeout exceeded', 'timed out'

Usage Example

import { isNavigationError, isTimeoutError } from 'browser-commander';

try {
  await page.waitForSelector('.button', { timeout: 5000 });
} catch (error) {
  if (isTimeoutError(error)) {
    console.log('⚠️  Timeout error occurred while waiting for page elements');
    console.log('   The automation will continue with the next item');
  } else if (isNavigationError(error)) {
    console.log('Page navigation occurred during wait');
  } else {
    throw error;
  }
}

Test Plan

  • All 351 unit tests pass
  • ESLint checks pass (no errors in changed files)
  • Prettier formatting check passes
  • New isTimeoutError tests cover:
    • Null/undefined/empty error handling
    • Error name 'TimeoutError' detection
    • Various timeout message patterns
    • Case-insensitive matching
    • Not matching navigation errors (to avoid false positives)

Related

Fixes #9

🤖 Generated with Claude Code

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

Issue: #9
@konard konard self-assigned this Dec 28, 2025
konard and others added 2 commits December 28, 2025 05:07
Adds a new isTimeoutError function to detect timeout errors from selector
waiting operations. This complements isNavigationError and allows
automation loops to handle timeout errors gracefully without crashing.

The function checks:
- Error name === 'TimeoutError' (most reliable)
- Error message patterns like 'waiting for selector', 'timeout', 'timed out'

Includes 14 comprehensive unit tests covering various timeout error scenarios
from both Playwright and Puppeteer.

Closes #9

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add isTimeoutError function for detecting timeout errors feat: add isTimeoutError function for detecting timeout errors Dec 28, 2025
@konard konard marked this pull request as ready for review December 28, 2025 04:10
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard
Copy link
Member Author

konard commented Dec 28, 2025

🤖 Solution Draft Log

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

💰 Cost estimation:

  • Public pricing estimate: $3.075377 USD
  • Calculated by Anthropic: $1.925706 USD
  • Difference: $-1.149671 (-37.38%)
    📎 Log file uploaded as GitHub Gist (440KB)
    🔗 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 d669af7 into main Dec 28, 2025
8 checks passed
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.

Add isTimeoutError function for detecting timeout errors

1 participant