UNPKG

chromancer

Version:

A powerful command-line interface for automating Chrome browser using Playwright. Perfect for web scraping, automation, testing, and browser workflows.

44 lines (43 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isTimeoutError = isTimeoutError; exports.formatErrorMessage = formatErrorMessage; exports.handleCommandError = handleCommandError; /** * Check if an error is a timeout error */ function isTimeoutError(error) { return (error.name === 'TimeoutError' || error.message.includes('TimeoutError') || error.message.includes('timeout') || error.message.includes('Timeout') || error.message.includes('Waiting failed')); } /** * Format error message with consistent structure */ function formatErrorMessage(action, message, selector, error) { if (error && isTimeoutError(error) && selector) { return `Timeout waiting for element: ${selector}`; } let formattedMessage = `Failed to ${action}: ${message}`; if (selector) { formattedMessage += ` (${selector})`; } return formattedMessage; } /** * Create a standardized command error */ function handleCommandError(error, action, selector) { const commandError = new Error(formatErrorMessage(action, error.message, selector, error)); commandError.action = action; commandError.selector = selector; commandError.originalError = error; commandError.isTimeout = isTimeoutError(error); // Preserve stack trace if (error.stack) { commandError.stack = error.stack; } return commandError; }