mcp-web-validator 1.3.51 → 1.3.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +64 -4
  3. package/dist/audit-history.d.ts +9 -0
  4. package/dist/audit-history.js +27 -0
  5. package/dist/audit-history.js.map +1 -1
  6. package/dist/index.js +2508 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/modules/browser-ux/lighthouse-lab-probe.d.ts +21 -0
  9. package/dist/modules/browser-ux/lighthouse-lab-probe.js +190 -0
  10. package/dist/modules/browser-ux/lighthouse-lab-probe.js.map +1 -0
  11. package/dist/modules/browser-ux/lighthouse-lab.d.ts +61 -0
  12. package/dist/modules/browser-ux/lighthouse-lab.js +98 -0
  13. package/dist/modules/browser-ux/lighthouse-lab.js.map +1 -0
  14. package/dist/modules/browser-ux/media-diagnostics.d.ts +41 -0
  15. package/dist/modules/browser-ux/media-diagnostics.js +183 -0
  16. package/dist/modules/browser-ux/media-diagnostics.js.map +1 -0
  17. package/dist/modules/browser-ux/raw-rendered-diff.d.ts +70 -0
  18. package/dist/modules/browser-ux/raw-rendered-diff.js +262 -0
  19. package/dist/modules/browser-ux/raw-rendered-diff.js.map +1 -0
  20. package/dist/modules/browser-ux/raw-rendered-probe.d.ts +17 -0
  21. package/dist/modules/browser-ux/raw-rendered-probe.js +163 -0
  22. package/dist/modules/browser-ux/raw-rendered-probe.js.map +1 -0
  23. package/dist/modules/browser-ux/resource-failures-probe.d.ts +11 -0
  24. package/dist/modules/browser-ux/resource-failures-probe.js +231 -0
  25. package/dist/modules/browser-ux/resource-failures-probe.js.map +1 -0
  26. package/dist/modules/browser-ux/resource-failures.d.ts +79 -0
  27. package/dist/modules/browser-ux/resource-failures.js +178 -0
  28. package/dist/modules/browser-ux/resource-failures.js.map +1 -0
  29. package/dist/modules/browser-ux/viewport-parity-probe.d.ts +5 -0
  30. package/dist/modules/browser-ux/viewport-parity-probe.js +307 -0
  31. package/dist/modules/browser-ux/viewport-parity-probe.js.map +1 -0
  32. package/dist/modules/browser-ux/viewport-parity.d.ts +112 -0
  33. package/dist/modules/browser-ux/viewport-parity.js +224 -0
  34. package/dist/modules/browser-ux/viewport-parity.js.map +1 -0
  35. package/dist/modules/browser-ux/wcag-interactions.d.ts +95 -0
  36. package/dist/modules/browser-ux/wcag-interactions.js +360 -0
  37. package/dist/modules/browser-ux/wcag-interactions.js.map +1 -0
  38. package/dist/modules/change-regression/availability-history-store.d.ts +18 -0
  39. package/dist/modules/change-regression/availability-history-store.js +168 -0
  40. package/dist/modules/change-regression/availability-history-store.js.map +1 -0
  41. package/dist/modules/change-regression/crawler-log-correlation.d.ts +111 -0
  42. package/dist/modules/change-regression/crawler-log-correlation.js +374 -0
  43. package/dist/modules/change-regression/crawler-log-correlation.js.map +1 -0
  44. package/dist/modules/change-regression/google-common-crawler-ip.d.ts +15 -0
  45. package/dist/modules/change-regression/google-common-crawler-ip.js +129 -0
  46. package/dist/modules/change-regression/google-common-crawler-ip.js.map +1 -0
  47. package/dist/modules/change-regression/historical-comparisons.d.ts +120 -0
  48. package/dist/modules/change-regression/historical-comparisons.js +330 -0
  49. package/dist/modules/change-regression/historical-comparisons.js.map +1 -0
  50. package/dist/modules/change-regression/production-change-comparison.d.ts +68 -0
  51. package/dist/modules/change-regression/production-change-comparison.js +214 -0
  52. package/dist/modules/change-regression/production-change-comparison.js.map +1 -0
  53. package/dist/modules/change-regression/regression-alerts.d.ts +73 -0
  54. package/dist/modules/change-regression/regression-alerts.js +183 -0
  55. package/dist/modules/change-regression/regression-alerts.js.map +1 -0
  56. package/dist/modules/change-regression/strict-observation-time.d.ts +7 -0
  57. package/dist/modules/change-regression/strict-observation-time.js +31 -0
  58. package/dist/modules/change-regression/strict-observation-time.js.map +1 -0
  59. package/dist/modules/content-schema/citation-methodology-consistency.d.ts +108 -0
  60. package/dist/modules/content-schema/citation-methodology-consistency.js +360 -0
  61. package/dist/modules/content-schema/citation-methodology-consistency.js.map +1 -0
  62. package/dist/modules/content-schema/competitor-intent-comparison.d.ts +74 -0
  63. package/dist/modules/content-schema/competitor-intent-comparison.js +185 -0
  64. package/dist/modules/content-schema/competitor-intent-comparison.js.map +1 -0
  65. package/dist/modules/content-schema/empty-boilerplate-content.d.ts +36 -0
  66. package/dist/modules/content-schema/empty-boilerplate-content.js +225 -0
  67. package/dist/modules/content-schema/empty-boilerplate-content.js.map +1 -0
  68. package/dist/modules/content-schema/extract-citation-methodology.d.ts +6 -0
  69. package/dist/modules/content-schema/extract-citation-methodology.js +201 -0
  70. package/dist/modules/content-schema/extract-citation-methodology.js.map +1 -0
  71. package/dist/modules/content-schema/extract-competitor-intent.d.ts +2 -0
  72. package/dist/modules/content-schema/extract-competitor-intent.js +140 -0
  73. package/dist/modules/content-schema/extract-competitor-intent.js.map +1 -0
  74. package/dist/modules/content-schema/extract-main-content.d.ts +6 -0
  75. package/dist/modules/content-schema/extract-main-content.js +33 -0
  76. package/dist/modules/content-schema/extract-main-content.js.map +1 -0
  77. package/dist/modules/content-schema/extract-metadata-consistency.d.ts +3 -0
  78. package/dist/modules/content-schema/extract-metadata-consistency.js +62 -0
  79. package/dist/modules/content-schema/extract-metadata-consistency.js.map +1 -0
  80. package/dist/modules/content-schema/extract-product-claims.d.ts +3 -0
  81. package/dist/modules/content-schema/extract-product-claims.js +58 -0
  82. package/dist/modules/content-schema/extract-product-claims.js.map +1 -0
  83. package/dist/modules/content-schema/extract-structured-data.d.ts +3 -0
  84. package/dist/modules/content-schema/extract-structured-data.js +25 -0
  85. package/dist/modules/content-schema/extract-structured-data.js.map +1 -0
  86. package/dist/modules/content-schema/metadata-consistency.d.ts +66 -0
  87. package/dist/modules/content-schema/metadata-consistency.js +282 -0
  88. package/dist/modules/content-schema/metadata-consistency.js.map +1 -0
  89. package/dist/modules/content-schema/product-claims.d.ts +73 -0
  90. package/dist/modules/content-schema/product-claims.js +195 -0
  91. package/dist/modules/content-schema/product-claims.js.map +1 -0
  92. package/dist/modules/content-schema/same-language-duplicates.d.ts +52 -0
  93. package/dist/modules/content-schema/same-language-duplicates.js +158 -0
  94. package/dist/modules/content-schema/same-language-duplicates.js.map +1 -0
  95. package/dist/modules/content-schema/structured-data-validation.d.ts +37 -0
  96. package/dist/modules/content-schema/structured-data-validation.js +385 -0
  97. package/dist/modules/content-schema/structured-data-validation.js.map +1 -0
  98. package/dist/modules/external-metrics/crux-field-probe.d.ts +10 -0
  99. package/dist/modules/external-metrics/crux-field-probe.js +113 -0
  100. package/dist/modules/external-metrics/crux-field-probe.js.map +1 -0
  101. package/dist/modules/external-metrics/crux-field.d.ts +61 -0
  102. package/dist/modules/external-metrics/crux-field.js +231 -0
  103. package/dist/modules/external-metrics/crux-field.js.map +1 -0
  104. package/dist/modules/http-crawl/availability-observations.d.ts +68 -0
  105. package/dist/modules/http-crawl/availability-observations.js +206 -0
  106. package/dist/modules/http-crawl/availability-observations.js.map +1 -0
  107. package/dist/modules/http-crawl/availability-probe.d.ts +8 -0
  108. package/dist/modules/http-crawl/availability-probe.js +46 -0
  109. package/dist/modules/http-crawl/availability-probe.js.map +1 -0
  110. package/dist/modules/http-crawl/crawler-access-probe.d.ts +6 -0
  111. package/dist/modules/http-crawl/crawler-access-probe.js +79 -0
  112. package/dist/modules/http-crawl/crawler-access-probe.js.map +1 -0
  113. package/dist/modules/http-crawl/crawler-access.d.ts +75 -0
  114. package/dist/modules/http-crawl/crawler-access.js +404 -0
  115. package/dist/modules/http-crawl/crawler-access.js.map +1 -0
  116. package/dist/modules/http-crawl/http-delivery-probe.d.ts +3 -0
  117. package/dist/modules/http-crawl/http-delivery-probe.js +44 -0
  118. package/dist/modules/http-crawl/http-delivery-probe.js.map +1 -0
  119. package/dist/modules/http-crawl/http-delivery.d.ts +64 -0
  120. package/dist/modules/http-crawl/http-delivery.js +269 -0
  121. package/dist/modules/http-crawl/http-delivery.js.map +1 -0
  122. package/dist/modules/http-crawl/https-security.d.ts +84 -0
  123. package/dist/modules/http-crawl/https-security.js +441 -0
  124. package/dist/modules/http-crawl/https-security.js.map +1 -0
  125. package/dist/modules/http-crawl/non-html-directives.d.ts +74 -0
  126. package/dist/modules/http-crawl/non-html-directives.js +353 -0
  127. package/dist/modules/http-crawl/non-html-directives.js.map +1 -0
  128. package/dist/modules/http-crawl/redirect-canonical-chains.d.ts +80 -0
  129. package/dist/modules/http-crawl/redirect-canonical-chains.js +459 -0
  130. package/dist/modules/http-crawl/redirect-canonical-chains.js.map +1 -0
  131. package/dist/modules/http-crawl/redirect-canonical-probe.d.ts +6 -0
  132. package/dist/modules/http-crawl/redirect-canonical-probe.js +83 -0
  133. package/dist/modules/http-crawl/redirect-canonical-probe.js.map +1 -0
  134. package/dist/modules/http-crawl/sitemap-inventory-probe.d.ts +8 -0
  135. package/dist/modules/http-crawl/sitemap-inventory-probe.js +155 -0
  136. package/dist/modules/http-crawl/sitemap-inventory-probe.js.map +1 -0
  137. package/dist/modules/http-crawl/sitemap-inventory.d.ts +107 -0
  138. package/dist/modules/http-crawl/sitemap-inventory.js +557 -0
  139. package/dist/modules/http-crawl/sitemap-inventory.js.map +1 -0
  140. package/dist/modules/http-crawl/url-variants.d.ts +86 -0
  141. package/dist/modules/http-crawl/url-variants.js +379 -0
  142. package/dist/modules/http-crawl/url-variants.js.map +1 -0
  143. package/dist/modules/site-architecture/extract-internal-links.d.ts +3 -0
  144. package/dist/modules/site-architecture/extract-internal-links.js +88 -0
  145. package/dist/modules/site-architecture/extract-internal-links.js.map +1 -0
  146. package/dist/modules/site-architecture/extract-multilingual-page.d.ts +2 -0
  147. package/dist/modules/site-architecture/extract-multilingual-page.js +29 -0
  148. package/dist/modules/site-architecture/extract-multilingual-page.js.map +1 -0
  149. package/dist/modules/site-architecture/internal-link-graph-probe.d.ts +7 -0
  150. package/dist/modules/site-architecture/internal-link-graph-probe.js +116 -0
  151. package/dist/modules/site-architecture/internal-link-graph-probe.js.map +1 -0
  152. package/dist/modules/site-architecture/internal-link-graph.d.ts +113 -0
  153. package/dist/modules/site-architecture/internal-link-graph.js +414 -0
  154. package/dist/modules/site-architecture/internal-link-graph.js.map +1 -0
  155. package/dist/modules/site-architecture/internal-link-quality.d.ts +77 -0
  156. package/dist/modules/site-architecture/internal-link-quality.js +260 -0
  157. package/dist/modules/site-architecture/internal-link-quality.js.map +1 -0
  158. package/dist/modules/site-architecture/multilingual-clusters.d.ts +82 -0
  159. package/dist/modules/site-architecture/multilingual-clusters.js +363 -0
  160. package/dist/modules/site-architecture/multilingual-clusters.js.map +1 -0
  161. package/dist/network.d.ts +4 -0
  162. package/dist/network.js +18 -2
  163. package/dist/network.js.map +1 -1
  164. package/dist/presentation.d.ts +53 -0
  165. package/dist/presentation.js +526 -0
  166. package/dist/presentation.js.map +1 -1
  167. package/dist/screenshot.d.ts +2 -1
  168. package/dist/screenshot.js +4 -2
  169. package/dist/screenshot.js.map +1 -1
  170. package/dist/seo-auditor.js +16 -6
  171. package/dist/seo-auditor.js.map +1 -1
  172. package/package.json +7 -4
@@ -0,0 +1,21 @@
1
+ import { type ScreenshotBrowserRuntime } from "../../screenshot.js";
2
+ import { type LabFactor, type LabReview, type LighthouseResultLike } from "./lighthouse-lab.js";
3
+ /** Lighthouse 13 requires Node >=22.19; optional runtime stays absent on older Node. */
4
+ export declare function lighthouseSupportedNode(version?: string): boolean;
5
+ export declare function sanitizeLighthouseLabHtml(html: string): string;
6
+ export interface LabProxy {
7
+ url: string;
8
+ deniedRequests(): number;
9
+ servedRequests(): number;
10
+ close(): Promise<void>;
11
+ }
12
+ export declare function startOfflineLighthouseProxy(html: string): Promise<LabProxy>;
13
+ type LighthouseRunner = (url: string, flags: Record<string, unknown>) => Promise<{
14
+ lhr: LighthouseResultLike;
15
+ } | undefined>;
16
+ export interface LabRuntime {
17
+ browser: ScreenshotBrowserRuntime;
18
+ lighthouse: LighthouseRunner;
19
+ }
20
+ export declare function inspectOfflineLighthouseLab(html: string, factor?: LabFactor, runtime?: LabRuntime): Promise<LabReview>;
21
+ export {};
@@ -0,0 +1,190 @@
1
+ /**
2
+ * V11-LAB: execute the real Lighthouse engine against one inert HTML sample,
3
+ * through a one-off loopback proxy that serves only a synthetic invalid domain.
4
+ * No arbitrary localhost, public network or page-origin requests are forwarded.
5
+ */
6
+ import * as http from "node:http";
7
+ import { load } from "cheerio";
8
+ import { defaultScreenshotBrowserRuntime, } from "../../screenshot.js";
9
+ import { analyzeLighthouseLabResult, MAX_LAB_BROWSER_MS, MAX_LAB_HTML_BYTES, MAX_LAB_PROXY_REQUESTS, } from "./lighthouse-lab.js";
10
+ const LAB_URL = "http://v11-lighthouse.invalid/";
11
+ const LOCALHOST = "127.0.0.1";
12
+ const byteLength = (value) => new TextEncoder().encode(value).byteLength;
13
+ /** Lighthouse 13 requires Node >=22.19; optional runtime stays absent on older Node. */
14
+ export function lighthouseSupportedNode(version = process.versions.node) {
15
+ const parts = /^(\d+)\.(\d+)\.(\d+)$/u.exec(version);
16
+ if (!parts)
17
+ return false;
18
+ const major = Number(parts[1]), minor = Number(parts[2]);
19
+ return major > 22 || (major === 22 && minor >= 19);
20
+ }
21
+ export function sanitizeLighthouseLabHtml(html) {
22
+ if (typeof html !== "string" || !html.trim() ||
23
+ byteLength(html) > MAX_LAB_HTML_BYTES) {
24
+ throw new Error("Provide between 1 and 180,000 UTF-8 bytes of static HTML");
25
+ }
26
+ const $ = load(html);
27
+ $("script,iframe,frame,frameset,object,embed,portal,applet,base").remove();
28
+ $('meta[http-equiv="refresh" i]').remove();
29
+ $("link[href]").remove();
30
+ $("*").each((_, element) => {
31
+ if (!("attribs" in element) || !element.attribs)
32
+ return;
33
+ for (const name of Object.keys(element.attribs)) {
34
+ if (/^on[a-z]+$/iu.test(name) || ["srcdoc", "formaction"].includes(name.toLowerCase())) {
35
+ $(element).removeAttr(name);
36
+ }
37
+ }
38
+ });
39
+ const sanitized = $.html();
40
+ if (byteLength(sanitized) > MAX_LAB_HTML_BYTES) {
41
+ throw new Error("Normalized static HTML exceeds the Lighthouse lab byte limit");
42
+ }
43
+ return sanitized;
44
+ }
45
+ export async function startOfflineLighthouseProxy(html) {
46
+ const body = new TextEncoder().encode(html);
47
+ const sockets = new Set();
48
+ let denied = 0;
49
+ let served = 0;
50
+ let attempted = 0;
51
+ const deny = (response, status = 403) => {
52
+ denied = Math.min(MAX_LAB_PROXY_REQUESTS, denied + 1);
53
+ response.writeHead(status, { "Content-Length": "0", "Cache-Control": "no-store" });
54
+ response.end();
55
+ };
56
+ const server = http.createServer((request, response) => {
57
+ attempted++;
58
+ if (attempted > MAX_LAB_PROXY_REQUESTS ||
59
+ !["GET", "HEAD"].includes(request.method ?? "") ||
60
+ request.url !== LAB_URL ||
61
+ request.headers["proxy-authorization"] !== undefined) {
62
+ deny(response, attempted > MAX_LAB_PROXY_REQUESTS ? 429 : 403);
63
+ return;
64
+ }
65
+ served++;
66
+ response.writeHead(200, {
67
+ "Content-Type": "text/html; charset=utf-8",
68
+ "Cache-Control": "no-store",
69
+ "Content-Length": String(body.byteLength),
70
+ // The synthetic fixture can load inline styles but no executable script,
71
+ // network fetch, form action or frame. DevTools evaluation is unaffected.
72
+ "Content-Security-Policy": "default-src 'none'; script-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src data:; connect-src 'none'; form-action 'none'; base-uri 'none'; frame-src 'none'",
73
+ });
74
+ response.end(request.method === "HEAD" ? undefined : body);
75
+ });
76
+ server.on("connect", (_request, socket) => { denied++; socket.destroy(); });
77
+ server.on("upgrade", (_request, socket) => { denied++; socket.destroy(); });
78
+ server.on("connection", (socket) => {
79
+ sockets.add(socket);
80
+ socket.once("close", () => sockets.delete(socket));
81
+ });
82
+ server.on("clientError", (_error, socket) => socket.destroy());
83
+ await new Promise((resolve, reject) => {
84
+ const onError = (error) => reject(error);
85
+ server.once("error", onError);
86
+ server.listen(0, LOCALHOST, () => {
87
+ server.off("error", onError);
88
+ resolve();
89
+ });
90
+ });
91
+ const address = server.address();
92
+ if (!address || typeof address === "string") {
93
+ server.close();
94
+ throw new Error("Could not bind an isolated loopback Lighthouse lab proxy");
95
+ }
96
+ let closed = false;
97
+ return {
98
+ url: `http://${LOCALHOST}:${address.port}`,
99
+ deniedRequests: () => Math.min(MAX_LAB_PROXY_REQUESTS, denied),
100
+ servedRequests: () => served,
101
+ async close() {
102
+ if (closed)
103
+ return;
104
+ closed = true;
105
+ const completion = new Promise((resolve) => server.close(() => resolve()));
106
+ for (const socket of sockets)
107
+ socket.destroy();
108
+ await completion;
109
+ },
110
+ };
111
+ }
112
+ async function defaultLighthouseRunner(url, flags) {
113
+ // This is an optional local-only dependency: dynamically load it at
114
+ // runtime rather than forcing TypeScript to resolve it on Node 22.12 CI.
115
+ const packageName = "lighthouse";
116
+ const loaded = await import(packageName);
117
+ const lighthouse = loaded.default;
118
+ return lighthouse(url, flags);
119
+ }
120
+ export async function inspectOfflineLighthouseLab(html, factor = "mobile", runtime = { browser: defaultScreenshotBrowserRuntime, lighthouse: defaultLighthouseRunner }) {
121
+ if (!lighthouseSupportedNode() && runtime.lighthouse === defaultLighthouseRunner) {
122
+ throw new Error("The optional Lighthouse 13 runtime requires Node.js >=22.19");
123
+ }
124
+ if (!["mobile", "desktop"].includes(factor))
125
+ throw new Error("Invalid Lighthouse form factor");
126
+ const sample = sanitizeLighthouseLabHtml(html);
127
+ const proxy = await startOfflineLighthouseProxy(sample);
128
+ let browser;
129
+ let deadline;
130
+ let pendingError;
131
+ try {
132
+ browser = await runtime.browser.launch(proxy.url);
133
+ const endpoint = new URL(browser.wsEndpoint());
134
+ const port = Number(endpoint.port);
135
+ if (endpoint.protocol !== "ws:" || endpoint.hostname !== LOCALHOST ||
136
+ !Number.isInteger(port) || port < 1 || port > 65_535) {
137
+ throw new Error("The isolated browser did not supply a local debugging endpoint");
138
+ }
139
+ const flags = {
140
+ port, hostname: LOCALHOST, onlyCategories: ["performance"],
141
+ output: "json", logLevel: "silent", throttlingMethod: "simulate",
142
+ maxWaitForLoad: 15_000, disableFullPageScreenshot: true,
143
+ formFactor: factor,
144
+ screenEmulation: factor === "mobile"
145
+ ? { mobile: true, width: 375, height: 812, deviceScaleFactor: 2, disabled: false }
146
+ : { mobile: false, width: 1440, height: 900, deviceScaleFactor: 1, disabled: false },
147
+ };
148
+ const timeout = new Promise((_resolve, reject) => {
149
+ deadline = setTimeout(() => {
150
+ void browser?.close().catch(() => { });
151
+ reject(new Error("Lighthouse lab browser deadline exceeded"));
152
+ }, MAX_LAB_BROWSER_MS);
153
+ deadline.unref?.();
154
+ });
155
+ // Closing Chrome alone may not resolve a stuck Lighthouse promise. The
156
+ // explicit race guarantees a bounded MCP response even in that case.
157
+ const result = await Promise.race([runtime.lighthouse(LAB_URL, flags), timeout]);
158
+ if (proxy.servedRequests() === 0) {
159
+ throw new Error("Lighthouse did not load the isolated static document");
160
+ }
161
+ return analyzeLighthouseLabResult(result?.lhr, factor, proxy.deniedRequests());
162
+ }
163
+ catch (cause) {
164
+ pendingError = cause;
165
+ throw cause;
166
+ }
167
+ finally {
168
+ if (deadline)
169
+ clearTimeout(deadline);
170
+ let cleanupFailure;
171
+ try {
172
+ if (browser)
173
+ await browser.close();
174
+ }
175
+ catch (cause) {
176
+ if (!pendingError)
177
+ cleanupFailure = cause;
178
+ }
179
+ try {
180
+ await proxy.close();
181
+ }
182
+ catch (cause) {
183
+ if (!pendingError && !cleanupFailure)
184
+ cleanupFailure = cause;
185
+ }
186
+ if (cleanupFailure)
187
+ throw cleanupFailure;
188
+ }
189
+ }
190
+ //# sourceMappingURL=lighthouse-lab-probe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lighthouse-lab-probe.js","sourceRoot":"","sources":["../../../src/modules/browser-ux/lighthouse-lab-probe.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EACL,+BAA+B,GAEhC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,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,KAAK,EAAE,CAAC;YAAC,IAAI,CAAC,YAAY,IAAI,CAAC,cAAc;gBAAE,cAAc,GAAG,KAAK,CAAC;QAAC,CAAC;QAC/E,IAAI,cAAc;YAAE,MAAM,cAAc,CAAC;IAC3C,CAAC;AACH,CAAC","sourcesContent":["/**\n * V11-LAB: execute the real Lighthouse engine against one inert HTML sample,\n * through a one-off loopback proxy that serves only a synthetic invalid domain.\n * No arbitrary localhost, public network or page-origin requests are forwarded.\n */\nimport * as http from \"node:http\";\nimport * as net from \"node:net\";\nimport { load } from \"cheerio\";\nimport {\n defaultScreenshotBrowserRuntime,\n type ScreenshotBrowserRuntime,\n} from \"../../screenshot.js\";\nimport {\n analyzeLighthouseLabResult,\n MAX_LAB_BROWSER_MS, MAX_LAB_HTML_BYTES, MAX_LAB_PROXY_REQUESTS,\n type LabFactor, type LabReview, type LighthouseResultLike,\n} from \"./lighthouse-lab.js\";\n\nconst LAB_URL = \"http://v11-lighthouse.invalid/\";\nconst LOCALHOST = \"127.0.0.1\";\nconst byteLength = (value: string) => new TextEncoder().encode(value).byteLength;\n\n/** Lighthouse 13 requires Node >=22.19; optional runtime stays absent on older Node. */\nexport function lighthouseSupportedNode(version: string = process.versions.node): boolean {\n const parts = /^(\\d+)\\.(\\d+)\\.(\\d+)$/u.exec(version);\n if (!parts) return false;\n const major = Number(parts[1]), minor = Number(parts[2]);\n return major > 22 || (major === 22 && minor >= 19);\n}\n\nexport function sanitizeLighthouseLabHtml(html: string): string {\n if (typeof html !== \"string\" || !html.trim() ||\n byteLength(html) > MAX_LAB_HTML_BYTES) {\n throw new Error(\"Provide between 1 and 180,000 UTF-8 bytes of static HTML\");\n }\n const $ = load(html);\n $(\"script,iframe,frame,frameset,object,embed,portal,applet,base\").remove();\n $('meta[http-equiv=\"refresh\" i]').remove();\n $(\"link[href]\").remove();\n $(\"*\").each((_, element) => {\n if (!(\"attribs\" in element) || !element.attribs) return;\n for (const name of Object.keys(element.attribs)) {\n if (/^on[a-z]+$/iu.test(name) || [\"srcdoc\", \"formaction\"].includes(name.toLowerCase())) {\n $(element).removeAttr(name);\n }\n }\n });\n const sanitized = $.html();\n if (byteLength(sanitized) > MAX_LAB_HTML_BYTES) {\n throw new Error(\"Normalized static HTML exceeds the Lighthouse lab byte limit\");\n }\n return sanitized;\n}\nexport interface LabProxy {\n url: string;\n deniedRequests(): number;\n servedRequests(): number;\n close(): Promise<void>;\n}\nexport async function startOfflineLighthouseProxy(html: string): Promise<LabProxy> {\n const body = new TextEncoder().encode(html);\n const sockets = new Set<net.Socket>();\n let denied = 0;\n let served = 0;\n let attempted = 0;\n const deny = (response: http.ServerResponse, status = 403) => {\n denied = Math.min(MAX_LAB_PROXY_REQUESTS, denied + 1);\n response.writeHead(status, { \"Content-Length\": \"0\", \"Cache-Control\": \"no-store\" });\n response.end();\n };\n const server = http.createServer((request, response) => {\n attempted++;\n if (attempted > MAX_LAB_PROXY_REQUESTS ||\n ![\"GET\", \"HEAD\"].includes(request.method ?? \"\") ||\n request.url !== LAB_URL ||\n request.headers[\"proxy-authorization\"] !== undefined) {\n deny(response, attempted > MAX_LAB_PROXY_REQUESTS ? 429 : 403);\n return;\n }\n served++;\n response.writeHead(200, {\n \"Content-Type\": \"text/html; charset=utf-8\",\n \"Cache-Control\": \"no-store\",\n \"Content-Length\": String(body.byteLength),\n // The synthetic fixture can load inline styles but no executable script,\n // network fetch, form action or frame. DevTools evaluation is unaffected.\n \"Content-Security-Policy\":\n \"default-src 'none'; script-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src data:; connect-src 'none'; form-action 'none'; base-uri 'none'; frame-src 'none'\",\n });\n response.end(request.method === \"HEAD\" ? undefined : body);\n });\n server.on(\"connect\", (_request, socket) => { denied++; socket.destroy(); });\n server.on(\"upgrade\", (_request, socket) => { denied++; socket.destroy(); });\n server.on(\"connection\", (socket) => {\n sockets.add(socket);\n socket.once(\"close\", () => sockets.delete(socket));\n });\n server.on(\"clientError\", (_error, socket) => socket.destroy());\n await new Promise<void>((resolve, reject) => {\n const onError = (error: Error) => reject(error);\n server.once(\"error\", onError);\n server.listen(0, LOCALHOST, () => {\n server.off(\"error\", onError);\n resolve();\n });\n });\n const address = server.address();\n if (!address || typeof address === \"string\") {\n server.close();\n throw new Error(\"Could not bind an isolated loopback Lighthouse lab proxy\");\n }\n let closed = false;\n return {\n url: `http://${LOCALHOST}:${address.port}`,\n deniedRequests: () => Math.min(MAX_LAB_PROXY_REQUESTS, denied),\n servedRequests: () => served,\n async close() {\n if (closed) return;\n closed = true;\n const completion = new Promise<void>((resolve) => server.close(() => resolve()));\n for (const socket of sockets) socket.destroy();\n await completion;\n },\n };\n}\ntype LighthouseRunner = (\n url: string, flags: Record<string, unknown>,\n) => Promise<{ lhr: LighthouseResultLike } | undefined>;\nexport interface LabRuntime {\n browser: ScreenshotBrowserRuntime;\n lighthouse: LighthouseRunner;\n}\nasync function defaultLighthouseRunner(url: string, flags: Record<string, unknown>) {\n // This is an optional local-only dependency: dynamically load it at\n // runtime rather than forcing TypeScript to resolve it on Node 22.12 CI.\n const packageName = \"lighthouse\";\n const loaded = await import(packageName);\n const lighthouse = loaded.default as LighthouseRunner;\n return lighthouse(url, flags);\n}\nexport async function inspectOfflineLighthouseLab(\n html: string,\n factor: LabFactor = \"mobile\",\n runtime: LabRuntime = { browser: defaultScreenshotBrowserRuntime, lighthouse: defaultLighthouseRunner },\n): Promise<LabReview> {\n if (!lighthouseSupportedNode() && runtime.lighthouse === defaultLighthouseRunner) {\n throw new Error(\"The optional Lighthouse 13 runtime requires Node.js >=22.19\");\n }\n if (![\"mobile\", \"desktop\"].includes(factor)) throw new Error(\"Invalid Lighthouse form factor\");\n const sample = sanitizeLighthouseLabHtml(html);\n const proxy = await startOfflineLighthouseProxy(sample);\n let browser: Awaited<ReturnType<ScreenshotBrowserRuntime[\"launch\"]>> | undefined;\n let deadline: ReturnType<typeof setTimeout> | undefined;\n let pendingError: unknown;\n try {\n browser = await runtime.browser.launch(proxy.url);\n const endpoint = new URL(browser.wsEndpoint());\n const port = Number(endpoint.port);\n if (endpoint.protocol !== \"ws:\" || endpoint.hostname !== LOCALHOST ||\n !Number.isInteger(port) || port < 1 || port > 65_535) {\n throw new Error(\"The isolated browser did not supply a local debugging endpoint\");\n }\n const flags: Record<string, unknown> = {\n port, hostname: LOCALHOST, onlyCategories: [\"performance\"],\n output: \"json\", logLevel: \"silent\", throttlingMethod: \"simulate\",\n maxWaitForLoad: 15_000, disableFullPageScreenshot: true,\n formFactor: factor,\n screenEmulation: factor === \"mobile\"\n ? { mobile: true, width: 375, height: 812, deviceScaleFactor: 2, disabled: false }\n : { mobile: false, width: 1440, height: 900, deviceScaleFactor: 1, disabled: false },\n };\n const timeout = new Promise<never>((_resolve, reject) => {\n deadline = setTimeout(() => {\n void browser?.close().catch(() => {});\n reject(new Error(\"Lighthouse lab browser deadline exceeded\"));\n }, MAX_LAB_BROWSER_MS);\n deadline.unref?.();\n });\n // Closing Chrome alone may not resolve a stuck Lighthouse promise. The\n // explicit race guarantees a bounded MCP response even in that case.\n const result = await Promise.race([runtime.lighthouse(LAB_URL, flags), timeout]);\n if (proxy.servedRequests() === 0) {\n throw new Error(\"Lighthouse did not load the isolated static document\");\n }\n return analyzeLighthouseLabResult(result?.lhr, factor, proxy.deniedRequests());\n } catch (cause) {\n pendingError = cause;\n throw cause;\n } finally {\n if (deadline) clearTimeout(deadline);\n let cleanupFailure: unknown;\n try { if (browser) await browser.close(); }\n catch (cause) { if (!pendingError) cleanupFailure = cause; }\n try { await proxy.close(); }\n catch (cause) { if (!pendingError && !cleanupFailure) cleanupFailure = cause; }\n if (cleanupFailure) throw cleanupFailure;\n }\n}\n"]}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * V11-LAB: redacted real-Lighthouse laboratory performance metrics.
3
+ * This module never executes Lighthouse; it extracts fixed numeric fields
4
+ * from a finished Lighthouse result, and never returns report URLs or text.
5
+ */
6
+ export declare const MAX_LAB_HTML_BYTES = 180000;
7
+ export declare const MAX_LAB_FINDINGS = 10;
8
+ export declare const MAX_LAB_BROWSER_MS = 75000;
9
+ export declare const MAX_LAB_PROXY_REQUESTS = 80;
10
+ export declare const LAB_FACTORS: readonly ["mobile", "desktop"];
11
+ export declare const LAB_STATUSES: readonly ["complete", "partial", "failed"];
12
+ export declare const LAB_FINDING_CODES: readonly ["lab_score_review", "lcp_review", "cls_review", "tbt_review", "metric_unavailable", "run_incomplete", "runtime_failed", "external_resources_blocked"];
13
+ export type LabFactor = typeof LAB_FACTORS[number];
14
+ export type LabStatus = typeof LAB_STATUSES[number];
15
+ export type LabCode = typeof LAB_FINDING_CODES[number];
16
+ export interface LabFinding {
17
+ code: LabCode;
18
+ severity: "warning" | "info";
19
+ message: string;
20
+ }
21
+ export interface LabMetrics {
22
+ fcp_ms: number | null;
23
+ lcp_ms: number | null;
24
+ tbt_ms: number | null;
25
+ speed_index_ms: number | null;
26
+ cls: number | null;
27
+ }
28
+ export interface LabReview {
29
+ scope: "isolated_caller_supplied_html_lighthouse_lab";
30
+ status: LabStatus;
31
+ form_factor: LabFactor;
32
+ browser_executed: boolean;
33
+ scripts_disabled: true;
34
+ network_isolated: true;
35
+ lighthouse_version: string | null;
36
+ performance_score_percent: number | null;
37
+ metrics: LabMetrics;
38
+ requests_blocked: number;
39
+ coverage_limited: true;
40
+ limitations: string[];
41
+ total_findings: number;
42
+ findings: LabFinding[];
43
+ findings_truncated: boolean;
44
+ error?: string;
45
+ }
46
+ export declare function emptyLighthouseLabReview(factor?: LabFactor): LabReview;
47
+ export interface LighthouseAuditLike {
48
+ numericValue?: unknown;
49
+ numericUnit?: unknown;
50
+ }
51
+ export interface LighthouseResultLike {
52
+ lighthouseVersion?: unknown;
53
+ runtimeError?: unknown;
54
+ categories?: {
55
+ performance?: {
56
+ score?: unknown;
57
+ };
58
+ };
59
+ audits?: Record<string, LighthouseAuditLike | undefined>;
60
+ }
61
+ export declare function analyzeLighthouseLabResult(raw: LighthouseResultLike | null | undefined, factor?: LabFactor, blocked?: number): LabReview;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * V11-LAB: redacted real-Lighthouse laboratory performance metrics.
3
+ * This module never executes Lighthouse; it extracts fixed numeric fields
4
+ * from a finished Lighthouse result, and never returns report URLs or text.
5
+ */
6
+ export const MAX_LAB_HTML_BYTES = 180_000;
7
+ export const MAX_LAB_FINDINGS = 10;
8
+ export const MAX_LAB_BROWSER_MS = 75_000;
9
+ export const MAX_LAB_PROXY_REQUESTS = 80;
10
+ export const LAB_FACTORS = ["mobile", "desktop"];
11
+ export const LAB_STATUSES = ["complete", "partial", "failed"];
12
+ export const LAB_FINDING_CODES = [
13
+ "lab_score_review", "lcp_review", "cls_review", "tbt_review",
14
+ "metric_unavailable", "run_incomplete", "runtime_failed", "external_resources_blocked",
15
+ ];
16
+ const limitations = [
17
+ "Real Lighthouse lab metrics for a sanitized, caller-supplied static HTML sample; no production page, external CSS/JS/fonts/assets, or live site performance was measured.",
18
+ "Executable page scripts, handlers, iframes and network requests are blocked; this cannot measure hydration, production APIs, third-party resources or Google Web Rendering Service.",
19
+ "FCP, LCP, TBT, Speed Index and CLS are lab observations, not 28-day CrUX field data. INP is not measured without real user interactions.",
20
+ "Machine load, Chromium version and Lighthouse throttling influence a single run. Repeat controlled runs before comparing performance or inferring ranking effects.",
21
+ ];
22
+ export function emptyLighthouseLabReview(factor = "mobile") {
23
+ return {
24
+ scope: "isolated_caller_supplied_html_lighthouse_lab",
25
+ status: "failed", form_factor: factor, browser_executed: false,
26
+ scripts_disabled: true, network_isolated: true,
27
+ lighthouse_version: null, performance_score_percent: null,
28
+ metrics: { fcp_ms: null, lcp_ms: null, tbt_ms: null, speed_index_ms: null, cls: null },
29
+ requests_blocked: 0, coverage_limited: true, limitations,
30
+ total_findings: 0, findings: [], findings_truncated: false,
31
+ };
32
+ }
33
+ function boundedMetric(value, max, places = 1) {
34
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > max)
35
+ return null;
36
+ const multiplier = 10 ** places;
37
+ return Math.round(value * multiplier) / multiplier;
38
+ }
39
+ function metric(lhr, id, max, places = 1) {
40
+ const audit = lhr.audits?.[id];
41
+ return audit && (id === "cumulative-layout-shift" ?
42
+ audit.numericUnit === "unitless" || audit.numericUnit === undefined :
43
+ audit.numericUnit === "millisecond" || audit.numericUnit === undefined)
44
+ ? boundedMetric(audit.numericValue, max, places)
45
+ : null;
46
+ }
47
+ export function analyzeLighthouseLabResult(raw, factor = "mobile", blocked = 0) {
48
+ if (!LAB_FACTORS.includes(factor) || !Number.isInteger(blocked) || blocked < 0) {
49
+ throw new Error("Invalid Lighthouse lab evidence");
50
+ }
51
+ const report = emptyLighthouseLabReview(factor);
52
+ report.browser_executed = raw !== null && raw !== undefined;
53
+ report.requests_blocked = Math.min(MAX_LAB_PROXY_REQUESTS, blocked);
54
+ const add = (code, severity, message) => {
55
+ report.total_findings++;
56
+ if (report.findings.length < MAX_LAB_FINDINGS)
57
+ report.findings.push({ code, severity, message });
58
+ };
59
+ if (!raw || typeof raw !== "object" || raw.runtimeError) {
60
+ add("runtime_failed", "warning", "Lighthouse did not deliver a valid completed laboratory report.");
61
+ return report;
62
+ }
63
+ report.lighthouse_version = typeof raw.lighthouseVersion === "string" &&
64
+ /^\d+\.\d+\.\d+(?:-[\w.]+)?$/u.test(raw.lighthouseVersion)
65
+ ? raw.lighthouseVersion.slice(0, 50) : null;
66
+ const score = raw.categories?.performance?.score;
67
+ report.performance_score_percent = typeof score === "number" &&
68
+ Number.isFinite(score) && score >= 0 && score <= 1
69
+ ? Math.round(score * 100) : null;
70
+ report.metrics = {
71
+ fcp_ms: metric(raw, "first-contentful-paint", 600_000),
72
+ lcp_ms: metric(raw, "largest-contentful-paint", 600_000),
73
+ tbt_ms: metric(raw, "total-blocking-time", 600_000),
74
+ speed_index_ms: metric(raw, "speed-index", 600_000),
75
+ cls: metric(raw, "cumulative-layout-shift", 100, 3),
76
+ };
77
+ const available = Object.values(report.metrics).filter((n) => n !== null).length;
78
+ report.status = report.performance_score_percent !== null && available === 5
79
+ ? "complete" : "partial";
80
+ if (report.performance_score_percent !== null && report.performance_score_percent < 90) {
81
+ add("lab_score_review", "info", "Lighthouse laboratory performance score is below 90; repeat with comparable inputs and machine load.");
82
+ }
83
+ if (report.metrics.lcp_ms !== null && report.metrics.lcp_ms > 2500)
84
+ add("lcp_review", "warning", "Laboratory largest contentful paint exceeds 2.5 seconds for this isolated static sample.");
85
+ if (report.metrics.cls !== null && report.metrics.cls > 0.1)
86
+ add("cls_review", "warning", "Laboratory cumulative layout shift exceeds 0.1 for this isolated static sample.");
87
+ if (report.metrics.tbt_ms !== null && report.metrics.tbt_ms > 200)
88
+ add("tbt_review", "warning", "Laboratory total blocking time exceeds 200 ms for this isolated static sample.");
89
+ if (available < 5)
90
+ add("metric_unavailable", "info", "One or more Lighthouse laboratory metrics are missing or invalid; zero was not substituted.");
91
+ if (report.status !== "complete")
92
+ add("run_incomplete", "info", "The performance category or metric sample is incomplete and cannot support a full laboratory score.");
93
+ if (report.requests_blocked > 0)
94
+ add("external_resources_blocked", "info", "Resource attempts were denied by the isolated test policy; these are not confirmed production failures.");
95
+ report.findings_truncated = report.findings.length < report.total_findings;
96
+ return report;
97
+ }
98
+ //# sourceMappingURL=lighthouse-lab.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lighthouse-lab.js","sourceRoot":"","sources":["../../../src/modules/browser-ux/lighthouse-lab.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAC1C,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AACnC,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AACzC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAU,CAAC;AAC1D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,SAAS,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EAAE,MAAM,EACvE,yGAAyG,CAAC,CAAC;IAC7G,MAAM,CAAC,kBAAkB,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC;IAC3E,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * V11-LAB: redacted real-Lighthouse laboratory performance metrics.\n * This module never executes Lighthouse; it extracts fixed numeric fields\n * from a finished Lighthouse result, and never returns report URLs or text.\n */\nexport const MAX_LAB_HTML_BYTES = 180_000;\nexport const MAX_LAB_FINDINGS = 10;\nexport const MAX_LAB_BROWSER_MS = 75_000;\nexport const MAX_LAB_PROXY_REQUESTS = 80;\nexport const LAB_FACTORS = [\"mobile\", \"desktop\"] as const;\nexport const LAB_STATUSES = [\"complete\", \"partial\", \"failed\"] as const;\nexport const LAB_FINDING_CODES = [\n \"lab_score_review\", \"lcp_review\", \"cls_review\", \"tbt_review\",\n \"metric_unavailable\", \"run_incomplete\", \"runtime_failed\", \"external_resources_blocked\",\n] as const;\nexport type LabFactor = typeof LAB_FACTORS[number];\nexport type LabStatus = typeof LAB_STATUSES[number];\nexport type LabCode = typeof LAB_FINDING_CODES[number];\nexport interface LabFinding {\n code: LabCode;\n severity: \"warning\" | \"info\";\n message: string;\n}\nexport interface LabMetrics {\n fcp_ms: number | null;\n lcp_ms: number | null;\n tbt_ms: number | null;\n speed_index_ms: number | null;\n cls: number | null;\n}\nexport interface LabReview {\n scope: \"isolated_caller_supplied_html_lighthouse_lab\";\n status: LabStatus;\n form_factor: LabFactor;\n browser_executed: boolean;\n scripts_disabled: true;\n network_isolated: true;\n lighthouse_version: string | null;\n performance_score_percent: number | null;\n metrics: LabMetrics;\n requests_blocked: number;\n coverage_limited: true;\n limitations: string[];\n total_findings: number;\n findings: LabFinding[];\n findings_truncated: boolean;\n error?: string;\n}\nconst limitations = [\n \"Real Lighthouse lab metrics for a sanitized, caller-supplied static HTML sample; no production page, external CSS/JS/fonts/assets, or live site performance was measured.\",\n \"Executable page scripts, handlers, iframes and network requests are blocked; this cannot measure hydration, production APIs, third-party resources or Google Web Rendering Service.\",\n \"FCP, LCP, TBT, Speed Index and CLS are lab observations, not 28-day CrUX field data. INP is not measured without real user interactions.\",\n \"Machine load, Chromium version and Lighthouse throttling influence a single run. Repeat controlled runs before comparing performance or inferring ranking effects.\",\n];\nexport function emptyLighthouseLabReview(factor: LabFactor = \"mobile\"): LabReview {\n return {\n scope: \"isolated_caller_supplied_html_lighthouse_lab\",\n status: \"failed\", form_factor: factor, browser_executed: false,\n scripts_disabled: true, network_isolated: true,\n lighthouse_version: null, performance_score_percent: null,\n metrics: { fcp_ms: null, lcp_ms: null, tbt_ms: null, speed_index_ms: null, cls: null },\n requests_blocked: 0, coverage_limited: true, limitations,\n total_findings: 0, findings: [], findings_truncated: false,\n };\n}\nexport interface LighthouseAuditLike {\n numericValue?: unknown;\n numericUnit?: unknown;\n}\nexport interface LighthouseResultLike {\n lighthouseVersion?: unknown;\n runtimeError?: unknown;\n categories?: { performance?: { score?: unknown } };\n audits?: Record<string, LighthouseAuditLike | undefined>;\n}\nfunction boundedMetric(value: unknown, max: number, places = 1): number | null {\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < 0 || value > max) return null;\n const multiplier = 10 ** places;\n return Math.round(value * multiplier) / multiplier;\n}\nfunction metric(lhr: LighthouseResultLike, id: string, max: number, places = 1): number | null {\n const audit = lhr.audits?.[id];\n return audit && (id === \"cumulative-layout-shift\" ?\n audit.numericUnit === \"unitless\" || audit.numericUnit === undefined :\n audit.numericUnit === \"millisecond\" || audit.numericUnit === undefined)\n ? boundedMetric(audit.numericValue, max, places)\n : null;\n}\nexport function analyzeLighthouseLabResult(\n raw: LighthouseResultLike | null | undefined,\n factor: LabFactor = \"mobile\",\n blocked = 0,\n): LabReview {\n if (!LAB_FACTORS.includes(factor) || !Number.isInteger(blocked) || blocked < 0) {\n throw new Error(\"Invalid Lighthouse lab evidence\");\n }\n const report = emptyLighthouseLabReview(factor);\n report.browser_executed = raw !== null && raw !== undefined;\n report.requests_blocked = Math.min(MAX_LAB_PROXY_REQUESTS, blocked);\n const add = (code: LabCode, severity: LabFinding[\"severity\"], message: string) => {\n report.total_findings++;\n if (report.findings.length < MAX_LAB_FINDINGS) report.findings.push({ code, severity, message });\n };\n if (!raw || typeof raw !== \"object\" || raw.runtimeError) {\n add(\"runtime_failed\", \"warning\", \"Lighthouse did not deliver a valid completed laboratory report.\");\n return report;\n }\n report.lighthouse_version = typeof raw.lighthouseVersion === \"string\" &&\n /^\\d+\\.\\d+\\.\\d+(?:-[\\w.]+)?$/u.test(raw.lighthouseVersion)\n ? raw.lighthouseVersion.slice(0, 50) : null;\n const score = raw.categories?.performance?.score;\n report.performance_score_percent = typeof score === \"number\" &&\n Number.isFinite(score) && score >= 0 && score <= 1\n ? Math.round(score * 100) : null;\n report.metrics = {\n fcp_ms: metric(raw, \"first-contentful-paint\", 600_000),\n lcp_ms: metric(raw, \"largest-contentful-paint\", 600_000),\n tbt_ms: metric(raw, \"total-blocking-time\", 600_000),\n speed_index_ms: metric(raw, \"speed-index\", 600_000),\n cls: metric(raw, \"cumulative-layout-shift\", 100, 3),\n };\n const available = Object.values(report.metrics).filter((n) => n !== null).length;\n report.status = report.performance_score_percent !== null && available === 5\n ? \"complete\" : \"partial\";\n if (report.performance_score_percent !== null && report.performance_score_percent < 90) {\n add(\"lab_score_review\", \"info\", \"Lighthouse laboratory performance score is below 90; repeat with comparable inputs and machine load.\");\n }\n if (report.metrics.lcp_ms !== null && report.metrics.lcp_ms > 2500)\n add(\"lcp_review\", \"warning\", \"Laboratory largest contentful paint exceeds 2.5 seconds for this isolated static sample.\");\n if (report.metrics.cls !== null && report.metrics.cls > 0.1)\n add(\"cls_review\", \"warning\", \"Laboratory cumulative layout shift exceeds 0.1 for this isolated static sample.\");\n if (report.metrics.tbt_ms !== null && report.metrics.tbt_ms > 200)\n add(\"tbt_review\", \"warning\", \"Laboratory total blocking time exceeds 200 ms for this isolated static sample.\");\n if (available < 5) add(\"metric_unavailable\", \"info\",\n \"One or more Lighthouse laboratory metrics are missing or invalid; zero was not substituted.\");\n if (report.status !== \"complete\") add(\"run_incomplete\", \"info\",\n \"The performance category or metric sample is incomplete and cannot support a full laboratory score.\");\n if (report.requests_blocked > 0) add(\"external_resources_blocked\", \"info\",\n \"Resource attempts were denied by the isolated test policy; these are not confirmed production failures.\");\n report.findings_truncated = report.findings.length < report.total_findings;\n return report;\n}\n"]}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * P1-10: local-only, static HTML media evidence.
3
+ * Do not fetch sources, execute scripts, infer decoded assets or claim WCAG compliance.
4
+ */
5
+ export declare const MAX_MEDIA_HTML_BYTES = 180000;
6
+ export declare const MAX_MEDIA_ELEMENTS = 160;
7
+ export declare const MAX_MEDIA_FINDINGS = 12;
8
+ export type MediaFindingCode = "image_name_unobserved" | "image_whitespace_alt" | "linked_image_name_unobserved" | "image_source_unobserved" | "image_lazy_dimensions_unobserved" | "image_invalid_loading" | "image_invalid_decoding" | "image_invalid_fetchpriority" | "picture_fallback_unobserved" | "picture_source_srcset_unobserved" | "video_source_unobserved" | "video_caption_track_unobserved" | "video_caption_source_unobserved" | "video_autoplay_without_muted";
9
+ export interface MediaFinding {
10
+ code: MediaFindingCode;
11
+ severity: "warning" | "info";
12
+ media_type: "image" | "picture" | "video";
13
+ element: number;
14
+ message: string;
15
+ }
16
+ export interface MediaDiagnostics {
17
+ scope: "caller_supplied_static_media_markup_only";
18
+ images_observed: number;
19
+ pictures_observed: number;
20
+ videos_observed: number;
21
+ source_elements_observed: number;
22
+ track_elements_observed: number;
23
+ media_elements_checked: number;
24
+ media_elements_truncated: boolean;
25
+ images_without_explicit_alt: number;
26
+ images_with_empty_alt: number;
27
+ images_without_intrinsic_dimensions: number;
28
+ lazy_images_without_intrinsic_dimensions: number;
29
+ image_sources_unobserved: number;
30
+ videos_without_observed_source: number;
31
+ videos_without_caption_track: number;
32
+ picture_fallbacks_unobserved: number;
33
+ coverage_limited: true;
34
+ limitations: string[];
35
+ total_findings: number;
36
+ findings: MediaFinding[];
37
+ findings_truncated: boolean;
38
+ error?: string;
39
+ }
40
+ export declare function emptyMediaDiagnostics(): MediaDiagnostics;
41
+ export declare function reviewMediaHtml(htmlContent: string): MediaDiagnostics;