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
feat(branding): find more of the page's real call-to-action buttons (#5049)
Abimael Martell6f892bc5026e
diff --git a/apps/api/src/__tests__/lib/branding/branding-script-buttons.test.ts b/apps/api/src/__tests__/lib/branding/branding-script-buttons.test.tsnew file mode 100644index 000000000..6f5f5432b--- /dev/null+++ b/apps/api/src/__tests__/lib/branding/branding-script-buttons.test.ts@@ -0,0 +1,115 @@+import { describe, it, expect } from "vitest";+import { JSDOM } from "jsdom";++import { getBrandingScript } from "../../../scraper/scrapeURL/engines/fire-engine/brandingScript";++// jsdom has no layout: elements get a box from data-top / data-w / data-h, and+// anything without data-top has an empty box (not visible).+function scan(body: string, scrollY = 0) {+ const dom = new JSDOM(+ `<html><head><title>Acme</title></head><body>${body}</body></html>`,+ { runScripts: "outside-only", url: "https://acme.test/" },+ );+ const window = dom.window as any;+ window.Element.prototype.getBoundingClientRect = function () {+ const top = Number(this.getAttribute?.("data-top") ?? NaN);+ if (Number.isNaN(top)) {+ return {+ x: 0,+ y: 0,+ top: 0,+ left: 0,+ width: 0,+ height: 0,+ right: 0,+ bottom: 0,+ };+ }+ const width = Number(this.getAttribute("data-w") ?? 160);+ const height = Number(this.getAttribute("data-h") ?? 44);+ return {+ x: 0,+ y: top,+ top,+ left: 0,+ width,+ height,+ right: width,+ bottom: top + height,+ };+ };+ Object.defineProperty(window, "scrollY", { value: scrollY });+ const result = window.eval(getBrandingScript());+ return result.branding.snapshots as Array<{+ text: string;+ isButton: boolean;+ isNavigation: boolean;+ visible: boolean;+ position: { top: number };+ colors: { background: string };+ }>;+}++const byText = (snaps: ReturnType<typeof scan>, text: string) =>+ snaps.find(s => s.text === text);++describe("branding script button detection", () => {+ it("reaches a hero button that comes after many lower buttons in the page", () => {+ const footer = Array.from(+ { length: 160 },+ (_, i) => `<button data-top="${3000 + i * 50}">Footer ${i}</button>`,+ ).join("");+ const snaps = scan(+ `${footer}<main><button data-top="400" style="background-color: rgb(83, 58, 253)">Start free trial</button></main>`,+ );++ const hero = byText(snaps, "Start free trial");+ expect(hero?.isButton).toBe(true);+ expect(hero?.position.top).toBe(400);+ });++ it("keeps a filled call to action in the header nav, but not plain menu links", () => {+ const snaps = scan(+ `<nav data-top="0" data-w="1200" data-h="64">+ <a href="/pricing" data-top="20">Pricing</a>+ <a href="/signup" data-top="20" style="background-color: rgb(255, 90, 0); color: rgb(255, 255, 255); padding: 8px 16px; border-radius: 6px">Sign up</a>+ </nav>`,+ );++ expect(byText(snaps, "Sign up")).toMatchObject({+ isButton: true,+ isNavigation: true,+ });+ expect(byText(snaps, "Pricing")?.isButton).toBe(false);+ });++ it("finds a link whose fill is on an inner element and reports that fill", () => {+ const snaps = scan(+ `<a href="/inspire" data-top="500" data-w="200" data-h="48"><span data-top="500" data-w="200" data-h="48" style="background-color: rgb(34, 34, 34); color: rgb(255, 255, 255)">Get inspired</span></a>`,+ );++ const link = snaps.find(s => s.text === "Get inspired" && s.isButton);+ expect(link?.colors.background).toBe("rgb(34, 34, 34)");+ });++ it("leaves out hidden copies of buttons", () => {+ const snaps = scan(+ `<button data-top="300" style="display: none">Hidden menu CTA</button><div data-top="300" style="opacity: 0"><button data-top="300">Faded menu CTA</button></div><button data-top="300">Shown CTA</button>`,+ );++ expect(byText(snaps, "Hidden menu CTA")).toBeUndefined();+ expect(byText(snaps, "Faded menu CTA")).toBeUndefined();+ expect(byText(snaps, "Shown CTA")?.visible).toBe(true);+ });++ it("keeps a fixed header button at its on-screen position after scrolling", () => {+ const snaps = scan(+ `<header style="position: fixed" data-top="0" data-w="1200" data-h="64"><button data-top="10">Sign up</button></header>+ <button data-top="100">Read more</button>`,+ 800,+ );++ expect(byText(snaps, "Sign up")?.position.top).toBe(10);+ expect(byText(snaps, "Read more")?.position.top).toBe(900);+ });+});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.tsnew file mode 100644index 000000000..25825ed57--- /dev/null+++ b/apps/api/src/__tests__/lib/branding/processor-text-color.test.ts@@ -0,0 +1,123 @@+import { processRawBranding } from "../../../lib/branding/processor";++const snap = (over: {+ tag?: string;+ text: string;+ textColor: string;+ background?: string;+ isButton?: boolean;+ w?: number;+ h?: number;+}) => ({+ tag: over.tag ?? "p",+ classes: "",+ text: over.text,+ rect: { w: over.w ?? 600, h: over.h ?? 24 },+ position: { top: 300, left: 0 },+ visible: true,+ colors: {+ text: over.textColor,+ background: over.background ?? "rgba(0, 0, 0, 0)",+ border: "rgba(0, 0, 0, 0)",+ borderWidth: 0,+ },+ typography: { fontStack: ["Inter"], size: "16px", weight: 400 },+ radius: 0,+ borderRadius: { topLeft: 0, topRight: 0, bottomRight: 0, bottomLeft: 0 },+ shadow: null,+ isButton: over.isButton ?? false,+ isNavigation: false,+ hasCTAIndicator: false,+ isInput: false,+ isLink: false,+});++const raw = (+ snapshots: ReturnType<typeof snap>[],+ page: { background: string; scheme: "light" | "dark" },+) =>+ ({+ cssData: { colors: [], spacings: [], radii: [] },+ snapshots,+ images: [],+ logoCandidates: [],+ brandName: "Acme",+ pageTitle: "Acme",+ pageUrl: "https://acme.test/",+ typography: { stacks: { body: [], heading: [], paragraph: [] }, sizes: {} },+ frameworkHints: [],+ colorScheme: page.scheme,+ pageBackground: page.background,+ backgroundCandidates: [],+ }) as any;++describe("text color heuristic", () => {+ it("takes the text color from the page's text, not from button fills", () => {+ const buttons = Array.from({ length: 8 }, (_, i) =>+ snap({+ tag: "a",+ text: `Order ${i}`,+ textColor: "rgb(255, 255, 255)",+ background: "rgb(50, 70, 47)",+ isButton: true,+ w: 180,+ h: 48,+ }),+ );+ // Dark gray buttons: their fills used to outvote the paragraph text.+ const grayButtons = Array.from({ length: 6 }, (_, i) =>+ snap({+ tag: "a",+ text: `Trade ${i}`,+ textColor: "rgb(255, 255, 255)",+ background: "rgb(70, 75, 85)",+ isButton: true,+ w: 180,+ h: 48,+ }),+ );+ const paragraphs = Array.from({ length: 4 }, (_, i) =>+ snap({ text: `Paragraph ${i}`, textColor: "rgb(33, 33, 33)" }),+ );++ const profile = processRawBranding(+ raw([...buttons, ...grayButtons, ...paragraphs], {+ background: "rgb(255, 255, 255)",+ scheme: "light",+ }),+ );++ expect(profile.colors?.textPrimary).toBe("#212121");+ });++ it("picks light text on a dark page", () => {+ const paragraphs = Array.from({ length: 4 }, (_, i) =>+ snap({ text: `Paragraph ${i}`, textColor: "rgb(255, 255, 255)" }),+ );++ const profile = processRawBranding(+ raw(paragraphs, { background: "rgb(18, 18, 18)", scheme: "dark" }),+ );++ expect(profile.colors?.textPrimary).toBe("#FFFFFF");+ });++ it("ignores text the visitor can't see", () => {+ const hidden = Array.from({ length: 10 }, (_, i) => ({+ ...snap({ text: `Menu item ${i}`, textColor: "rgb(120, 0, 0)" }),+ visible: false,+ }));+ const paragraphs = Array.from({ length: 3 }, (_, i) =>+ snap({ text: `Paragraph ${i}`, textColor: "rgb(33, 33, 33)" }),+ );++ const profile = processRawBranding(+ raw([...hidden, ...paragraphs], {+ background: "rgb(255, 255, 255)",+ scheme: "light",+ }),+ );++ expect(profile.colors?.textPrimary).toBe("#212121");+ });+});diff --git a/apps/api/src/lib/branding/processor.ts b/apps/api/src/lib/branding/processor.tsindex 7dd760b69..c11748672 100644--- a/apps/api/src/lib/branding/processor.ts+++ b/apps/api/src/lib/branding/processor.ts@@ -183,10 +183,27 @@ function inferPalette(background,colorScheme,});+ // Text color from what text is written in: the most common text color of+ // non-button elements that stands out from the background. Voting over every+ // sampled color let button fills outvote the paragraphs.+ const textVotes = new Map<string, number>();+ for (const s of snapshots) {+ if (s.isButton || s.visible === false || !s.text || !s.text.trim()) {+ continue;+ }+ const hex = hexify(s.colors.text, pageBackground);+ if (hex) textVotes.set(hex, (textVotes.get(hex) || 0) + 1);+ }+ const readableText = Array.from(textVotes.entries())+ .sort((x, y) => y[1] - x[1])+ .map(([h]) => h)+ .find(h => Math.abs(contrastYIQ(h) - contrastYIQ(background)) > 100);const textPrimary =+ readableText ||ranked.find(h => h !== primary && !/^#FFFFFF$/i.test(h) && contrastYIQ(h) < 160,- ) || (colorScheme === "dark" ? "#FFFFFF" : "#111111");+ ) ||+ (colorScheme === "dark" ? "#FFFFFF" : "#111111");const accent =ranked.find(h =>@@ -275,6 +292,9 @@ function pickLogo(images: Array<{ type: string; src: string }>): string | null {}// Process raw branding data into BrandingProfile+// Roughly one desktop screen; buttons above it count as more prominent.+const FIRST_SCREEN_PX = 1000;+export function processRawBranding(raw: BrandingScriptReturn): BrandingProfile {const palette = inferPalette(raw.snapshots,@@ -327,7 +347,9 @@ export function processRawBranding(raw: BrandingScriptReturn): BrandingProfile {const candidateButtons = raw.snapshots.filter(s => {if (!s.isButton) return false;- if (s.rect.w < 30 || s.rect.h < 30) return false;+ // Hidden copies (mobile menus, closed dialogs) aren't what visitors see.+ if (s.visible === false) return false;+ if (s.rect.w < 30 || s.rect.h < 24) return false;if (!s.text || s.text.trim().length === 0) return false;// Include buttons with valid background OR buttons with borders (transparent bg + border is valid)@@ -396,6 +418,9 @@ export function processRawBranding(raw: BrandingScriptReturn): BrandingProfile {const area = (s.rect.w || 0) * (s.rect.h || 0);score += Math.log10(area + 1) * 10;+ // On the first screen, where a page puts the action it wants taken.+ if (s.position && s.position.top < FIRST_SCREEN_PX) score += 150;+return { ...s, _score: score };}).sort((a: any, b: any) => (b._score || 0) - (a._score || 0));@@ -484,6 +509,7 @@ export function processRawBranding(raw: BrandingScriptReturn): BrandingProfile {borderRadius: representativeBorderRadius,borderRadiusCorners: corners,shadow: s.shadow || null,+ ...(s.position ? { top: Math.round(s.position.top) } : {}),// Debug: original color values before hex conversionoriginalBackgroundColor: s.colors.background || undefined,originalTextColor: s.colors.text || undefined,diff --git a/apps/api/src/lib/branding/transformer.ts b/apps/api/src/lib/branding/transformer.tsindex a94319e9c..760a89b57 100644--- a/apps/api/src/lib/branding/transformer.ts+++ b/apps/api/src/lib/branding/transformer.ts@@ -158,6 +158,9 @@ export async function brandingTransformer(score += 30;}+ // On the first screen of the page+ if (typeof btn.top === "number" && btn.top < 1000) score += 40;+return { btn, originalIdx: idx, score };}).sort((a, b) => b.score - a.score)diff --git a/apps/api/src/lib/branding/types.ts b/apps/api/src/lib/branding/types.tsindex 80ace6c9e..e91a06e1f 100644--- a/apps/api/src/lib/branding/types.ts+++ b/apps/api/src/lib/branding/types.ts@@ -18,6 +18,8 @@ export interface ButtonSnapshot {bottomLeft?: string;};shadow?: string | null;+ /** Distance from the top of the page in px, when the scan measured it. */+ top?: number;// Debug: original color values before conversion to hexoriginalBackgroundColor?: string;originalTextColor?: string;@@ -116,6 +118,9 @@ export interface BrandingScriptReturn {classes: string;text: string;rect: { w: number; h: number };+ // Scripts older than the position fields don't send them.+ position?: { top: number; left: number };+ visible?: boolean;colors: {text: string;background: string;diff --git a/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/buttons.ts b/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/buttons.tsindex 9b4c4e914..7cf398e05 100644--- a/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/buttons.ts+++ b/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/buttons.ts@@ -2,9 +2,111 @@ import { CONSTANTS } from "./constants";import {getClassNameString,getComputedStyleCached,+ getPseudoStyle,recordError,} from "./helpers";+const isOpaque = (color: string | null | undefined): boolean => {+ if (!color || color === "transparent") return false;+ const m = color.match(/rgba?\(([^)]+)\)/);+ if (!m) return true;+ const parts = m[1].split(/[\s,/]+/).filter(Boolean);+ const alpha = parts.length >= 4 ? parseFloat(parts[3]) : 1;+ return alpha > CONSTANTS.MIN_ALPHA_THRESHOLD;+};++/**+ * Rendered, with a size, and not hidden or fully transparent. Opacity doesn't+ * inherit, so a faded-out ancestor (a closed menu) is checked too.+ */+export const isVisibleElement = (el: Element, rect: DOMRect): boolean => {+ if (!(rect.width > 0 && rect.height > 0)) return false;+ const cs = getComputedStyleCached(el);+ if (cs.display === "none" || cs.visibility === "hidden") return false;+ let node: Element | null = el;+ for (let depth = 0; node && depth < 15; depth++) {+ if (parseFloat(getComputedStyleCached(node).opacity) < 0.05) return false;+ node = node.parentElement;+ }+ return true;+};++/** Fixed or sticky (itself or an ancestor): its on-screen position doesn't scroll. */+export const isViewportAnchored = (el: Element): boolean => {+ let node: Element | null = el;+ for (let depth = 0; node && depth < 10; depth++) {+ const position = getComputedStyleCached(node).position;+ if (position === "fixed" || position === "sticky") return true;+ node = node.parentElement;+ }+ return false;+};++/** Distance from the top of the page, or of the screen for fixed/sticky elements. */+export const pageTop = (el: Element, rect: DOMRect): number =>+ isViewportAnchored(el) ? rect.top : rect.top + (window.scrollY || 0);++/** The first opaque background behind an element (its ancestors'), white if none. */+const getBackgroundBehind = (el: Element): string => {+ let parent = el.parentElement;+ for (let depth = 0; parent && depth < 10; depth++) {+ const bg = getComputedStyleCached(parent).backgroundColor;+ if (isOpaque(bg)) return bg;+ parent = parent.parentElement;+ }+ return "rgb(255, 255, 255)";+};++/**+ * The color filling a button-like element as a visitor sees it: its own+ * background, else a ::before/::after layer, else a child covering most of it.+ * Many buttons are a transparent <a> or <button> with the fill on an inner+ * span or a pseudo-element. Null when nothing fills it.+ */+export const getEffectiveFill = (el: Element): string | null => {+ try {+ const own = getComputedStyleCached(el).backgroundColor;+ if (isOpaque(own)) return own;+ for (const pseudo of ["::before", "::after"]) {+ const ps = getPseudoStyle(el, pseudo);+ // Hover-only layers sit at opacity 0 until hovered: not a fill.+ if (+ ps &&+ ps.content &&+ ps.content !== "none" &&+ ps.visibility !== "hidden" &&+ !(parseFloat(ps.opacity) < 0.05) &&+ isOpaque(ps.backgroundColor)+ ) {+ return ps.backgroundColor;+ }+ }+ const rect = el.getBoundingClientRect();+ const area = rect.width * rect.height;+ if (area > 0) {+ for (let i = 0; i < el.children.length && i < 5; i++) {+ const child = el.children[i];+ const r = child.getBoundingClientRect();+ if (r.width * r.height >= area * 0.8) {+ const bg = getComputedStyleCached(child).backgroundColor;+ if (isOpaque(bg)) return bg;+ }+ }+ }+ } catch (e) {+ recordError("getEffectiveFill", e);+ }+ return null;+};++/** Filled with a color that stands out from what is behind it, or outlined. */+export const looksFilledOrOutlined = (el: Element): boolean => {+ const fill = getEffectiveFill(el);+ if (fill && fill !== getBackgroundBehind(el)) return true;+ const cs = getComputedStyleCached(el);+ return parseFloat(cs.borderTopWidth) > 0 && isOpaque(cs.borderTopColor);+};+export const checkButtonLikeElement = (el: Element,cs: CSSStyleDeclaration,@@ -40,7 +142,11 @@ export const checkButtonLikeElement = (parseFloat(cs.borderLeftWidth) > 0 ||parseFloat(cs.borderRightWidth) > 0;- return hasPadding && hasMinSize && (hasRounded || hasBorder);+ if (hasPadding && hasMinSize && (hasRounded || hasBorder)) return true;++ // Links styled through an inner span or a pseudo-element have no padding or+ // border of their own; what makes them a button is a fill that stands out.+ return hasMinSize && looksFilledOrOutlined(el);};export const isButtonElement = (el: Element | null): boolean => {diff --git a/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/constants.ts b/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/constants.tsindex 66e4983d6..6fc3924a3 100644--- a/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/constants.ts+++ b/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/constants.ts@@ -4,6 +4,9 @@ export const CONSTANTS = {BUTTON_MIN_PADDING_VERTICAL: 3,BUTTON_MIN_PADDING_HORIZONTAL: 6,MAX_PARENT_TRAVERSAL: 5,+ // Elements checked for buttons, and how many of them are kept (nearest the top first).+ BUTTON_SCAN_LIMIT: 1500,+ BUTTON_SAMPLE_LIMIT: 150,MAX_BACKGROUND_SAMPLES: 100,MIN_SIGNIFICANT_AREA: 1000,MIN_LARGE_CONTAINER_AREA: 10000,diff --git a/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/elements.ts b/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/elements.tsindex c25dcd2d3..3f6a08f8d 100644--- a/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/elements.ts+++ b/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/elements.ts@@ -5,7 +5,13 @@ import {recordError,toPx,} from "./helpers";-import { isButtonElement } from "./buttons";+import {+ getEffectiveFill,+ isButtonElement,+ isVisibleElement,+ looksFilledOrOutlined,+ pageTop,+} from "./buttons";export const sampleElements = (): Element[] => {const picksSet = new Set<Element>();@@ -22,17 +28,25 @@ export const sampleElements = (): Element[] => {pushQ('header img, .site-logo img, img[alt*=logo i], img[src*="logo"]', 5);- pushQ(- 'button, input[type="submit"], input[type="button"], [role=button], [data-primary-button], [data-secondary-button], [data-cta], a.button, a.btn, [class*="btn"], [class*="button"], a[class*="bg-brand"], a[class*="bg-primary"], a[class*="bg-accent"]',- 100,- );-- const allLinks = Array.from(document.querySelectorAll("a")).slice(0, 100);- for (const link of allLinks) {- if (!picksSet.has(link) && isButtonElement(link)) {- picksSet.add(link);+ // Buttons and button-like links, visible ones nearest the top of the page+ // first. Taking matches in document order let menus and footers use up the+ // budget before the hero's call to action was reached.+ const pool: Array<{ el: Element; top: number; order: number }> = [];+ const scanned = document.querySelectorAll(`${CONSTANTS.BUTTON_SELECTOR}, a`);+ for (let i = 0; i < scanned.length && i < CONSTANTS.BUTTON_SCAN_LIMIT; i++) {+ const el = scanned[i];+ try {+ const rect = el.getBoundingClientRect();+ if (!isVisibleElement(el, rect) || !isButtonElement(el)) continue;+ pool.push({ el, top: pageTop(el, rect), order: i });+ } catch (e) {+ recordError("sampleElements-buttons", e);}}+ pool.sort((a, b) => a.top - b.top || a.order - b.order);+ for (const { el } of pool.slice(0, CONSTANTS.BUTTON_SAMPLE_LIMIT)) {+ picksSet.add(el);+ }pushQ('input, select, textarea, [class*="form-control"]', 25);pushQ("h1, h2, h3, p, a", 50);@@ -49,6 +63,9 @@ export interface StyleSnapshot {classes: string;text: string;rect: { w: number; h: number };+ /** Page coordinates, so later steps can tell a hero button from a footer link. */+ position: { top: number; left: number };+ visible: boolean;colors: {text: string;background: string;@@ -136,7 +153,14 @@ export const getStyleSnapshot = (el: Element): StyleSnapshot => {el.tagName.toLowerCase() === "select" ||el.tagName.toLowerCase() === "textarea";- if ((isTransparent || hasZeroAlpha) && !isInputElement) {+ // The visible fill may sit on a pseudo-element or an inner child.+ const innerFill =+ (isTransparent || hasZeroAlpha) && !isInputElement+ ? getEffectiveFill(el)+ : null;+ if (innerFill) {+ bgColor = innerFill;+ } else if ((isTransparent || hasZeroAlpha) && !isInputElement) {let parent = el.parentElement;let depth = 0;while (parent && depth < CONSTANTS.MAX_PARENT_TRAVERSAL) {@@ -268,6 +292,11 @@ export const getStyleSnapshot = (el: Element): StyleSnapshot => {classes: classNames,text: text,rect: { w: rect.width, h: rect.height },+ position: {+ top: pageTop(el, rect),+ left: rect.left + (window.scrollX || 0),+ },+ visible: isVisibleElement(el, rect),colors: {text: textColor,background: bgColor,@@ -309,7 +338,9 @@ export const getStyleSnapshot = (el: Element): StyleSnapshot => {bottomLeft: toPx(cs.getPropertyValue("border-bottom-left-radius")),},shadow: cs.getPropertyValue("box-shadow") || null,- isButton: isButton && !isNavigation,+ // A filled or outlined button in the header is still a button: sites often+ // put their main call to action there. Plain menu links are not.+ isButton: isButton && (!isNavigation || looksFilledOrOutlined(el)),isNavigation: isNavigation,hasCTAIndicator: hasCTAIndicator,isInput: isInputField,diff --git a/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/helpers.ts b/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/helpers.tsindex a629afe7c..f1339f236 100644--- a/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/helpers.ts+++ b/apps/api/src/scraper/scrapeURL/engines/fire-engine/branding-script/helpers.ts@@ -42,6 +42,24 @@ try {nativeGetComputedStyle = () => ({}) as CSSStyleDeclaration;}+/** Computed style of a pseudo-element ("::before" / "::after"), or null. */+export const getPseudoStyle = (+ el: Element,+ pseudo: string,+): CSSStyleDeclaration | null => {+ try {+ return (+ nativeGetComputedStyle as (+ el: Element,+ pseudo?: string,+ ) => CSSStyleDeclaration+ )(el, pseudo);+ } catch (e) {+ recordError("getPseudoStyle", e);+ return null;+ }+};+// Style cachingconst styleCache = new WeakMap<Element, CSSStyleDeclaration>();