Multi-task workflows allow you to reuse a single browser session for multiple sequential tasks. This is more efficient than creating a new session for each task, as the browser state persists between tasks.When to use:
Multiple related tasks on the same website
Workflows that build on previous actions (e.g., login → search → checkout)
Scenarios where maintaining browser state (cookies, local storage) is important
For workflows that span multiple sessions (e.g., daily recurring tasks that need to stay logged in), use browser profiles to persist cookies and browser data between sessions.
When not to use:
Single, isolated tasks (use /start/run-task instead)
This example demonstrates a complete multi-task workflow: creating a session, sending multiple tasks, polling for results, and terminating the session.
Copy
const API_KEY = "YOUR_API_KEY";const BASE = "https://connect.webrun.ai";async function runMultiTaskWorkflow() { // 1. Create session const session = await fetch(`${BASE}/start/start-session`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${API_KEY}` }, body: JSON.stringify({ mode: "default", initialTask: { taskDetails: "Go to amazon.com", startingPoint: "https://amazon.com" } }) }).then(r => r.json()); console.log("Session created:", session.sessionId); // 2. Send follow-up task const task1 = await fetch(`${BASE}/start/send-message`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${API_KEY}` }, body: JSON.stringify({ sessionId: session.sessionId, message: { actionType: "newTask", newState: "start", taskDetails: "Search for 'wireless keyboard'" } }) }).then(r => r.json()); // 3. Poll if pending if (task1.pending) { const result = await pollForResult(session.sessionId, task1.taskId); console.log("Task 1 result:", result); } // 4. Send another task const task2 = await fetch(`${BASE}/start/send-message`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${API_KEY}` }, body: JSON.stringify({ sessionId: session.sessionId, message: { actionType: "newTask", newState: "start", taskDetails: "Add the first result to cart" } }) }).then(r => r.json()); if (task2.pending) { const result = await pollForResult(session.sessionId, task2.taskId); console.log("Task 2 result:", result); } // 5. Terminate when done await fetch(`${BASE}/start/send-message`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${API_KEY}` }, body: JSON.stringify({ sessionId: session.sessionId, message: { actionType: "state", newState: "terminate" } }) }); console.log("Session terminated");}async function pollForResult(sessionId, taskId) { const maxAttempts = 60; const interval = 2000; for (let i = 0; i < maxAttempts; i++) { const res = await fetch(`${BASE}/task/${sessionId}/${taskId}`, { headers: { "Authorization": `Bearer ${API_KEY}` } }); const data = await res.json(); if (data.type === "task_completed") return data; if (data.type === "guardrail_trigger") throw new Error(`Guardrail: ${data.data.value}`); if (data.status === "failed") throw new Error(data.error); if (data.pending) { await new Promise(r => setTimeout(r, interval)); continue; } return data; } throw new Error("Polling timeout");}runMultiTaskWorkflow();
When you only need to execute one task and don’t need session persistence:
Copy
curl -X POST https://connect.webrun.ai/start/run-task \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "taskDetails": "Search Google for Anthropic and return the first result" }'
Session automatically terminates when task completes