Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(branding): never report the browser's default link color as a brand color (#5099)
Abimael Martellde97a832fe07
diff --git a/apps/api/src/__tests__/lib/branding/color-roles.test.ts b/apps/api/src/__tests__/lib/branding/color-roles.test.tsindex 8eea51eba..a57917a78 100644--- a/apps/api/src/__tests__/lib/branding/color-roles.test.ts+++ b/apps/api/src/__tests__/lib/branding/color-roles.test.ts@@ -316,3 +316,33 @@ describe("monochrome brands", () => {expect(merged.colors?.primary).toBe("#1ED760");});});++describe("browser link colors from the model", () => {+ it("keeps the heuristic colors when the model answers with the default link blue", () => {+ const merged = mergeBrandingResults(+ {+ colorScheme: "light",+ colors: {+ primary: "#C82540",+ accent: "#F9B200",+ secondary: "#2E7D32",+ },+ },+ {+ ...emptyLlm,+ colorRoles: {+ primaryColor: "#0000ee",+ secondaryColor: "#0000EE",+ accentColor: "#551A8B",+ backgroundColor: "#FFFFFF",+ textPrimary: "#212121",+ confidence: 0.9,+ },+ },+ [],+ );+ expect(merged.colors?.primary).toBe("#C82540");+ expect(merged.colors?.accent).toBe("#F9B200");+ expect(merged.colors?.secondary).toBe("#2E7D32");+ });+});diff --git a/apps/api/src/__tests__/lib/branding/processor-text-color.test.ts b/apps/api/src/__tests__/lib/branding/processor-text-color.test.tsindex 25825ed57..83c3143f0 100644--- a/apps/api/src/__tests__/lib/branding/processor-text-color.test.ts+++ b/apps/api/src/__tests__/lib/branding/processor-text-color.test.ts@@ -121,3 +121,42 @@ describe("text color heuristic", () => {expect(profile.colors?.textPrimary).toBe("#212121");});});++describe("browser link colors", () => {+ it("never picks the default link blue as a brand or text color", () => {+ // Unstyled links in a footer or skip-nav, drawn in the browser's blue.+ const links = Array.from({ length: 12 }, (_, i) =>+ snap({ tag: "a", text: `Link ${i}`, textColor: "rgb(0, 0, 238)" }),+ );+ const visited = Array.from({ length: 4 }, (_, i) =>+ snap({ tag: "a", text: `Visited ${i}`, textColor: "rgb(85, 26, 139)" }),+ );+ const cta = snap({+ tag: "a",+ text: "Book a table",+ textColor: "rgb(255, 255, 255)",+ background: "rgb(200, 37, 64)",+ isButton: true,+ w: 180,+ h: 48,+ });+ const paragraphs = Array.from({ length: 3 }, (_, i) =>+ snap({ text: `Paragraph ${i}`, textColor: "rgb(33, 33, 33)" }),+ );++ const profile = processRawBranding(+ raw([...links, ...visited, cta, ...paragraphs], {+ background: "rgb(255, 255, 255)",+ scheme: "light",+ }),+ );++ const picked = Object.values(profile.colors ?? {}).map(c =>+ String(c).toUpperCase(),+ );+ expect(picked).not.toContain("#0000EE");+ expect(picked).not.toContain("#551A8B");+ expect(profile.colors?.primary).toBe("#C82540");+ expect(profile.colors?.textPrimary).toBe("#212121");+ });+});diff --git a/apps/api/src/lib/branding/color-roles.ts b/apps/api/src/lib/branding/color-roles.tsindex 75402bbfb..9907c79ff 100644--- a/apps/api/src/lib/branding/color-roles.ts+++ b/apps/api/src/lib/branding/color-roles.ts@@ -63,6 +63,15 @@ export function isUsableBrandPrimary(const HEX = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;+// What browsers draw unstyled links in (unvisited, visited). A page that shows+// them never chose them, so they say nothing about the brand.+const BROWSER_LINK_COLORS = new Set(["#0000EE", "#551A8B"]);++export function isBrowserLinkColor(value?: string | null): boolean {+ const hex = normalizeRoleHex(value);+ return !!hex && BROWSER_LINK_COLORS.has(hex);+}+/** Accept #RGB / #RRGGBB; reject names like "navy" so they cannot overwrite heuristics. */export function normalizeRoleHex(value?: string | null): string | undefined {if (!value) return undefined;diff --git a/apps/api/src/lib/branding/merge.ts b/apps/api/src/lib/branding/merge.tsindex 90596ba01..7f895b1ee 100644--- a/apps/api/src/lib/branding/merge.ts+++ b/apps/api/src/lib/branding/merge.ts@@ -1,6 +1,7 @@import { BrandingProfile } from "../../types/branding";import {colorDistance,+ isBrowserLinkColor,isNeutralDark,isUsableBrandPrimary,normalizeRoleHex,@@ -278,9 +279,12 @@ export function mergeBrandingResults(merged.colorScheme,)) {- const llmPrimary = normalizeRoleHex(llm.colorRoles.primaryColor);- const llmSecondary = normalizeRoleHex(llm.colorRoles.secondaryColor);- const llmAccent = normalizeRoleHex(llm.colorRoles.accentColor);+ // A browser's default link color is never a brand color.+ const brandHex = (value?: string | null) =>+ isBrowserLinkColor(value) ? undefined : normalizeRoleHex(value);+ const llmPrimary = brandHex(llm.colorRoles.primaryColor);+ const llmSecondary = brandHex(llm.colorRoles.secondaryColor);+ const llmAccent = brandHex(llm.colorRoles.accentColor);const llmBackground = normalizeRoleHex(llm.colorRoles.backgroundColor);const llmText = normalizeRoleHex(llm.colorRoles.textPrimary);const usablePrimary =diff --git a/apps/api/src/lib/branding/processor.ts b/apps/api/src/lib/branding/processor.tsindex c11748672..b261b9ebf 100644--- a/apps/api/src/lib/branding/processor.ts+++ b/apps/api/src/lib/branding/processor.ts@@ -1,6 +1,7 @@import { BrandingProfile } from "../../types/branding";import {contrastYIQ,+ isBrowserLinkColor,isGrayish,isNearBlack,pickBrandPrimary,@@ -117,7 +118,7 @@ function inferPalette() {const freq = new Map<string, number>();const bump = (hex: string | null, weight = 1) => {- if (!hex) return;+ if (!hex || isBrowserLinkColor(hex)) return;freq.set(hex, (freq.get(hex) || 0) + weight);};@@ -192,7 +193,9 @@ function inferPalette(continue;}const hex = hexify(s.colors.text, pageBackground);- if (hex) textVotes.set(hex, (textVotes.get(hex) || 0) + 1);+ if (hex && !isBrowserLinkColor(hex)) {+ textVotes.set(hex, (textVotes.get(hex) || 0) + 1);+ }}const readableText = Array.from(textVotes.entries()).sort((x, y) => y[1] - x[1])