Best images
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:
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:
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 withrendered: falseand the failure (FieldworkError) asrenderError;metastill 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"insources). 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 carryverified: falsewith the page’s own URL first invariants.renderedandrenderError: whether the browser ran, and (under"auto") any render failure after a usable HTML read.metaandraw:metasums usage across every call and keepsrequestIdonly when one call ran;rawkeepsraw.readandraw.act(one entry per render attempt).- Errors: an empty
imagesarray always means the page has no images. A 404 or 410 throwsNotFound. Any other error status, empty HTML, a bot check (Cloudflare, PerimeterX, DataDome, reCAPTCHA, hCaptcha), an “Access Denied” page or a consent wall throwsProviderError(carryingmetafor the calls so far). An invalid URL orlimitthrowsInvalidRequestbefore any request is sent, and anactadapter other than Kernel throwsUnsupportedunlessrenderis"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.