---
title: Best images
description: Find a page's main images, best first, each resolved to its largest known original URL through @howells/fieldwork-sdk/image.
---

`@howells/fieldwork-sdk/image` returns the images on a page, best first, each at its largest known original URL. It reads the page through your instance's `read` and renders it through its `act`, so every request goes through the provider; Fieldwork fetches nothing itself.

The instance needs a `read` that returns raw HTML with `format: "raw"` (Kernel or Browserbase) and an `act` that runs the Playwright render script (Kernel). Kernel has both on its own:

```ts
import { fieldwork } from "@howells/fieldwork-sdk";
import { kernel } from "@howells/fieldwork-sdk/kernel";
import { bestImages } from "@howells/fieldwork-sdk/image";

const web = fieldwork({ adapter: kernel() });
const result = await bestImages(web, "https://shop.example/linen-shirt", {
  limit: 5,
});

result.images[0]; // { url, verified, variants, width, height, measured, sources: ["img", "srcset"], score }
result.rendered; // true if the page was rendered in a browser
result.raw; // { read?, act[] }
```

Or pair Browserbase's HTML read with Kernel's browser render through a [router](/docs/router):

```ts
import { fieldwork, router } from "@howells/fieldwork-sdk";
import { browserbase } from "@howells/fieldwork-sdk/browserbase";
import { kernel } from "@howells/fieldwork-sdk/kernel";

const web = fieldwork({
  adapter: router({ read: browserbase(), act: kernel() }),
});
```

## Rendering modes

`render` controls when the page is rendered in the provider's browser to find JavaScript-loaded images and measure natural sizes:

- **`"auto"`** (default): reads HTML first and renders only when the read finds no image, its top pick has no size, or the top pick leads the next by less than 1.2×. Under `"auto"`, a render that fails after a read that found images returns the read's images with `rendered: false` and the failure (`FieldworkError`) as `renderError`; `meta` still counts the render.
- **`"never"`**: reads HTML only; never opens a browser.
- **`"always"`**: renders in a browser without reading HTML first.

Pages that stop responding, time out or crash the tab are rendered once more with other sites' scripts blocked (`meta.warnings` notes when that happens). `timeout` bounds the read and render together, `signal` cancels both, and `retries` applies to each call.

## Result and errors

- **`images`**: ranked by pixel area (measured, else declared, else CDN-encoded size), with the largest contentful paint weighted double (`"lcp"` in `sources`). SVGs, `data:` URLs, images in headers/navs/footers, and images known to be under 100px on a side are excluded. CDN resolution never fetches; unverified rewritten URLs carry `verified: false` with the page's own URL first in `variants`.
- **`rendered`** and **`renderError`**: whether the browser ran, and (under `"auto"`) any render failure after a usable HTML read.
- **`meta`** and **`raw`**: `meta` sums usage across every call and keeps `requestId` only when one call ran; `raw` keeps `raw.read` and `raw.act` (one entry per render attempt).
- **Errors**: an empty `images` array always means the page has no images. A 404 or 410 throws `NotFound`. Any other error status, empty HTML, a bot check (Cloudflare, PerimeterX, DataDome, reCAPTCHA, hCaptcha), an "Access Denied" page or a consent wall throws `ProviderError` (carrying `meta` for the calls so far). An invalid URL or `limit` throws `InvalidRequest` before any request is sent, and an `act` adapter other than Kernel throws `Unsupported` unless `render` is `"never"`.

## In agent tools and MCP

In `@howells/fieldwork-sdk/tools` and `@howells/fieldwork-mcp`, `bestImages` is exposed as `find_images` (read-only, not destructive). The tool accepts only `url`, `limit`, and `render` (plus `maxCharacters`) and strips `raw` from its result. Over stdio it is offered automatically whenever the server has Kernel (or Browserbase reading with `--act kernel`), even without `--allow-act`.

## Lower-level helpers

`@howells/fieldwork-sdk/image` also exports `collectImages`, `collectImagesSource`, `rankImages`, and `resolveOriginal` for working directly with DOM documents, page scripts, and image URLs.
