If you're building an AI agent in TypeScript with Playwright or similar — i.e. anything that navigates to a URL and clicks stuff to move through a workflow and extract structured data — you've probably wondered: how do I make my LLM actually "see" the page? Old-school scraper devs will tell you to strip <script> and <style> tags and pass the rest of the DOM. Framework authors will tell you to pass Playwright's Accessibility Tree (ARIA snapshot) instead. You could also just take a screenshot (JPEG/PNG), and let a Vision LLM (like Gemma 4) figure it out.
Let's benchmark these three head-to-head, and find out which works the best. For this, I had to use Scraping Browser, Web Unlocker, and Residential Proxies from Bright Data so our benchmarking agent wouldn't HTTP 403 out.
TL;DR: Screenshots + Vision AI is great for reading a page, but terrible for interactions — while raw HTML is too bloated for either. The best way to build an AI browser agent is the Set-of-Marks approach (combining a screenshot with numbered button tags so the AI picks a button by number, and not guesswork on pixels), and using it with proxies to get past anti-bot walls.
All The Ways an AI Agent Can "See" a Webpage
With a ~1 MB modern webpage (like Canva, Zillow, or Discogs), you can't just dump the raw HTML string into your prompt. Unless you enjoy burning 150,000 tokens per click, I guess. 🙃
To see what actually works, I tested the three standard ways developers feed a webpage to an LLM — plus two hybrid approaches that tag buttons with numbered IDs so the model doesn't have to guess selectors or pixels:
- 1. Pruned DOM HTML: Keeping only
<main>, with all<script>,<style>, and<svg>tags stripped out. - 2. Playwright ARIA Snapshot: Passing the browser's Accessibility Tree formatted as YAML.
- 3. Pure Vision Screenshot: Passing a clean 1280x900 JPEG screenshot and asking the vision model to guess
(x, y)click coordinates. - 4. Numbered Controls + ARIA: Giving the model a numbered list of visible buttons alongside the ARIA YAML.
- 5. Set-of-Marks (SoM) Vision: Drawing numbered red boxes directly onto the JPEG screenshot and passing the matching button list.
I ran all five modes through a local multimodal Gemma 4 12B vision-capable setup served via LM Studio with strict JSON schema outputs enabled (zero temperature).
On each page, the model had to perform two tasks per turn:
- Read & Extract: Pull structured facts from the page (album tracklists on Discogs, property valuation specs on Zillow, and template categories on Canva).
- Click Interactive Action Targets: Identify the exact button to click next (
Edit Master Releaseon Discogs,Shareon Zillow, andLog inon Canva).
Here is how all five modes scored across the three websites:
| Page Representation Mode | Avg Prompt Tokens | Token Savings vs. DOM | Avg Step Latency | Data Extraction Accuracy | Button Click Accuracy |
|---|---|---|---|---|---|
1. Pruned DOM HTML (<main>) | 10,785 tok | Baseline (0%) | 6,930 ms | 12 / 15 (80.0%) | 2 / 3 (66.7%) |
| 2. Playwright ARIA Snapshot | 3,289 tok | 69.5% | 3,583 ms | 14 / 15 (93.3%) | 3 / 3 (100%) |
| 3. Pure Vision Screenshot (1280x900) | 558 tok | 94.8% | 2,493 ms | 15 / 15 (100%) | 0 / 3 (0.0%) |
| 4. Numbered Controls + ARIA | 2,619 tok | 75.7% | 3,150 ms | 14 / 15 (93.3%) | 3 / 3 (100%) |
5. Set-of-Marks Vision (Screenshot + [id] Map) | 765 tok | 92.9% | 2,569 ms | 15 / 15 (100%) | 3 / 3 (100%) |
Let's get into the whys and wherefores of these numbers.
Takeaway 1: Vision LLMs Are Great At Reading, But Fail At Interacting With The Page
Giving a multimodal LLM a screenshot is by far the fastest and cheapest way to read a webpage, but asking that same model to guess (x, y) pixel coordinates to interact with anything fails every time.
When you look at a complex page visually, it is easy to see why a screenshot beats raw HTML for reading data.
On Discogs (I used the page for Radiohead's OK Computer), all the album metadata and tracklist titles are right in the center of the viewport. The vision model did exactly what it was supposed to on a 1280x900 JPEG screenshot, using just 556 prompt tokens to extract 5 out of 5 fields without breaking a sweat.
So why did it fail completely when asked to actually click a button?
Look at the exact pixel coordinates the vision model guessed vs. where the buttons actually were on the 1280x900 canvas:
| Target Website & Category | Target Button | Actual Button Bounding Box (x, y) | Pure Vision (x, y) Guess | Pixel Miss Distance |
|---|---|---|---|---|
| 1. Discogs (E-Commerce & Media) | Edit Master Release | x: 885..1011, y: 165..181 (center 948, 173) | 758, 176 | Off by 190 px (Missed left) |
| 2. Zillow (Real Estate Dashboard) | Share | x: 1050..1108, y: 23..45 (center 1079, 34) | 847, 41 | Off by 232 px (Missed left) |
| 3. Canva (SaaS Search Portal) | Log in | x: 1168..1232, y: 24..56 (center 1200, 40) | 941, 38 | Off by 259 px (Missed left) |
Notice a pattern?
On all three pages, the vision LLM got the vertical y coordinate almost spot-on (176 vs 173, 41 vs 34, 38 vs 40) — and missed the horizontal x coordinate by 190 to 259 pixels to the left every single time! How curious.
Why does this happen? Because vision encoders resize and patch-tile 1280x900 screenshots internally (for example, scaling images into normalized square grids or 768x768 patches) before the language model ever sees them. The model knows where the button is visually (y is near the top, x is on the right side), so it estimates an x value around 750–940...and that is actually empty whitespace 200 pixels to the left of the actual 1280px button.
This was getting really interesting, now! If I hadn't gotten curious and did this benchmark, I'd have never known vision LLMs did this.
Takeaway 2: Why Pruned DOM HTML and ARIA Snapshots Struggle on Heavy Pages
Even if you strip out scripts, styles, and SVGs, modern webpage HTML is still way too big for an agent loop — and CSS-in-JS class names make selector clicking unreliable.
If you ask an LLM to read pruned <main> HTML and output a CSS selector to click, two very bad things happen:
- Nested layout wrappers push real data out of your context budget: On Discogs, even after stripping every
<script>,<style>, and<svg>tag from the 647 KB page, the remaining<main>HTML was still 133,238 characters of nested<div>wrappers. Truncating that HTML to fit a reasonable prompt budget cut off the tracklist, causing the model to hallucinate"Eeny"(???) as the first track instead of"Airbag". On Canva's Templates portal,<main>was even worse: 637,342 characters, costing 12,152 prompt tokens and 7.2 seconds for a single turn. - Modern frameworks obfuscate class names: On Discogs, as an example, the
Edit Master Releaselink uses a compiled CSS module class:<a class="link_PKPcS">. If an agent tries to click it, it will return".link_PKPcS"— a generic styling class shared by dozens of unrelated links on the page.
Switching to Playwright's Accessibility Tree (ariaSnapshot) improved things dramatically — cutting tokens by 69.5% (3,289 tokens avg.) and matching all 3 buttons by their semantic role and name (button Share, button Log in).
Still, on link-heavy sites like Discogs and Canva, the Accessibility Tree alone can be 24K-26K characters (that's 3,329 to 5,975 tokens) because, understandably, screen-reader trees dutifully list every single header, sidebar, and footer link on the page.
So we have our task cut out for us. Can we get the 558-token speed and 100% visual reading accuracy of a screenshot without the 200-pixel coordinate miss?
Takeaway 3: How Set-of-Marks (SoM) Fixes Both Reading and Clicking
Instead of asking a vision LLM to do pixel math, draw numbered red boxes around visible buttons before taking the screenshot. The model will read the page visually and pick the badge numbers, and your Playwright script will click the exact button with zero pixel error.
Look at how a webpage looks to the model when we use Set-of-Marks (SoM):

We draw a red bounding box (and a numbered badge) around every clickable link, button, or input inside the viewport. Instead of guessing where Edit Master Release sits in 1280x900 pixel space, the model will only have to look at badge number [14] on the right sidebar and pick it by number.
It works the exact same way on dense dashboards like Zillow (where Share is tagged as [4] in the top-right bar) and SaaS portals like Canva (where Log in is tagged as [3]):


You can build this in Playwright in ~50 lines of TypeScript.
Before calling page.screenshot(), run a quick page.evaluate() pass that finds visible interactive elements in the viewport, draws the red numbered overlay in the DOM, and returns each element's exact center (x, y) coordinates to Node.js:
import type { Page } from "playwright";
export interface InteractiveControl {
id: number;
tag: string;
text: string;
x: number;
y: number;
}
export async function captureSetOfMarks(page: Page): Promise<{
screenshotBase64: string;
controls: InteractiveControl[];
compactList: string;
}> {
const controls = await page.evaluate((): InteractiveControl[] => {
const candidates = Array.from(
document.querySelectorAll(
'a, button, input, select, textarea, [role="button"], [role="link"], [role="tab"]'
)
);
const items: InteractiveControl[] = [];
const overlay = document.createElement("div");
overlay.id = "__som_overlay__";
overlay.style.cssText =
"position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:2147483647;";
document.body.appendChild(overlay);
let id = 1;
for (const el of candidates) {
const rect = el.getBoundingClientRect();
if (rect.width < 12 || rect.height < 12 || rect.top < 0 || rect.top > 880) continue;
const style = window.getComputedStyle(el);
if (style.visibility === "hidden" || style.display === "none" || Number(style.opacity) === 0) {
continue;
}
const text = (
el.textContent ||
el.getAttribute("aria-label") ||
el.getAttribute("placeholder") ||
""
)
.trim()
.replace(/\s+/g, " ")
.slice(0, 65);
if (!text) continue;
const cx = Math.round(rect.left + rect.width / 2);
const cy = Math.round(rect.top + rect.height / 2);
if (items.some((p) => Math.abs(p.x - cx) < 8 && Math.abs(p.y - cy) < 8)) continue;
items.push({ id, tag: el.tagName.toLowerCase(), text, x: cx, y: cy });
const box = document.createElement("div");
box.style.cssText = `position:fixed;left:${Math.round(rect.left)}px;top:${Math.round(rect.top)}px;width:${Math.round(rect.width)}px;height:${Math.round(rect.height)}px;border:2px solid #ef4444;background:rgba(239,68,68,0.08);`;
const badge = document.createElement("span");
badge.textContent = `[${id}]`;
badge.style.cssText =
"position:absolute;top:-16px;left:-2px;background:#ef4444;color:#fff;font:bold 11px/14px monospace;padding:0 3px;";
box.appendChild(badge);
overlay.appendChild(box);
if (++id > 75) break;
}
return items;
});
const buf = await page.screenshot({ type: "jpeg", quality: 82 });
await page.evaluate(() => document.getElementById("__som_overlay__")?.remove());
return {
screenshotBase64: buf.toString("base64"),
controls,
compactList: controls.map((c) => `[${c.id}] <${c.tag}> "${c.text}"`).join("\n"),
};
}
When the LLM returns its chosen actionTarget ID, you simply look up the matching control in controls and call await page.mouse.click(control.x, control.y).
Look at what Set-of-Marks (setOfMarksVision) achieved across all three sites:
- 15 / 15 (100%) extraction accuracy and 3 / 3 (100%) click accuracy.
- 765 average prompt tokens — a 92.9% reduction compared to Pruned DOM (10,785 tokens) and 4.3x fewer tokens than a raw Playwright Accessibility Tree (3,289 tokens).
- 2.57 seconds average step time (versus 6.93 seconds on Pruned DOM).
Set-of-Marks is awesome for any AI agent that needs to interact with a webpage. To learn more about this method, read this paper by Microsoft right here: https://arxiv.org/abs/2310.11441
The Catch: Your AI Agent Still Can't Get Past a Cloudflare or PerimeterX Block Screen
Set-of-Marks solves how your agent sees and clicks a page once it loads — but if you launch local Headless Chromium directly against protected sites, your agent will just draw red boxes around a CAPTCHA challenge, not the real webpage.
Wait — look back at that Zillow Set-of-Marks screenshot above for a second. Did you notice the big white modal sitting in the center of the screen?
When we first pointed standard Playwright (chromium.launch()) at Discogs, Zillow, and Canva during viability testing, all three sites blocked headless Chromium on the spot:
- Canva returned HTTP 403 (
Just a moment...Cloudflare challenge). - Discogs returned HTTP 403 (
Cloudflare security verification). - Zillow threw up PerimeterX's
"Before we continue... Press & Hold to confirm you are a human"modal right over the actual content we wanted.
As I proved in my previous deep dive on how Cloudflare, DataDome, and PerimeterX detect browser fingerprints, local headless browsers leak automation signals through navigator.webdriver, CDP runtime checks, and datacenter IPs.
Obviously, even the best vision LLM in the world will score 0% if the screenshot you hand it is of the security block page and not the actual content.
How to Use Set-of-Marks with Bright Data Scraping Browser
To run a Set-of-Marks agent in production without fighting Cloudflare blocks or running out of container RAM in Docker, swap chromium.launch() for chromium.connectOverCDP() using Bright Data Scraping Browser.
Your captureSetOfMarks(page) function works identically over the remote DevTools connection, while Bright Data handles browser fingerprinting, residential IP rotation, and automatic CAPTCHA solving in the cloud:
import { chromium } from "playwright";
import { captureSetOfMarks } from "./som";
// Format: wss://brd-customer-<ID>-zone-<ZONE>:<PASS>@brd.superproxy.io:9222
const SBR_WS_ENDPOINT = process.env.BRIGHT_DATA_BROWSER_AUTH!;
export async function runUnblockedAgentStep(targetUrl: string) {
const browser = await chromium.connectOverCDP(SBR_WS_ENDPOINT);
try {
const page = await browser.newPage();
await page.setViewportSize({ width: 1280, height: 900 });
await page.goto(targetUrl, { waitUntil: "domcontentloaded", timeout: 60_000 });
// Injects [1]..[N] red badges, takes the JPEG screenshot, and returns exact click coords
const { screenshotBase64, controls, compactList } = await captureSetOfMarks(page);
return { screenshotBase64, controls, compactList };
} finally {
await browser.close();
}
}
And if your agent only needs to read a page without clicking through multi-step UI state, you don't even need a browser session — you can fetch the unblocked HTML or edge-converted Markdown in one HTTP request via Bright Data Web Unlocker.
Which Page Representation Should You Use for Your AI Agent?
Match how your agent "sees" the page to what the task actually requires:
| Agent Task Type | Recommended Representation | Avg Tokens / Step | Extraction / Click Accuracy | Best Infrastructure Pairing |
|---|---|---|---|---|
| Read-Only Data Extraction (No Clicking) | Pure Vision Screenshot or Clean Markdown | ~558 tok | 100% Read / 0% Click | fetch() + Bright Data Web Unlocker |
| Interactive Multi-Step Browser Agent | Set-of-Marks Vision (SoM Screenshot + [id] List) | ~765 tok | 100% Read / 100% Click | Playwright + Bright Data Scraping Browser |
| Text-Only LLM (No Multimodal Vision Support) | Numbered Controls + Scoped ARIA Snapshot | ~2,619 tok | 93.3% Read / 100% Click | Playwright + Bright Data Residential Proxies |
Raw or Pruned DOM HTML (<main>) | Avoid for agent loops | ~10,785 tok | 80.0% Read / 66.7% Click | Static Cheerio parsers only |
That's everything! If your browser agent keeps clicking empty whitespace or burning 10,000 tokens per turn, stop asking your LLM to do pixel geometry or read raw HTML divs — use Set-of-Marks. Draw numbered boxes on the screen and let it pick a number.
Frequently Asked Questions
Why do Vision LLMs miss button clicks when given a browser screenshot?
Multimodal vision encoders resize and tile wide browser screenshots (such as 1280x900) into normalized internal grids before tokenization. While the model sees the button clearly, its estimated (x, y) coordinates reflect the rescaled internal image space — missing the true DOM bounding box by 190 to 259 pixels horizontally in our benchmark.
Would a better model still have the same problem?
Yes, unless the model is specifically trained as a GUI grounding agent (like Anthropic's Computer Use or OpenAI's Operator) and you manually rescale your screenshot to match its exact training resolution. General-purpose frontier models still resize images inside their vision encoders before converting them into tokens, so raw pixel guesses will still drift on small navbar icons or non-standard aspect ratios. Set-of-Marks removes that guesswork completely — even a small local model hits 100% click accuracy because Playwright reads the exact coordinates straight from the browser DOM.
Is Playwright's Accessibility Tree (ARIA snapshot) better than DOM HTML for AI agents?
Yes. Across Discogs, Zillow, and Canva, Playwright's Accessibility Tree reduced average prompt tokens by 69.5% compared to Pruned DOM HTML (3,289 tokens vs. 10,785 tokens), cut step latency in half (3.58 seconds vs. 6.93 seconds), and improved button targeting from 66.7% to 100% by exposing semantic roles instead of obfuscated CSS module classes like .link_PKPcS.
How does Set-of-Marks (SoM) prompting work in Playwright?
Before taking a screenshot, a short page.evaluate() script queries all visible interactive elements (a, button, input, [role="button"]), records their exact getBoundingClientRect() center coordinates in Node.js, and renders a numbered badge over each element. The Vision LLM reads the screenshot, selects the badge ID, and Playwright clicks the exact stored coordinates with zero pixel error.
How do I stop Cloudflare and PerimeterX from blocking my Playwright AI agent?
Standard chromium.launch() exposes headless browser fingerprints and datacenter IPs, causing sites like Canva, Discogs, and Zillow to return HTTP 403 pages or "Press & Hold" CAPTCHA modals. Connect Playwright to Bright Data Scraping Browser via chromium.connectOverCDP() to run your Set-of-Marks loop on unblocked cloud browsers with built-in residential IP rotation and CAPTCHA solving.
Further Reading
Discover more articles on similar topics across our network
Comments
Loading comments…