Brand Extractor: __name is not defined in page.evaluate()
Status: ✅ Fixed (2026-05-05)
Severity: High — brand color/font extraction silently skipped on every new tenant crawl
File: packages/agents/src/utils/brand-extractor.ts
Symptom
Every tenant web crawl logs this warning and skips brand asset extraction entirely:
WARN [tenant-web-crawler] Brand extraction failed — skipping
ReferenceError: __name is not defined
at eval (eval at evaluate (:302:30), <anonymous>:1:303)
at extractBrandAssets (brand-extractor.ts:29)BrandAssets records are never populated from the homepage, so the onboarding Brand Assets step never shows the “Prefilled from your website” banner.
Root Cause
page.evaluate() serialises the callback function to a string and re-evaluates it inside the Playwright browser sandbox. When esbuild compiles the agent server bundle, it transforms named function declarations to preserve their .name property using a __name() helper:
// Source
function parseColor(color: string) { ... }
// esbuild output (with keepNames or similar)
var parseColor = __name(function(color) { ... }, "parseColor");__name is defined at the top of the server bundle — but the serialised function string still references it, and it does not exist inside the browser context that page.evaluate() creates. Any function declaration inside the callback triggers the error.
Fix
Convert every function declaration inside the page.evaluate() callback to an arrow function assigned to a const. esbuild does not apply __name to arrow functions because their name is already inferred from the variable declaration.
// Before (broken)
function parseColor(color: string): string | null { ... }
// After (fixed)
const parseColor = (color: string): string | null => { ... };Five declarations were changed: parseColor, parseHsl, hue2rgb (nested inside parseHsl), parseAnyColor, isUsable.
The fix was applied in commit on 2026-05-05.
Scope
The same problem will occur in any other page.evaluate() call that contains named function declarations compiled by esbuild. Search the codebase before adding new ones:
grep -rn "page.evaluate" packages/agents/src/Rule: Inside any page.evaluate() callback, always use arrow functions (const x = () =>), never function declarations.