The design language that makes your AI harness better at design.
JavaScript
Cap ad-tech script errors apart from counted ones
Paul Bakaus69aa49e5fac2
diff --git a/crates/browser/src/lib.rs b/crates/browser/src/lib.rsindex 6166ce986..8104ac166 100644--- a/crates/browser/src/lib.rs+++ b/crates/browser/src/lib.rs@@ -889,9 +889,9 @@ fn scan_page_inner(})?;results.extend(hidden);- for error in page.page_errors().into_iter().take(3) {- results.push(script_error_result(&error.message, error.source.as_deref()));- }+ results.extend(capped_script_errors(+ page.page_errors().iter().map(|e| (e.message.as_str(), e.source.as_deref())),+ ));let analyses = step(profile, "visual-contrast", "browser-analyze", url, || {snapshot_engine::analyze_visual_contrast(page, &base, 12.0, true)@@ -923,6 +923,29 @@ fn scan_page_inner(Ok(results)}+/// At most this many counted script errors per scan, and separately at+/// most this many ad-tech ones.+const SCRIPT_ERROR_CAP: usize = 3;++/// The page's deduped errors as `script-error` results, in arrival order.+/// The cap applies to counted errors and advisory ad-tech errors+/// separately, after classifying, so ad-tech errors never take the slots a+/// first-party error needs: three failing ad scripts ahead of a broken app+/// bundle still report the bundle as an error.+fn capped_script_errors<'a>(errors: impl IntoIterator<Item = (&'a str, Option<&'a str>)>) -> Vec<RawResult> {+ let (mut counted, mut ad_tech) = (0usize, 0usize);+ let mut out = Vec::new();+ for (message, source) in errors {+ let r = script_error_result(message, source);+ let slot = if r.third_party.is_some() { &mut ad_tech } else { &mut counted };+ if *slot < SCRIPT_ERROR_CAP {+ *slot += 1;+ out.push(r);+ }+ }+ out+}+/// One uncaught page error as a `script-error` result. The message alone/// rarely says which script failed (`Uncaught [object Object]`, a minified/// React invariant), so the finding names where it was thrown. An error an@@ -1251,6 +1274,27 @@ fn truthy(v: Option<&Value>) -> bool {mod tests {use super::*;+ #[test]+ fn ad_tech_errors_never_take_a_counted_errors_slot() {+ let prebid = |n: u32| (format!("Uncaught Error: bid {n}"), Some(format!("at https://example.com/prebid/p{n}.js:1:1")));+ let mut errors: Vec<(String, Option<String>)> = (1..=4).map(prebid).collect();+ errors.push(("Uncaught TypeError: cart is undefined".to_string(), Some("at https://example.com/js/app.js:1:1".to_string())));+ for n in 1..=4 {+ errors.push((format!("Uncaught Error: first-party {n}"), None));+ }+ let results = capped_script_errors(errors.iter().map(|(m, s)| (m.as_str(), s.as_deref())));+ let summary: Vec<(bool, &str)> =+ results.iter().map(|r| (r.severity == "advisory", r.snippet.as_str())).collect();+ assert_eq!(summary.len(), 6, "{summary:?}");+ // Three ad-tech errors, in arrival order; the fourth is capped.+ assert!(summary[..3].iter().all(|(advisory, s)| *advisory && s.contains("(third-party: Prebid)")));+ // The first-party error after them still reports, counted, and the+ // counted cap stops at three of its own.+ assert_eq!(summary[3], (false, "Uncaught TypeError: cart is undefined (at https://example.com/js/app.js:1:1)"));+ assert_eq!(summary[4], (false, "Uncaught Error: first-party 1"));+ assert_eq!(summary[5], (false, "Uncaught Error: first-party 2"));+ }+#[test]fn design_system_serialization_shape() {assert!(serialize_design_system_for_browser(None).is_null());diff --git a/crates/browser/tests/brand_and_vendors.rs b/crates/browser/tests/brand_and_vendors.rsindex f03ab7a24..b9f0d9a3f 100644--- a/crates/browser/tests/brand_and_vendors.rs+++ b/crates/browser/tests/brand_and_vendors.rs@@ -8,7 +8,8 @@//! do; a gradient reports on both (r3-23-ai-color-palette-brand-hue).//! - `script-error-ad-tech.html`: an error an ad-tech script threw, or the//! removed Topics API rejected, names the vendor and reports as advisory;-//! the site's own error stays an error (r3-31-script-error-ad-tech).+//! the site's own error stays an error, even after three ad-tech errors,+//! because the two are capped separately (r3-31-script-error-ad-tech).//! - `third-party-widgets.html`: findings on Taboola's cards and on Swiper's//! slide elements name the vendor and keep their severity; the site's own//! markup, inside a slide or not, is not tagged@@ -123,7 +124,13 @@ fn ad_tech_script_errors_are_advisory_and_name_the_vendor() {let port = serve();let findings = scan(&engine, port, "script-error-ad-tech.html");let errors = of(&findings, "script-error");- assert_eq!(errors.len(), 3, "{errors:#?}");+ // Three ad-tech errors arrive ahead of the site's own; a fourth, after+ // it, is past the ad-tech cap. The counted error still reports.+ assert_eq!(errors.len(), 4, "{errors:#?}");+ assert!(!errors.iter().any(|f| f.snippet.contains("slot render failed")), "{errors:#?}");+ let prebid = errors.iter().find(|f| f.snippet.contains("bidder timeout")).expect("Prebid error");+ assert_eq!(prebid.severity, "advisory");+ assert_eq!(third_party(prebid), Some("Prebid"));let own = errors.iter().find(|f| f.snippet.contains("cart is undefined")).expect("own error");assert_eq!(own.severity, "error");diff --git a/docs/CLI-CONTRACT.md b/docs/CLI-CONTRACT.mdindex a31b949f5..d5d41f258 100644--- a/docs/CLI-CONTRACT.md+++ b/docs/CLI-CONTRACT.md@@ -338,7 +338,7 @@ Optional keys added later by engines (appended after the above): `ignoreValue` (- **Where a script error was thrown.** A `script-error` snippet is the message followed by ` (at <source>)`: `<function>, <url>:<line>:<column>` from the top stack frame, or `<url>:<line>:<column>` for an anonymous frame or a script with no stack (a syntax error carries only the script position). A frame in a script with no URL (code from `eval` or `new Function`, a script element given text rather than a `src`) prints V8's name for it, `<anonymous>`, in the URL's place: `(at eval, <anonymous>:3:1)`. Line and column are 1-based (CDP's are 0-based); a URL past 160 characters is cut to 160 plus `...`; a throw with neither a named script nor a frame gets no suffix. The suffix is added after deduping, from the first occurrence. The JSON shape is unchanged: the source travels in `snippet`.- **One message shape.** Every script-error message reads the way the console prints it, `Uncaught <Type>: <message>`, whatever path the throw took, where the JS printed puppeteer's `err.message` with the type stripped on one path and CDP's typed text on another. CDP's marker comes first: `Uncaught`, or `Uncaught (in promise)` for an unhandled rejection. An `Error` reads the first line of its description, which names its type (`TypeError: ...`, or the name a library gave it, `ChunkLoadError: ...`); a description that names no type gets the class in front, and an empty message is the type alone (`Uncaught AbortError`). A thrown value that is not an `Error` (CDP `type: object` with no `subtype`: a plain object, a class instance, a rejected object) reads its class and V8's property preview, `Uncaught Object {code: "E_CONFIG", message: "config missing"}` (strings JSON-quoted, other values as previewed, `...` when the preview overflowed). A primitive reads as `String(value)`, `Uncaught boom`. A throw that arrives with no exception object (a cross-origin script) keeps CDP's text, which is typed already (`Uncaught TypeError: ...`, or `Uncaught [object Object]`). The body after the marker is its first line, trimmed, and the message after its type (`TypeError: `) is cut at 160 characters, the cut the JS applied to the untyped message, so naming the type costs the message nothing it showed before; a throw whose body is empty reports nothing.- **React invariants read as their message.** A production React build throws `Minified React error #<n>; visit <url> for the full message or use the non-minified dev environment for full errors and additional helpful warnings.` For a common invariant number the boilerplate from `; visit ` on is replaced by the message React's error decoder prints, the number kept: `Uncaught Error: Minified React error #418: Hydration failed because the initial UI does not match what was rendered on the server.` The table (`REACT_INVARIANTS` in `crates/browser/src/cdp.rs`) covers 31, 130, 185, 300, 301, 310, 321, 418, 419, 421, 422, 423, 425 and 426. The message is added after the 160-character cut, so it is never cut. A number the table does not know, text after the number other than `; visit `, and any message that is not an invariant stay as they were. Deduping compares the decoded messages, so both reports of one invariant still share a key.- - **One throw, one report.** Deduping compares messages with the `(in promise)` marker read as a plain `Uncaught`, so a throw that surfaces both synchronously and as an unhandled rejection (a consent manager's patched `document.createElement` called from a script and from a promise) reports once, with the first report's text and source. Messages that differ in anything else stay separate. The three-error cap applies after deduping.+ - **One throw, one report.** Deduping compares messages with the `(in promise)` marker read as a plain `Uncaught`, so a throw that surfaces both synchronously and as an unhandled rejection (a consent manager's patched `document.createElement` called from a script and from a promise) reports once, with the first report's text and source. Messages that differ in anything else stay separate. The three-error cap applies after deduping, and after classing (next item): counted errors and advisory ad-tech errors are capped at three each, in arrival order, so ad-tech errors never take a slot a counted error needs. Three failing ad scripts ahead of the site's own broken bundle still leave the bundle's error reported as `error`; a scan reports at most six script errors.- **Ad-tech script errors are advisory and name the vendor** (corpus decision r3-31-script-error-ad-tech). A script error thrown from a known ad-tech script (its source URL contains `anymind360.com` (AnyMind), `/prebid` (Prebid), `connect.facebook.net` (Meta Pixel), `googletagmanager.com` (Google Tag Manager), `cookielaw.org` (OneTrust, the consent layer that holds ad tags back), or `googlesyndication.com` / `doubleclick.net` / `googleadservices.com` (Google Ads)), or whose message names an ad API (`browsingTopics`, `joinAdInterestGroup`, `runAdAuction` (vendor `ad tech`), `adsbygoogle` (Google Ads)), reports with `severity: 'advisory'`, its snippet ends ` (third-party: <vendor>)`, and it carries `thirdParty: "<vendor>"` after `ignoreValue`. The source is checked first. Product analytics and a site's own bundles and chunks (ad code served from the site's own host included) are not on the list and stay `error`. The list lives in `crates/core/src/third_party.rs` and holds only vendors the corpus has evidence for.- **Findings on third-party widget markup name the vendor** (corpus decision r4-p24-third-party-widget-markup). A finding whose element is a known widget vendor's markup keeps its severity; its snippet ends ` (third-party: <vendor>)` and it carries `thirdParty: "<vendor>"` (after `selector`). Taboola owns its whole feed: an element with an id starting `taboola-` or `internal_trc_`, a class starting `trc_rbox`, or the class `trc_related_container`, and everything under it. Swiper owns only its structural elements: the element itself has the class `swiper`, `swiper-container`, `swiper-wrapper` or `swiper-slide`, or an id starting `swiper-wrapper-`; the site's content inside a slide is the site's. The rule pass tags in `serialize_findings` (so the in-page bundle and the extension see it too), the visual-contrast pass by its selector's first match. Page-level findings are never tagged. The static engine does not tag.- **Purple headings in the brand hue** (corpus decision r3-23-ai-color-palette-brand-hue). The heading forms of `ai-color-palette` (a snippet ending ` on heading`) do not report when the heading's computed `color` is within 12 degrees of hue of a brand surface on the same page: the solid `background-color` (alpha at least 0.9, chroma at least 50, no gradient painted over it) of the logo (an element whose `id`, `class`, `alt` or `aria-label` contains `logo`; its text colour too when it has text of its own), the nav bar (`nav`, `header`, `role=navigation|banner`, at least half the viewport wide), or a band across the page (at least 90% of the viewport's width) covering a fifth of the viewport's area or more. Headings are never brand surfaces, and the gradient and neon forms keep reporting: purple that shows up only in headings and gradients is the tell. URL engine only (the static engine has no rendered page to read surfaces from).diff --git a/tests/fixtures/antipatterns/script-error-ad-tech.html b/tests/fixtures/antipatterns/script-error-ad-tech.htmlindex 72abbb0db..e01a0cd5e 100644--- a/tests/fixtures/antipatterns/script-error-ad-tech.html+++ b/tests/fixtures/antipatterns/script-error-ad-tech.html@@ -18,12 +18,6 @@vendor. The site's own script errors keep reporting as errors.</p></main><script>- // Should flag (error): the site's own script throws.- function renderCart() { throw new TypeError('cart is undefined'); }- setTimeout(renderCart, 0);- // Should flag (advisory, third-party AnyMind): code an ad-tech host- // served. The sourceURL names the script the way the real one is named.- setTimeout(new Function('pbjs.que.push(1)\n//# sourceURL=https://anymind360.com/js/17837/prebid_2026_9_10.js'), 0);// Should flag (advisory, third-party ad tech): the Topics API rejection// Chrome gives since it removed the API, raised here the way Chrome// raises it so the fixture does not depend on the browser build.@@ -31,6 +25,18 @@"Failed to execute 'browsingTopics' on 'Document': document.browsingTopics() is deprecated and has been removed.",'NotSupportedError'));+ // Should flag (advisory, third-party AnyMind): code an ad-tech host+ // served. The sourceURL names the script the way the real one is named.+ setTimeout(new Function('pbjs.que.push(1)\n//# sourceURL=https://anymind360.com/js/17837/prebid_2026_9_10.js'), 0);+ // Should flag (advisory, third-party Prebid): a bidder adapter throws.+ setTimeout(new Function("throw new Error('bidder timeout')\n//# sourceURL=https://cdn.example.com/prebid/prebid-9.1.js"), 0);+ // Should flag (error): the site's own script throws, after three ad-tech+ // errors. Those are capped apart from counted errors, so they never take+ // the slot this one needs.+ function renderCart() { throw new TypeError('cart is undefined'); }+ setTimeout(renderCart, 100);+ // Should not flag: a fourth ad-tech error, past the ad-tech cap of three.+ setTimeout(new Function("throw new Error('slot render failed')\n//# sourceURL=https://securepubads.g.doubleclick.net/tag/js/gpt.js"), 200);</script></body></html>diff --git a/tests/oracle/DELTAS.md b/tests/oracle/DELTAS.mdindex a98835f88..a2264e047 100644--- a/tests/oracle/DELTAS.md+++ b/tests/oracle/DELTAS.md@@ -3783,7 +3783,13 @@ What each does (the contract is in `docs/CLI-CONTRACT.md`):Google Tag Manager, OneTrust or Google Ads script hosts, or naming`browsingTopics` / `joinAdInterestGroup` / `runAdAuction` / `adsbygoogle`,is `severity: advisory`, ends ` (third-party: <vendor>)` and carries- `thirdParty`. The list is `crates/core/src/third_party.rs`.+ `thirdParty`. The list is `crates/core/src/third_party.rs`. The+ three-error cap is applied after classing, to counted and ad-tech errors+ separately (`capped_script_errors` in `crates/browser/src/lib.rs`), so+ three ad-tech errors ahead of the site's own never push it out of the+ report: a page whose only counted error arrived fourth would otherwise pass+ with exit 0. `script-error-ad-tech.html` has three ad-tech errors ahead of+ its own and a fourth after it.4. **Vendor widgets.** Findings on Taboola's feed subtree and on Swiper's ownwrapper and slide elements end ` (third-party: <vendor>)` and carry`thirdParty`; severity unchanged. Same module.