Overview
Notification tasks are the core of hans.ai. They define:- What to monitor (URL)
- How to evaluate changes (evaluation function)
- When to check (schedule)
- What to do when conditions are met (actions)
Creating a Notification Task
Basic Structure
Evaluation Functions
Evaluation functions are JavaScript code that runs in the context of the monitored page. They determine whether to trigger actions.Simple Boolean Evaluation
Data Extraction with Schema
When you provide a Zod schema, the evaluation function should return data matching that schema:Stagehand Scripts
For complex interactions requiring browser automation, use Stagehand scripts:Task Execution
Manual Execution
Trigger a task immediately via API:Scheduled Execution
Tasks run automatically based on their cron schedule:*/5 * * * *- Every 5 minutes0 * * * *- Every hour0 0 * * *- Daily at midnight0 0 * * 1- Weekly on Monday0 0 1 * *- Monthly on the 1st
Execution Results
Each execution produces a result:Best Practices
Reliable Selectors
Use stable CSS selectors or data attributes that won’t break with minor UI changes
Error Handling
Include try-catch blocks in evaluation functions to handle missing elements gracefully
Efficient Schedules
Balance monitoring frequency with API limits and resource usage
Test First
Test evaluation functions manually before scheduling
Advanced Features
Conditional Actions
Trigger different actions based on evaluation results:Multi-Page Monitoring
Monitor multiple pages with a single task using Stagehand:Troubleshooting
Evaluation function returns undefined
Evaluation function returns undefined
Ensure your function explicitly returns a value. Use
return false instead of no return
statement.Selectors not finding elements
Selectors not finding elements
The page might be dynamically loaded. Use Stagehand scripts with
waitForSelector for dynamic
content.Task not executing on schedule
Task not executing on schedule
Check that the cron expression is valid and the task is active. Verify system time and timezone
settings.