Skip to main content

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:
With corresponding Zod 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:
Common cron patterns:
  • */5 * * * * - Every 5 minutes
  • 0 * * * * - Every hour
  • 0 0 * * * - Daily at midnight
  • 0 0 * * 1 - Weekly on Monday
  • 0 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

Ensure your function explicitly returns a value. Use return false instead of no return statement.
The page might be dynamically loaded. Use Stagehand scripts with waitForSelector for dynamic content.
Check that the cron expression is valid and the task is active. Verify system time and timezone settings.