Task Management
Learn how to create, monitor, and manage automated browser tasks using the Browserable JavaScript SDK.
Creating Tasks
Create a new task using the createTask
method:
Task Options
task
(required): Natural language description of what you want to automateagent
(optional): Agent to use (defaults to'BROWSER_AGENT'
)
Listing Tasks
Get a list of all your tasks with pagination support:
Managing Task Runs
List Task Runs
Get all runs for a specific task:
Check Run Status
Monitor the status of a task run:
Get Run Results
Retrieve the results of a completed run:
Wait for Run Completion
Wait for a task run to complete while monitoring its status:
This method combines status monitoring and result retrieval into a single convenient call. It will:
- Poll the task status at regular intervals
- Provide status updates through the
onStatusChange
callback - Automatically handle completion and error states
- Return the final result when the task completes
- Throw an error if the task times out or fails
Get Run GIF
Get the GIF recording of a task run. The GIF is automatically generated from browser screenshots taken during task execution:
The GIF generation is an asynchronous process that starts after a task run completes. The status field indicates:
pending
: GIF is being generatedcompleted
: GIF is ready and can be accessed via theurl
fielderror
: GIF generation failed, check theerror
field for details
Stopping Tasks
Stop a Task Run
Stop a specific run of a task:
Stop a Task
Stop a task from running future executions:
Error Handling
All methods return an ApiResponse
object with the following structure:
Example error handling:
Best Practices
- Task Description: Write clear, specific task descriptions
- Status Monitoring: Regularly check task status for long-running tasks
- Error Handling: Always handle errors and edge cases
- Resource Management: Stop unused tasks to free up resources
- Pagination: Use pagination for listing tasks and runs to manage large datasets