Run a browser task

Receive one bounded assignment, obtain local authorization, execute through the wrapper’s browser driver, and return ordered progress plus a structured result.

Executor example

This executor contains wrapper-owned browser behavior. The shared runtime sees only its capability, bounded work input, progress, result, and proof hook.

import {
  BodyExecutorRegistry,
  type BodyExecutor,
  type BrowserDriver,
} from "@tabworker/sdk";

export function registerBrowserTask(driver: BrowserDriver) {
  const executor: BodyExecutor = {
    capability: { namespace: "com.example", name: "browser_task", version: "1" },
    async execute(work, context) {
      await context.progress({ stage: "opening" });
      await driver.navigate(String(work.input.url));
      const page = await driver.inspect();
      return {
        result: { title: page.title ?? "", url: page.url },
        proofInput: { pageUrl: page.url },
      };
    },
  };
  const executors = new BodyExecutorRegistry();
  executors.register(executor);
  return executors;
}

States

StateAllowed next operationsWhat the wrapper owns
disconnectedconnectTransport construction and credentials
connectedpair, disconnectExisting pairing flow
pairedreceivePinnedWork, claimPinnedWork, disconnectHow pinned work is obtained
claimedauthorize, cancelLocal consent and authorization UI
authorizedstart, cancelFinal pre-execution checks
startedheartbeat, progress, complete, cancelDomain execution and proof creation
finisheddisconnectLocal cleanup and result retention

Progress and results

Progress sequences start at 1 and increase by one. Completion contains a structured JSON result and an opaque proof reference. The wrapper produces and stores proof material; acknowledgement is not review, payment, or settlement.

Cancellation

Cancellation is valid after claim, authorization, or start. Give the transport a bounded reason, stop local execution at a safe boundary, and disconnect. If execution throws, wrappers should attempt cancellation without hiding the primary error.

Reconnect and revoke

BodyRuntime retains the active assignment and last progress sequence across a bounded reconnect, then asks the brain to resume the same attempt. Revocation stops the node and must not allow later browser mutations or completion.