Webhooks

Instead of waiting on GET /v1/tasks/:id?wait=30, you can have the task call you when it finishes. Pass webhook_url when you create the task:

{
  "url": "https://example.com",
  "task": "Find the page's main heading.",
  "webhook_url": "https://your-app.example/hooks/browserwhale"
}

webhook_url follows the same URL rules as the start URL: a public http or https address. Use https in production.

The event

When the task reaches completed, partial, failed or cancelled, we send one POST with a JSON body:

{
  "id": "evt_9b2f0c1d4e5a6b7c8d9e0f1a2b3c4d5e",
  "type": "task.finished",
  "created_at": "2026-10-19T12:00:00.000Z",
  "data": { "id": "task_…", "status": "completed", "output": { "heading": "Example Domain" }, "…": "…" }
}

data is the task object, exactly as GET /v1/tasks/:id returns it.

When a task asks for your go-ahead before a step, we also send a task.waiting_for_confirmation event, in the same shape, with the task's confirmation set. Answer it before confirmation.expires_at. The task may have moved on by the time the event arrives; its current status is the one GET /v1/tasks/:id returns.

Header Value
Browserwhale-Webhook-Id The event id. The same on every delivery attempt.
Browserwhale-Webhook-Timestamp Unix seconds when this attempt was signed.
Browserwhale-Signature v1= and the hex HMAC-SHA256 of <timestamp>.<raw body>, keyed with your webhook secret.

Answering and retries

Answer with any 2xx status within 10 seconds. Anything else (another status, a timeout, a refused connection) is retried: after 10 s, 30 s, 2 min, 10 min, 30 min, 1 h and 2 h, so 8 attempts over about 3.5 hours. A Retry-After header on your answer delays the next attempt (up to an hour). Redirects are not followed.

The same event can arrive more than once, for example when your answer is lost. Keep the ids you have handled and ignore repeats.

Verifying the signature

Your webhook secret (whsec_…) is issued with your API key. Check every request before trusting it: compute the HMAC over the raw body, compare it in constant time, and reject timestamps older than a few minutes.

With the SDK:

import { verifyWebhook, WebhookVerificationError } from "@browserwhale/sdk";

// Express: use express.raw({ type: "application/json" }) so the body stays raw.
app.post("/hooks/browserwhale", async (req, res) => {
  try {
    const event = await verifyWebhook({
      payload: req.body.toString("utf8"),
      headers: req.headers,
      secret: process.env.BROWSERWHALE_WEBHOOK_SECRET!,
    });
    if (!(await alreadyHandled(event.id))) await handle(event.data);
    res.sendStatus(204);
  } catch (error) {
    if (error instanceof WebhookVerificationError) return res.sendStatus(400);
    throw error;
  }
});

Without it, in any language:

expected = "v1=" + hex(hmac_sha256(secret, timestamp + "." + raw_body))

Browserwhale-Signature may hold several signatures separated by spaces; the request is genuine if one of them matches.