# Browser

> Browsers: a browser an agent drives, and profiles that keep a person's logins.

```python
profile = noclick.BrowserProfile.from_name("ana-work", create_if_missing=True, user="user_42")
profile.login("https://portal.example.com", reason="to download your invoices").wait()

with noclick.Browser.create(profile=profile, timeout_s=900) as browser:
    browser.goto("https://portal.example.com/invoices")
    result = browser.act("Download every invoice from September")
    print(result.summary)
# closed on exit
```

A browser is Chromium in a sandbox, driven by a model that sees the page and
acts on it. NoClick solves the CAPTCHAs it can; when a page still needs a person
(a CAPTCHA it couldn't solve, a two-factor code), the browser parks, unbilled,
while that person finishes the step on a page NoClick sends them. A profile
keeps the sign-ins a person made once; when a site signs it out, the next
browser asks that person to sign in again the same way, and saves the new
sign-in. A profile counts as a credential, so it is never exported and only its
own user's browsers and agents use it.

## Browser

```typescript
class Browser
```

A running browser; it closes at `expiresAt`, or when you `close()` it.
Billed per minute while it runs, plus the model tokens `act` and `extract` use; time it waits on a
person is neither billed nor counted against `timeoutS`.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string` |  |
| `status` | `BrowserStatus` | `starting`, `running`, `parked` (waiting on a person, or an agent's browser waiting for its conversation's next turn), `closed` or `failed`. |
| `region` | `string | null` | Where it runs: its profile's region, else the one it was created in. |
| `profileId` | `string | null` | The profile it is signed in with (null if none). |
| `agentId` | `string | null` | The agent driving it, for an agent's browser. |
| `conversation` | `string | null` | The conversation it works in, for a browser an agent's turn started. |
| `actId` | `string | null` | Its newest `act`'s operation. |
| `acting` | `boolean` | Whether an `act` is driving it now. |
| `steps` | `BrowserWatchedStep[]` | The steps its newest `act` has taken so far. |
| `held` | `boolean` | Whether a person has taken it over (`takeOver`): its `act` waits until they hand it back. |
| `waitingOn` | `BrowserWaitingOn | null` | A step a person is asked to finish in it, while its `act` waits on them. |
| `liveUrl` | `string | null` | A NoClick page where you watch it live and can take over; it works while the browser runs, with no sign-in, so treat it like a password. Only a caller that may take the browser over reads it: your account's keys (one acting for a user too) and its signed-in owner. An MCP connection, an agent's turn and an app's code read null. |
| `url` | `string | null` | The page it is on. |
| `title` | `string | null` |  |
| `frameUrl` | `string | null` | A picture of the page it last stopped on (its `act`'s end, or its conversation's turn's), signed for an hour from each read; null before it first stopped. |
| `timeoutS` | `number | null` | How long it may run; parked time doesn't count. |
| `solveCaptchas` | `boolean | null` | Whether NoClick solves CAPTCHAs before asking a person. |
| `parkedS` | `number | null` | Seconds it has waited parked: not billed, not counted against `timeoutS`. |
| `costUsd` | `number | null` | What it has cost so far: minutes and model tokens. |
| `userId` | `string | null` |  |
| `createdAt` | `Date | null` |  |
| `startedAt` | `Date | null` | When it started running (null while it starts). |
| `expiresAt` | `Date | null` |  |
| `closedAt` | `Date | null` |  |

Types:

```typescript
/** `parked`: waiting on a person, or (an agent's browser) for its conversation's next turn; neither billed nor counted against `timeoutS`. */
type BrowserStatus = "starting" | "running" | "parked" | "closed" | "failed";
```

### Browser.create

```typescript
static create(options?: BrowserCreateOptions): Promise<Browser>
```

Start a browser; with `profile` it is signed in to the profile's sites and acts in the profile's user.

Parameters:

- `options.profile` (`BrowserProfile | string`): Signed in to this profile's sites; the browser acts in the profile's user, runs in its region and
saves new sign-ins into it when it closes. One such browser per profile at a time: a second throws
`Conflict` naming the first (`browser_id`).
- `options.timeoutS` (`number`): How long it may run: 300 by default, up to 3600; time waiting on a person doesn't count.
- `options.region` (`string`): Where it runs without a profile (`regions({ kind: "browser" })`); the account's default when omitted.
- `options.solveCaptchas` (`boolean`): NoClick solves the CAPTCHAs it can before asking a person (default); `false` for sites whose terms forbid it.
- `options.human` (`Human`): Who is asked when a page needs a person: the user by default, you for an account browser.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The browser, `running` on a blank page, with its `live_url`.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### Browser.fromId

```typescript
static fromId(browserId: string, options?: CallOptions): Browser
```

A lazy reference to a browser by id, for one you started earlier.

Parameters:

- `browserId` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.

Returns: A browser that loads the first time you read a field. Nothing is sent yet.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### Browser.get

```typescript
static get(browserId: string, options?: CallOptions): Promise<Browser>
```

Load a browser by id now; an unknown id raises `noclick.NotFound`.

Parameters:

- `browserId` (`string`, required)
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The browser, loaded: its `status`, the page it is on and its `live_url`.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### Browser.list

```typescript
static list(
  options?: ReadOptions & BrowserFilters & { limit?: number },
): Promise<Browser[]>
```

The current user's browsers, newest first: optionally one profile's, or an agent's (one `conversation`'s: an
agent's browser works in the conversation whose turn started it, one at a time); `status: "live"` lists those
starting, running or parked.

Parameters:

- `options.profile` (`BrowserProfile | string`)
- `options.status` (`BrowserStatus | "live"`)
- `options.agent` (`Agent | string`): An agent's browsers.
- `options.conversation` (`string`): One conversation's (with `agent`).
- `options.limit` (`number`): Return at most this many.
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: Every matching browser, newest first, fetched page by page. Agents' browsers are listed too.

Types:

```typescript
/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** `parked`: waiting on a person, or (an agent's browser) for its conversation's next turn; neither billed nor counted against `timeoutS`. */
type BrowserStatus = "starting" | "running" | "parked" | "closed" | "failed";
```

### Browser.listPage

```typescript
static listPage(
  options?: ReadOptions & PageOptions & BrowserFilters,
): Promise<Page<Browser>>
```

One page of browsers; pass `nextCursor` back as `cursor`.

Parameters:

- `options.cursor` (`string | null`): The `next_cursor` of the page before; omit it for the first page.
- `options.limit` (`number`): Return at most this many.
- `options.profile` (`BrowserProfile | string`)
- `options.status` (`BrowserStatus | "live"`)
- `options.agent` (`Agent | string`): An agent's browsers.
- `options.conversation` (`string`): One conversation's (with `agent`).
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: A page whose `data` holds the browsers and whose `next_cursor` is `None` on the last page.

Types:

```typescript
/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** `parked`: waiting on a person, or (an agent's browser) for its conversation's next turn; neither billed nor counted against `timeoutS`. */
type BrowserStatus = "starting" | "running" | "parked" | "closed" | "failed";
```

### Browser.goto

```typescript
goto(url: string): Promise<PageState>
```

Open `url` and wait for the page to load.

Parameters:

- `url` (`string`, required)

Returns: The page it landed on: its `url` after redirects and its `title`.

### Browser.act

```typescript
act(
  instruction: string,
  options: BrowserActOptions & { background: true },
): Promise<Operation<ActResult>>
act(
  instruction: string,
  options?: BrowserActOptions & { background?: false },
): Promise<ActResult>
```

Have the model carry out `instruction` on the page, with `files` downloaded into the browser first
for its forms. NoClick solves the CAPTCHAs it can, giving one half a minute; one still there, or a
two-factor prompt, parks the browser (not billed, not counted against its timeout) and sends a person
a page carrying the live view, and the step waits until they have dealt with it; so does the sign-in
page of a site whose saved sign-in expired, and the new sign-in is saved to the profile.
`{ background: true }` returns at once with an `Operation` whose `wait()` resolves to the `ActResult`.

Parameters:

- `instruction` (`string`, required)
- `options.background` (`boolean`, required): Return at once with an `Operation` whose `wait()` resolves to the `ActResult`.
- `options.maxSteps` (`number`): At most this many actions: 50 by default, up to 200.
- `options.files` (`string[]`): https URLs (a bucket's `signedUrl` works) NoClick downloads into the browser for the task's forms; up to 5.
- `options.timeoutS` (`number`): Seconds to wait here; the step keeps going after.

Returns: How it went: whether it's `done`, a `summary`, the `steps` it took, the `url`
it ended on and any `downloads`. With `background=True`, an `Operation` at once,
whose `wait()` gives that result.

### Browser.extract

```typescript
extract(query: string, options?: { schema?: JsonObject }): Promise<T>
```

Read what `query` describes off the page, shaped by `schema` (a JSON Schema) when you pass one.

Parameters:

- `query` (`string`, required)
- `options.schema` (`JsonObject`)

Returns: The data as JSON: an object or a list matching `schema`, or the model's own shape without one.

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### Browser.screenshot

```typescript
screenshot(options?: { fullPage?: boolean }): Promise<Uint8Array>
```

A PNG of the viewport, or the whole page with `fullPage`.

Parameters:

- `options.fullPage` (`boolean`)

Returns: The PNG's bytes.

### Browser.content

```typescript
content(options?: { format?: BrowserContentFormat }): Promise<string>
```

The page's content as markdown (default), text or html.

Parameters:

- `options.format` (`BrowserContentFormat`, default `"markdown"`)

Returns: The page's content in that format; markdown keeps headings, links and tables.

Types:

```typescript
type BrowserContentFormat = "markdown" | "text" | "html";
```

### Browser.takeOver

```typescript
takeOver(): Promise<void>
```

Take the browser over from its agent, as a person: it waits for you (unbilled), and an `act` in it stops at its
next step until you `handBack()`. Drive it from its `liveUrl`. Asked to finish a step in it (`waitingOn`), only
the person asked takes it over.

### Browser.handBack

```typescript
handBack(): Promise<void>
```

Hand the browser back: a step you were asked to finish counts as finished (as Done on its page does), and the
`act` waiting on you carries on; with nothing asked, it's the agent's again.

### Browser.liveView

```typescript
liveView(options?: BrowserViewOptions): Promise<BrowserLiveView>
```

A single-use token for the browser's live view, for a page of your own: `connect()` the result once, within two
minutes, or hand its `url` and `token` to the page from your server. `thumb`: smaller pictures for a tile.
`control`: a view that drives it, once you've taken it over (`takeOver`); it ends when it's handed back. Your
account's keys and its signed-in owner get one; an MCP connection, an agent's turn and an app's code don't.

Parameters:

- `options.control` (`boolean`): A view that drives the browser: it must be taken over (`takeOver`) first, and the view ends at its hand-back.
- `options.thumb` (`boolean`): Smaller pictures, at most two a second, for a tile. A view that drives the browser is full size.

Returns: The view: its `url` and its `token`, good once, within two minutes.

### Browser.close

```typescript
close(): Promise<void>
```

Close the browser now (billing stops with it). The profile keeps any new sign-ins.

### Browser.view

```typescript
view(
  options?: BrowserViewOptions & BrowserViewConnectOptions,
): BrowserViewConnection
```

Show the browser live in this page: asks for a token (`liveView`) and connects, and again with a new token
whenever the view needs to open again, until it ends or you `close()` it. See `BrowserViewConnection`.

Parameters:

- `options.control` (`boolean`): A view that drives the browser: it must be taken over (`takeOver`) first, and the view ends at its hand-back.
- `options.thumb` (`boolean`): Smaller pictures, at most two a second, for a tile. A view that drives the browser is full size.
- `options.onViewport` (`(viewport: BrowserViewport) => void`): The page's size, before its first picture and whenever it changes.
- `options.onPicture` (`(jpeg: Uint8Array) => void`): The page, as a JPEG.
- `options.onState` (`(state: BrowserViewState) => void`)
- `options.onEnd` (`(end: { code: number; reason: string }) => void`): It ended for good: the close code (`BROWSER_VIEW_CLOSE`), or 0 when asking for a token was refused.
- `options.WebSocket` (`typeof WebSocket`): A WebSocket class, where the runtime has none of its own (Node before 22).

Types:

```typescript
/** The size of the page the pictures show, in CSS pixels. */
interface BrowserViewport {
  width: number;
  height: number;
}

/** `connecting` until the first picture, `live` while pictures come (a view's renewal included), `ended` for good. */
type BrowserViewState = "connecting" | "live" | "ended";
```

## BrowserLiveView

```typescript
class BrowserLiveView
```

A browser's live view as `Browser.liveView` gives it: a single-use `token` for the websocket at `url`, valid two
minutes, for a page to `connect()` with (or for your server to hand to one). `Browser.view` asks for one and
connects, again and again as the view needs.

| Attribute | Type | Description |
| --- | --- | --- |
| `browserId` | `string` |  |
| `control` | `boolean` | Whether it drives the browser, not only watches it. |
| `thumb` | `boolean` | Smaller pictures, at most two a second, for a tile. |
| `url` | `string` | The view's websocket. |
| `token` | `string | null` | Opens `url` once, within two minutes: the socket's first message, `{"type": "auth", "token": ...}`. |
| `tokenExpiresAt` | `Date | null` |  |

### BrowserLiveView.connect

```typescript
connect(options?: BrowserViewConnectOptions): BrowserViewConnection
```

Open this view, once: it doesn't open again by itself (`Browser.view` does).

Parameters:

- `options.onViewport` (`(viewport: BrowserViewport) => void`): The page's size, before its first picture and whenever it changes.
- `options.onPicture` (`(jpeg: Uint8Array) => void`): The page, as a JPEG.
- `options.onState` (`(state: BrowserViewState) => void`)
- `options.onEnd` (`(end: { code: number; reason: string }) => void`): It ended for good: the close code (`BROWSER_VIEW_CLOSE`), or 0 when asking for a token was refused.
- `options.WebSocket` (`typeof WebSocket`): A WebSocket class, where the runtime has none of its own (Node before 22).

Types:

```typescript
/** The size of the page the pictures show, in CSS pixels. */
interface BrowserViewport {
  width: number;
  height: number;
}

/** `connecting` until the first picture, `live` while pictures come (a view's renewal included), `ended` for good. */
type BrowserViewState = "connecting" | "live" | "ended";
```

## BrowserProfile

```typescript
class BrowserProfile
```

Saved sign-ins for one person.
`BrowserProfile.fromName("ana-work", { createIfMissing: true, user: "user_42" })` is lazy;
`profile.login(url)` asks the person to sign in once, and browsers started with the profile are signed in.
Its `region` is where its browsers run; its sign-ins are kept in the US whatever the region.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string` |  |
| `name` | `string` |  |
| `region` | `string | null` | Where its browsers run, fixed when it is created. |
| `userId` | `string | null` |  |
| `lastUsedAt` | `Date | null` | When a browser last used it (null if never). |
| `createdAt` | `Date | null` |  |
| `sites` | `SiteLogin[]` | The sites it is signed in to, most recently signed in first (throws until hydrated). |

### BrowserProfile.create

```typescript
static create(
  name: string,
  options?: CallOptions & AllowExisting & { region?: string },
): Promise<BrowserProfile>
```

Create an empty profile called `name` (unique per user; a duplicate throws `Conflict` with
`existingId`, or with `allowExisting: true` returns the profile already there, signed in where it
was). `region` is where its browsers run (`regions({ kind: "browser" })`; the account's default when
omitted), fixed for its life; its sign-ins are kept in the US.

Parameters:

- `name` (`string`, required)
- `options.region` (`string`)
- `options.allowExisting` (`boolean`): A taken name returns the object already there, as it is: nothing about it changes.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The new profile, signed in nowhere yet.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### BrowserProfile.fromName

```typescript
static fromName(
  name: string,
  options?: CallOptions & { createIfMissing?: boolean; region?: string },
): BrowserProfile
```

A lazy reference to the profile called `name`; with `createIfMissing` it's created, empty, on
first use, in `region` when you pass one.

Parameters:

- `name` (`string`, required)
- `options.createIfMissing` (`boolean`, default `false`)
- `options.region` (`string`)
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: A profile that loads, or is created, the first time it's used. Nothing is sent yet.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### BrowserProfile.fromId

```typescript
static fromId(profileId: string, options?: CallOptions): BrowserProfile
```

A lazy reference to a profile by id.

Parameters:

- `profileId` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.

Returns: A profile that loads the first time you read a field. Nothing is sent yet.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### BrowserProfile.get

```typescript
static get(profileId: string, options?: CallOptions): Promise<BrowserProfile>
```

Load a profile by id now; an unknown id raises `noclick.NotFound`.

Parameters:

- `profileId` (`string`, required)
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The profile, loaded, with the `sites` it is signed in to.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### BrowserProfile.list

```typescript
static list(
  options?: ReadOptions & { limit?: number },
): Promise<BrowserProfile[]>
```

The current user's profiles (the account's own outside `asUser`, or those `userFilter` covers).

Parameters:

- `options.limit` (`number`): Return at most this many.
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: Every matching profile, newest first, fetched page by page, each with its `sites`.

Types:

```typescript
/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;
```

### BrowserProfile.listPage

```typescript
static listPage(
  options?: ReadOptions & PageOptions,
): Promise<Page<BrowserProfile>>
```

One page of profiles; pass `nextCursor` back as `cursor`.

Parameters:

- `options.cursor` (`string | null`): The `next_cursor` of the page before; omit it for the first page.
- `options.limit` (`number`): Return at most this many.
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: A page whose `data` holds the profiles and whose `next_cursor` is `None` on the last page.

Types:

```typescript
/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;
```

### BrowserProfile.login

```typescript
login(
  url: string,
  options?: { human?: Human; reason?: string },
): Promise<BrowserLogin>
```

Ask a person to sign in to the site at `url` in a live browser; the sign-in is saved to this
profile. `human` is who is asked: the profile's user when omitted (an account profile with
no `human` sends nothing, so pass the link's `url` on yourself). `await login.wait()`
resolves to the `SiteLogin`. You ask once: when the site signs the profile out, the browser that
meets its sign-in page asks the same person again (`SiteLogin.signedInBy`). The link's browser
starts (and is billed) only once the person opens it.

Parameters:

- `url` (`string`, required)
- `options.human` (`Human`)
- `options.reason` (`string`)

Returns: The sign-in link, already sent: its `url`, when it `expires_at` (in
24 hours) and where it went. `wait()` returns the `SiteLogin` once the person has signed in.

### BrowserProfile.forget

```typescript
forget(domain: string): Promise<void>
```

Sign the profile out of `domain` and drop what it and its subdomains stored. A short browser
(about a minute, billed like any) clears them and saves the profile; this resolves once it has.
It throws `Conflict` (naming the browser) while another browser saves into the profile, and a
browser already using the profile keeps the old state until it closes.

Parameters:

- `domain` (`string`, required)

### BrowserProfile.delete

```typescript
delete(): Promise<void>
```

Delete the profile and every sign-in in it.

## BrowserLogin

```typescript
class BrowserLogin extends Operation
```

A live-browser link where a person signs in to a site, and the
operation that finishes once they have: `await login.wait()` resolves to the `SiteLogin`.

| Attribute | Type | Description |
| --- | --- | --- |
| `url` | `string` | The page where the person signs in, in a live browser. |
| `expiresAt` | `Date | null` |  |
| `domain` | `string | null` | The site's domain. |
| `deliveredVia` | `string[]` | Channels the link went out on (`["email"]`); empty when nobody was sent it. |
| `undelivered` | `JsonObject[]` | Channels that failed, each with a `reason`: send the link yourself. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### BrowserLogin.list

```typescript
static list(
  options?: KindScopedFilters & { limit?: number },
): Promise<Operation<SiteLogin>[]>
```

Sign-in operations (kind `browser.login`), newest first.

Parameters:

- `options.limit` (`number`): Return at most this many.
- `options.client` (`NoClick`)
- `options.user` (`UserOption`): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.status` (`OperationStatus | "live" | readonly (OperationStatus | "live")[]`): Statuses, or `"live"` for every non-terminal one.
- `options.agent` (`string | ApiObject`): An `Agent` or agent id.
- `options.statusNot` (`OperationStatus | readonly OperationStatus[]`)
- `options.key` (`string`): The requesting key: its id or its prefix (`nk_live_ab12`).
- `options.createdAfter` (`Date | string`)
- `options.createdBefore` (`Date | string`)
- `options.updatedAfter` (`Date | string`): Rows changed since (for polling).
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).

Returns: Every matching operation (or the first `limit`); `wait()` on one returns the `SiteLogin`.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

type OperationStatus =
  | "queued" | "running" | "awaiting_human"
  | "succeeded" | "failed" | "canceled" | "expired";

/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;
```

### BrowserLogin.listPage

```typescript
static listPage(
  options?: KindScopedFilters & PageOptions,
): Promise<Page<Operation<SiteLogin>>>
```

One page of sign-in operations; pass `nextCursor` back as `cursor`.

Parameters:

- `options.cursor` (`string | null`): The `next_cursor` of the page before; omit it for the first page.
- `options.limit` (`number`): Return at most this many.
- `options.client` (`NoClick`)
- `options.user` (`UserOption`): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.status` (`OperationStatus | "live" | readonly (OperationStatus | "live")[]`): Statuses, or `"live"` for every non-terminal one.
- `options.agent` (`string | ApiObject`): An `Agent` or agent id.
- `options.statusNot` (`OperationStatus | readonly OperationStatus[]`)
- `options.key` (`string`): The requesting key: its id or its prefix (`nk_live_ab12`).
- `options.createdAfter` (`Date | string`)
- `options.createdBefore` (`Date | string`)
- `options.updatedAfter` (`Date | string`): Rows changed since (for polling).
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).

Returns: A page whose `data` holds the operations and whose `next_cursor` is `None` on the last page.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

type OperationStatus =
  | "queued" | "running" | "awaiting_human"
  | "succeeded" | "failed" | "canceled" | "expired";

/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;
```

### BrowserLogin.summary

```typescript
static summary(options?: KindScopedFilters): Promise<OperationSummary>
```

How many sign-in operations match, by status.

Parameters:

- `options.client` (`NoClick`)
- `options.user` (`UserOption`): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.status` (`OperationStatus | "live" | readonly (OperationStatus | "live")[]`): Statuses, or `"live"` for every non-terminal one.
- `options.agent` (`string | ApiObject`): An `Agent` or agent id.
- `options.statusNot` (`OperationStatus | readonly OperationStatus[]`)
- `options.key` (`string`): The requesting key: its id or its prefix (`nk_live_ab12`).
- `options.createdAfter` (`Date | string`)
- `options.createdBefore` (`Date | string`)
- `options.updatedAfter` (`Date | string`): Rows changed since (for polling).
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).

Returns: The `total` that match and a count for every status in `by_status`.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

type OperationStatus =
  | "queued" | "running" | "awaiting_human"
  | "succeeded" | "failed" | "canceled" | "expired";

/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;
```

## PageState

```typescript
interface PageState
```

Where the browser is: the page's `url` (after redirects) and `title`.

| Attribute | Type | Description |
| --- | --- | --- |
| `url` | `string | null` |  |
| `title` | `string | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## ActResult

```typescript
interface ActResult
```

How an `act` went: `done` is false when it ran out of steps or couldn't go on (`summary` says why).

| Attribute | Type | Description |
| --- | --- | --- |
| `done` | `boolean` |  |
| `summary` | `string` |  |
| `steps` | `BrowserActStep[]` |  |
| `url` | `string | null` |  |
| `downloads` | `BrowserDownload[]` |  |
| `costUsd` | `number | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
/** One action an `act` took. */
interface BrowserActStep {
  /** `click`, `type`, `scroll`, `goto`, `download`, `wait_for_person`, ... */
  action: string;
  detail: string | null;
  url: string | null;
  /** The element it acted on, as the page names it (a field's label, a button's text); never what it typed. */
  target: string | null;
}

/** A file an `act` saved. `url` is signed and valid for an hour. */
interface BrowserDownload {
  name: string;
  sizeBytes: number | null;
  url: string;
}

type JsonObject = { [key: string]: unknown };
```

## SiteLogin

```typescript
interface SiteLogin
```

A site a profile is signed in to. When the site signs the profile out, the next browser that meets
its sign-in page asks `signedInBy` to sign in again in the live view, as for a two-factor code,
and saves the new sign-in.

| Attribute | Type | Description |
| --- | --- | --- |
| `domain` | `string` |  |
| `signedInAt` | `Date | null` |  |
| `signedInBy` | `string | null` | The email of the person who signed in (the one `login` asked), and who is asked again when the sign-in expires; null for a link you passed on yourself, and then the browser's `human` is asked. |
| `lastUsedAt` | `Date | null` | When a browser last used the sign-in (null if never). |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## BrowserWatchedStep

```typescript
interface BrowserWatchedStep
```

A step of a browser's newest `act`, as a person watching it is told: what it did and to what, never what it typed.

| Attribute | Type | Description |
| --- | --- | --- |
| `action` | `string` |  |
| `target` | `string | null` |  |
| `at` | `Date | null` |  |

## BrowserWaitingOn

```typescript
interface BrowserWaitingOn
```

A step a person is asked to finish in the browser: its `act` waits on them.

| Attribute | Type | Description |
| --- | --- | --- |
| `person` | `string` | What they're asked to do, in a sentence. |
| `forYou` | `boolean` | Whether it's you they asked: only that person takes the browser over and hands it back. |
