@a.incantalupo/web-tools 0.0.0-stage → 0.2.0

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 (50) hide show
  1. package/README.md +41 -2
  2. package/dist/audit/cli.d.ts +1 -0
  3. package/dist/audit/cli.js +238 -0
  4. package/dist/audit/crux.d.ts +6 -0
  5. package/dist/audit/crux.js +29 -0
  6. package/dist/audit/fetch.d.ts +17 -0
  7. package/dist/audit/fetch.js +51 -0
  8. package/dist/audit/findings.d.ts +9 -0
  9. package/dist/audit/findings.js +514 -0
  10. package/dist/audit/index.d.ts +6 -0
  11. package/dist/audit/index.js +3 -0
  12. package/dist/audit/lighthouse.d.ts +2 -0
  13. package/dist/audit/lighthouse.js +84 -0
  14. package/dist/audit/page.d.ts +10 -0
  15. package/dist/audit/page.js +156 -0
  16. package/dist/audit/profile.d.ts +11 -0
  17. package/dist/audit/profile.js +21 -0
  18. package/dist/audit/render.d.ts +8 -0
  19. package/dist/audit/render.js +63 -0
  20. package/dist/audit/rerender.d.ts +1 -0
  21. package/dist/audit/rerender.js +55 -0
  22. package/dist/audit/reviews.d.ts +2 -0
  23. package/dist/audit/reviews.js +36 -0
  24. package/dist/audit/scores.d.ts +3 -0
  25. package/dist/audit/scores.js +51 -0
  26. package/dist/audit/site.d.ts +19 -0
  27. package/dist/audit/site.js +78 -0
  28. package/dist/audit/summary.d.ts +2 -0
  29. package/dist/audit/summary.js +59 -0
  30. package/dist/audit/types.d.ts +132 -0
  31. package/dist/audit/types.js +1 -0
  32. package/dist/browser/cli.d.ts +1 -0
  33. package/dist/browser/cli.js +11 -0
  34. package/dist/browser/index.d.ts +15 -0
  35. package/dist/browser/index.js +59 -0
  36. package/dist/cli.d.ts +2 -0
  37. package/dist/cli.js +34 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +4 -0
  40. package/dist/refs/cli.d.ts +1 -0
  41. package/dist/refs/cli.js +193 -0
  42. package/dist/refs/glyphs.d.ts +1 -0
  43. package/dist/refs/glyphs.js +101 -0
  44. package/dist/refs/images.d.ts +1 -0
  45. package/dist/refs/images.js +163 -0
  46. package/dist/refs/snapshot.d.ts +1 -0
  47. package/dist/refs/snapshot.js +243 -0
  48. package/dist/refs/text.d.ts +1 -0
  49. package/dist/refs/text.js +728 -0
  50. package/package.json +29 -5
@@ -0,0 +1,514 @@
1
+ const SEARCH_BOTS = [
2
+ "Googlebot",
3
+ "Bingbot",
4
+ "OAI-SearchBot",
5
+ "ChatGPT-User",
6
+ "Claude-SearchBot",
7
+ "Claude-User",
8
+ "PerplexityBot",
9
+ ];
10
+ /** Schema.org types that count as "the business" and as "an item it sells"; a profile can replace them. */
11
+ export const DEFAULT_BUSINESS_TYPES = ["LocalBusiness", "Organization", "Store", "ProfessionalService"];
12
+ export const DEFAULT_ITEM_TYPES = ["Product", "Offer", "Service"];
13
+ const STALE_SITEMAP_DAYS = 90;
14
+ const kb = (bytes) => `${Math.round(bytes / 1024)} KB`;
15
+ const median = (xs) => {
16
+ const s = [...xs].sort((a, b) => a - b);
17
+ return s.length ? s[Math.floor(s.length / 2)] : 0;
18
+ };
19
+ const grade = (value, medium, high) => value > high ? "high" : value > medium ? "medium" : "pass";
20
+ export function buildFindings(r, types = {}) {
21
+ // A profile's lists replace the defaults: a niche knows which types really count.
22
+ const BUSINESS_TYPES = types.business ?? DEFAULT_BUSINESS_TYPES;
23
+ const ITEM_TYPES = types.items ?? DEFAULT_ITEM_TYPES;
24
+ const f = [];
25
+ const ok = r.pages.filter((p) => p.status === 200);
26
+ const home = ok[0];
27
+ // On a preview host, being kept out of search engines is the intended setup.
28
+ const intended = new Set(["ai-search-bots", "noindex", "robots-sitemap"]);
29
+ const add = (x) => f.push(r.preview && intended.has(x.id) && x.severity !== "pass"
30
+ ? {
31
+ ...x,
32
+ severity: "info",
33
+ title: `${x.title} (preview host, intended)`,
34
+ }
35
+ : x);
36
+ // Performance
37
+ for (const lh of r.lighthouse.filter((l) => l.formFactor === "mobile")) {
38
+ if (lh.scores.performance == null) {
39
+ add({
40
+ id: "lh-error",
41
+ area: "performance",
42
+ severity: "info",
43
+ title: "Lighthouse could not measure performance",
44
+ evidence: `${lh.error ?? "no performance score"} (${lh.reportFile})`,
45
+ pages: [lh.url],
46
+ });
47
+ continue;
48
+ }
49
+ const perf = lh.scores.performance;
50
+ add({
51
+ id: "lh-performance",
52
+ area: "performance",
53
+ severity: perf < 50 ? "high" : perf < 90 ? "medium" : "pass",
54
+ title: `Lighthouse mobile performance ${perf}/100`,
55
+ evidence: `LCP ${Math.round(lh.metrics.lcpMs ?? 0)} ms, TBT ${Math.round(lh.metrics.tbtMs ?? 0)} ms, CLS ${(lh.metrics.cls ?? 0).toFixed(3)} (${lh.reportFile})`,
56
+ pages: [lh.url],
57
+ });
58
+ add({
59
+ id: "lcp",
60
+ area: "performance",
61
+ severity: grade(lh.metrics.lcpMs ?? 0, 2500, 4000),
62
+ title: "Largest Contentful Paint (mobile, lab)",
63
+ evidence: `${Math.round(lh.metrics.lcpMs ?? 0)} ms (budget 2500 ms)`,
64
+ pages: [lh.url],
65
+ });
66
+ add({
67
+ id: "cls",
68
+ area: "performance",
69
+ severity: grade(lh.metrics.cls ?? 0, 0.1, 0.25),
70
+ title: "Cumulative Layout Shift (mobile, lab)",
71
+ evidence: `${(lh.metrics.cls ?? 0).toFixed(3)} (budget 0.1)`,
72
+ pages: [lh.url],
73
+ });
74
+ add({
75
+ id: "tbt",
76
+ area: "performance",
77
+ severity: grade(lh.metrics.tbtMs ?? 0, 200, 600),
78
+ title: "Total Blocking Time (mobile, lab; proxy for INP)",
79
+ evidence: `${Math.round(lh.metrics.tbtMs ?? 0)} ms (budget 200 ms)`,
80
+ pages: [lh.url],
81
+ });
82
+ if (lh.scriptBytes !== null)
83
+ add({
84
+ id: "js-weight",
85
+ area: "performance",
86
+ severity: grade(lh.scriptBytes, 100 * 1024, 300 * 1024),
87
+ title: "JavaScript transferred",
88
+ evidence: `${kb(lh.scriptBytes)} (budget 100 KB)`,
89
+ pages: [lh.url],
90
+ });
91
+ if (lh.totalBytes !== null)
92
+ add({
93
+ id: "page-weight",
94
+ area: "performance",
95
+ severity: grade(lh.totalBytes, 2.5 * 1024 * 1024, 5 * 1024 * 1024),
96
+ title: "Total page weight",
97
+ evidence: `${kb(lh.totalBytes)} (images ${kb(lh.imageBytes ?? 0)}, third-party ${kb(lh.thirdPartyBytes ?? 0)})`,
98
+ pages: [lh.url],
99
+ });
100
+ }
101
+ // Real visitors (Chrome UX Report)
102
+ const real = r.crux?.home ?? r.crux?.origin;
103
+ if (r.crux?.error)
104
+ add({
105
+ id: "crux-error",
106
+ area: "performance",
107
+ severity: "info",
108
+ title: "Chrome UX Report could not be read",
109
+ evidence: r.crux.error,
110
+ });
111
+ else if (r.crux && !real)
112
+ add({
113
+ id: "crux-none",
114
+ area: "performance",
115
+ severity: "info",
116
+ title: "No real-visitor data from Google (too few Chrome visits)",
117
+ evidence: "Chrome UX Report has no record for the home page or the site",
118
+ });
119
+ if (real?.lcpMs != null)
120
+ add({
121
+ id: "crux-lcp",
122
+ area: "performance",
123
+ severity: grade(real.lcpMs, 2500, 4000),
124
+ title: "Real visitors on phones: main content shown (LCP, 75th percentile)",
125
+ evidence: `${Math.round(real.lcpMs)} ms (budget 2500 ms); ${real.lcpGood != null ? `${Math.round(real.lcpGood * 100)}% of visits within 2.5 s; ` : ""}${real.scope} ${real.key}, ${real.period}`,
126
+ });
127
+ if (real?.inpMs != null)
128
+ add({
129
+ id: "crux-inp",
130
+ area: "performance",
131
+ severity: grade(real.inpMs, 200, 500),
132
+ title: "Real visitors on phones: response to taps (INP, 75th percentile)",
133
+ evidence: `${Math.round(real.inpMs)} ms (budget 200 ms)`,
134
+ });
135
+ if (real?.cls != null)
136
+ add({
137
+ id: "crux-cls",
138
+ area: "performance",
139
+ severity: grade(real.cls, 0.1, 0.25),
140
+ title: "Real visitors on phones: layout shift (CLS, 75th percentile)",
141
+ evidence: `${real.cls.toFixed(2)} (budget 0.1)`,
142
+ });
143
+ if (ok.length) {
144
+ const ttfb = median(ok.map((p) => p.ttfbMs));
145
+ add({
146
+ id: "ttfb",
147
+ area: "performance",
148
+ severity: grade(ttfb, 800, 1800),
149
+ title: "Server response time (median over crawled pages)",
150
+ evidence: `${ttfb} ms (budget 800 ms)`,
151
+ });
152
+ const uncompressed = ok.filter((p) => !p.contentEncoding);
153
+ if (uncompressed.length)
154
+ add({
155
+ id: "compression",
156
+ area: "performance",
157
+ severity: "medium",
158
+ title: "HTML served without compression",
159
+ evidence: `${uncompressed.length}/${ok.length} pages without gzip/br`,
160
+ pages: uncompressed.map((p) => p.url),
161
+ });
162
+ const thirdParty = new Set(ok.flatMap((p) => p.thirdPartyHosts));
163
+ add({
164
+ id: "third-party",
165
+ area: "performance",
166
+ severity: thirdParty.size > 5 ? "medium" : thirdParty.size > 2 ? "low" : "pass",
167
+ title: "Third-party script hosts",
168
+ evidence: thirdParty.size ? [...thirdParty].join(", ") : "none",
169
+ });
170
+ const imgs = ok.reduce((n, p) => n + p.images, 0);
171
+ const legacy = ok.reduce((n, p) => n + p.legacyImageFormats, 0);
172
+ if (imgs && legacy / imgs > 0.5)
173
+ add({
174
+ id: "image-formats",
175
+ area: "performance",
176
+ severity: "low",
177
+ title: "Most images are JPEG/PNG/GIF instead of WebP/AVIF",
178
+ evidence: `${legacy}/${imgs} images`,
179
+ });
180
+ }
181
+ // Crawl
182
+ if (!r.site.https)
183
+ add({
184
+ id: "https",
185
+ area: "crawl",
186
+ severity: "high",
187
+ title: "HTTP does not redirect to HTTPS",
188
+ evidence: r.target,
189
+ });
190
+ if (r.site.robotsTxt === null)
191
+ add({
192
+ id: "robots-missing",
193
+ area: "crawl",
194
+ severity: "medium",
195
+ title: "robots.txt missing",
196
+ evidence: "/robots.txt not 200",
197
+ });
198
+ else if (!/^\s*sitemap\s*:/im.test(r.site.robotsTxt))
199
+ add({
200
+ id: "robots-sitemap",
201
+ area: "crawl",
202
+ severity: "medium",
203
+ title: "robots.txt does not reference a sitemap",
204
+ evidence: 'no "Sitemap:" line',
205
+ });
206
+ if (!r.site.sitemaps.length)
207
+ add({
208
+ id: "sitemap-missing",
209
+ area: "crawl",
210
+ severity: "high",
211
+ title: "No XML sitemap found",
212
+ evidence: "robots.txt and /sitemap.xml checked",
213
+ });
214
+ for (const s of r.site.sitemaps) {
215
+ const age = s.newestLastmod
216
+ ? (Date.now() - Date.parse(s.newestLastmod)) / 86_400_000
217
+ : null;
218
+ add({
219
+ id: "sitemap-fresh",
220
+ area: "crawl",
221
+ severity: age === null ? "low" : age > STALE_SITEMAP_DAYS ? "medium" : "pass",
222
+ title: "Sitemap freshness",
223
+ evidence: `${s.url}: ${s.urls} URLs, newest lastmod ${s.newestLastmod ?? "none"}${age !== null ? ` (${Math.round(age)} days ago)` : ""}`,
224
+ });
225
+ }
226
+ const broken = r.pages.filter((p) => p.status >= 400 || p.status === 0);
227
+ if (broken.length)
228
+ add({
229
+ id: "broken-pages",
230
+ area: "crawl",
231
+ severity: "high",
232
+ title: "Internal pages returning errors",
233
+ evidence: broken.map((p) => `${p.status} ${p.url}`).join("; "),
234
+ pages: broken.map((p) => p.url),
235
+ });
236
+ const noindex = ok.filter((p) => p.noindex);
237
+ if (noindex.length)
238
+ add({
239
+ id: "noindex",
240
+ area: "crawl",
241
+ severity: "high",
242
+ title: "Pages marked noindex",
243
+ evidence: `${noindex.length} pages`,
244
+ pages: noindex.map((p) => p.url),
245
+ });
246
+ const noCanonical = ok.filter((p) => !p.canonical);
247
+ if (noCanonical.length)
248
+ add({
249
+ id: "canonical",
250
+ area: "crawl",
251
+ severity: "low",
252
+ title: "Pages without canonical link",
253
+ evidence: `${noCanonical.length}/${ok.length} pages`,
254
+ pages: noCanonical.map((p) => p.url),
255
+ });
256
+ // AI visibility
257
+ const blockedSearch = SEARCH_BOTS.filter((b) => r.site.aiBots[b] === "blocked");
258
+ add({
259
+ id: "ai-search-bots",
260
+ area: "ai-visibility",
261
+ severity: blockedSearch.length ? "high" : "pass",
262
+ title: "Search and AI-answer crawlers allowed in robots.txt",
263
+ evidence: blockedSearch.length
264
+ ? `blocked: ${blockedSearch.join(", ")}`
265
+ : `allowed: ${SEARCH_BOTS.join(", ")}`,
266
+ });
267
+ const blockedTraining = Object.entries(r.site.aiBots)
268
+ .filter(([b, v]) => v === "blocked" && !SEARCH_BOTS.includes(b))
269
+ .map(([b]) => b);
270
+ add({
271
+ id: "ai-training-bots",
272
+ area: "ai-visibility",
273
+ severity: "info",
274
+ title: "AI training crawlers",
275
+ evidence: blockedTraining.length
276
+ ? `blocked: ${blockedTraining.join(", ")}`
277
+ : "none blocked",
278
+ });
279
+ const jsOnly = ok.filter((p) => p.jsOnly?.length);
280
+ if (jsOnly.length) {
281
+ const what = [...new Set(jsOnly.flatMap((p) => p.jsOnly))];
282
+ add({
283
+ id: "js-only",
284
+ area: "ai-visibility",
285
+ severity: what.some((w) => w === "price" || w === "tel")
286
+ ? "medium"
287
+ : "low",
288
+ title: "Shown only after JavaScript runs (crawlers and AI may not see it)",
289
+ evidence: `${what.join(", ")} on ${jsOnly.length}/${ok.length} pages`,
290
+ pages: jsOnly.map((p) => p.url),
291
+ });
292
+ }
293
+ const textless = ok.filter((p) => p.wordCount < 150);
294
+ if (textless.length)
295
+ add({
296
+ id: "thin-html",
297
+ area: "ai-visibility",
298
+ severity: textless.length > ok.length / 2 ? "medium" : "low",
299
+ title: "Pages with little text in the server HTML (< 150 words)",
300
+ evidence: `${textless.length}/${ok.length} pages; crawlers and LLMs read the raw HTML`,
301
+ pages: textless.map((p) => p.url),
302
+ });
303
+ add({
304
+ id: "llms-txt",
305
+ area: "ai-visibility",
306
+ severity: "info",
307
+ title: "llms.txt",
308
+ evidence: r.site.llmsTxt ? "present" : "absent (Google: not required)",
309
+ });
310
+ // Structured data
311
+ const allTypes = new Set(ok.flatMap((p) => p.jsonLdTypes));
312
+ add({
313
+ id: "jsonld-business",
314
+ area: "structured-data",
315
+ severity: BUSINESS_TYPES.some((t) => allTypes.has(t)) ? "pass" : "high",
316
+ title: `Business JSON-LD (${BUSINESS_TYPES.join("/")})`,
317
+ evidence: allTypes.size
318
+ ? `types found: ${[...allTypes].join(", ")}`
319
+ : "no JSON-LD on any crawled page",
320
+ });
321
+ add({
322
+ id: "jsonld-items",
323
+ area: "structured-data",
324
+ severity: ITEM_TYPES.some((t) => allTypes.has(t)) ? "pass" : "high",
325
+ title: `Item JSON-LD on item pages (${ITEM_TYPES.join("/")})`,
326
+ evidence: ITEM_TYPES.filter((t) => allTypes.has(t)).join(", ") || "none",
327
+ });
328
+ if (!allTypes.has("BreadcrumbList"))
329
+ add({
330
+ id: "jsonld-breadcrumb",
331
+ area: "structured-data",
332
+ severity: "low",
333
+ title: "No BreadcrumbList JSON-LD",
334
+ evidence: "none found",
335
+ });
336
+ const jsonLdErrors = ok.filter((p) => p.jsonLdErrors);
337
+ if (jsonLdErrors.length)
338
+ add({
339
+ id: "jsonld-invalid",
340
+ area: "structured-data",
341
+ severity: "medium",
342
+ title: "Invalid JSON-LD blocks",
343
+ evidence: `${jsonLdErrors.length} pages`,
344
+ pages: jsonLdErrors.map((p) => p.url),
345
+ });
346
+ // Content
347
+ const titles = new Map();
348
+ for (const p of ok)
349
+ titles.set(p.title, [...(titles.get(p.title) ?? []), p.url]);
350
+ const dupTitles = [...titles.entries()].filter(([t, urls]) => t && urls.length > 1);
351
+ const missingTitles = ok.filter((p) => !p.title);
352
+ if (missingTitles.length || dupTitles.length)
353
+ add({
354
+ id: "titles",
355
+ area: "content",
356
+ severity: "medium",
357
+ title: "Missing or duplicate page titles",
358
+ evidence: [
359
+ missingTitles.length && `${missingTitles.length} missing`,
360
+ ...dupTitles.map(([t, u]) => `"${t}" x${u.length}`),
361
+ ]
362
+ .filter(Boolean)
363
+ .join("; "),
364
+ });
365
+ const noDesc = ok.filter((p) => !p.metaDescription);
366
+ if (noDesc.length)
367
+ add({
368
+ id: "meta-description",
369
+ area: "content",
370
+ severity: "medium",
371
+ title: "Pages without meta description",
372
+ evidence: `${noDesc.length}/${ok.length}`,
373
+ pages: noDesc.map((p) => p.url),
374
+ });
375
+ const badH1 = ok.filter((p) => p.h1Count !== 1);
376
+ if (badH1.length)
377
+ add({
378
+ id: "h1",
379
+ area: "content",
380
+ severity: "low",
381
+ title: "Pages without exactly one H1",
382
+ evidence: badH1.map((p) => `${p.h1Count}x ${p.url}`).join("; "),
383
+ pages: badH1.map((p) => p.url),
384
+ });
385
+ const priced = ok.filter((p) => p.hasPrice);
386
+ add({
387
+ id: "prices",
388
+ area: "content",
389
+ severity: priced.length ? "pass" : "high",
390
+ title: "Prices visible on pages",
391
+ evidence: `${priced.length}/${ok.length} pages mention a price`,
392
+ });
393
+ const noAlt = ok.reduce((n, p) => n + p.imagesWithoutAlt, 0);
394
+ const imgTotal = ok.reduce((n, p) => n + p.images, 0);
395
+ if (noAlt)
396
+ add({
397
+ id: "alt",
398
+ area: "content",
399
+ severity: noAlt / imgTotal > 0.3 ? "medium" : "low",
400
+ title: "Images without alt text",
401
+ evidence: `${noAlt}/${imgTotal} images`,
402
+ });
403
+ if (home && !home.lang)
404
+ add({
405
+ id: "lang",
406
+ area: "content",
407
+ severity: "low",
408
+ title: "Missing <html lang>",
409
+ evidence: home.url,
410
+ });
411
+ // Local + conversion
412
+ const withTel = ok.filter((p) => p.telLinks);
413
+ const withWa = ok.filter((p) => p.whatsappLinks);
414
+ const withForm = ok.filter((p) => p.forms);
415
+ const withMaps = ok.filter((p) => p.mapsLinks);
416
+ add({
417
+ id: "tel",
418
+ area: "conversion",
419
+ severity: withTel.length === ok.length
420
+ ? "pass"
421
+ : withTel.length
422
+ ? "medium"
423
+ : "high",
424
+ title: "Tap-to-call link",
425
+ evidence: `${withTel.length}/${ok.length} pages`,
426
+ });
427
+ add({
428
+ id: "whatsapp",
429
+ area: "conversion",
430
+ severity: withWa.length ? "pass" : "medium",
431
+ title: "WhatsApp link",
432
+ evidence: `${withWa.length}/${ok.length} pages`,
433
+ });
434
+ add({
435
+ id: "forms",
436
+ area: "conversion",
437
+ severity: withForm.length ? "pass" : "medium",
438
+ title: "Contact or lead form",
439
+ evidence: `${withForm.length}/${ok.length} pages`,
440
+ });
441
+ add({
442
+ id: "maps",
443
+ area: "local",
444
+ severity: withMaps.length ? "pass" : "medium",
445
+ title: "Map link or embed",
446
+ evidence: `${withMaps.length}/${ok.length} pages`,
447
+ });
448
+ // Reputation (Google reviews; the first file is the business, the rest competitors)
449
+ const [own, ...rivals] = r.reviews;
450
+ if (own) {
451
+ const best = [...rivals].sort((a, b) => b.count - a.count)[0];
452
+ add({
453
+ id: "reviews-rating",
454
+ area: "reputation",
455
+ severity: own.rating < 4 ? "high" : own.rating < 4.5 ? "medium" : "pass",
456
+ title: "Google rating",
457
+ evidence: `${own.rating}★ from ${own.count} reviews${rivals.length ? `; competitors: ${rivals.map((c) => `${c.name} ${c.rating}★/${c.count}`).join(", ")}` : ""}`,
458
+ });
459
+ if (best && best.count > own.count * 1.5)
460
+ add({
461
+ id: "reviews-behind",
462
+ area: "reputation",
463
+ severity: "medium",
464
+ title: "Fewer reviews than a competitor",
465
+ evidence: `${own.count} vs ${best.count} (${best.name})`,
466
+ });
467
+ add({
468
+ id: "reviews-recent",
469
+ area: "reputation",
470
+ severity: own.last3Months < 3 ? "medium" : "pass",
471
+ title: "New reviews in the last 3 months",
472
+ evidence: `${own.last3Months} in 3 months, ${own.last12Months} in 12 months (of ${own.read} read)`,
473
+ });
474
+ if (own.replied !== null)
475
+ add({
476
+ id: "reviews-replies",
477
+ area: "reputation",
478
+ severity: own.read && own.replied / own.read < 0.5
479
+ ? own.replied === 0
480
+ ? "high"
481
+ : "medium"
482
+ : "pass",
483
+ title: "Reviews answered by the owner",
484
+ evidence: `${own.replied}/${own.read}; 1-3 star reviews in the last 12 months: ${own.recentLow}, answered ${own.recentLowReplied ?? "?"}`,
485
+ });
486
+ }
487
+ // Hygiene
488
+ const origin = new URL(r.target).origin;
489
+ const homeShares = ok
490
+ .filter((p) => p.url !== home?.url)
491
+ .filter((p) => p.shareLinks.length &&
492
+ p.shareLinks.every((s) => decodeURIComponent(s).includes(`=${origin}/&`) ||
493
+ decodeURIComponent(s).endsWith(`=${origin}/`)));
494
+ if (homeShares.length)
495
+ add({
496
+ id: "share-links",
497
+ area: "hygiene",
498
+ severity: "medium",
499
+ title: "Share buttons share the homepage instead of the current page",
500
+ evidence: `${homeShares.length} pages`,
501
+ pages: homeShares.map((p) => p.url),
502
+ });
503
+ const insecure = ok.filter((p) => p.insecureResources);
504
+ if (insecure.length)
505
+ add({
506
+ id: "mixed-content",
507
+ area: "hygiene",
508
+ severity: "medium",
509
+ title: "HTTP resources on HTTPS pages",
510
+ evidence: `${insecure.length} pages`,
511
+ pages: insecure.map((p) => p.url),
512
+ });
513
+ return f;
514
+ }
@@ -0,0 +1,6 @@
1
+ export type * from "./types.ts";
2
+ export type { AuditProfile } from "./profile.ts";
3
+ export type { FindingTypes } from "./findings.ts";
4
+ export { DEFAULT_BUSINESS_TYPES, DEFAULT_ITEM_TYPES, buildFindings } from "./findings.ts";
5
+ export { computeScores, WEIGHTS } from "./scores.ts";
6
+ export { renderSummary } from "./summary.ts";
@@ -0,0 +1,3 @@
1
+ export { DEFAULT_BUSINESS_TYPES, DEFAULT_ITEM_TYPES, buildFindings } from "./findings.js";
2
+ export { computeScores, WEIGHTS } from "./scores.js";
3
+ export { renderSummary } from "./summary.js";
@@ -0,0 +1,2 @@
1
+ import type { LighthouseRun } from "./types.ts";
2
+ export declare function runLighthouse(urls: string[], outDir: string): Promise<LighthouseRun[]>;
@@ -0,0 +1,84 @@
1
+ import * as chromeLauncher from "chrome-launcher";
2
+ import lighthouse from "lighthouse";
3
+ import desktopConfig from "lighthouse/core/config/desktop-config.js";
4
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
5
+ import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
+ import { extraHeaders } from "./fetch.js";
8
+ const METRICS = {
9
+ lcpMs: "largest-contentful-paint",
10
+ fcpMs: "first-contentful-paint",
11
+ tbtMs: "total-blocking-time",
12
+ cls: "cumulative-layout-shift",
13
+ speedIndexMs: "speed-index",
14
+ ttfbMs: "server-response-time",
15
+ };
16
+ export async function runLighthouse(urls, outDir) {
17
+ // Own profile dir, passed as a raw flag: on WSL chrome-launcher rewrites its
18
+ // `userDataDir` option to a Windows path and creates it as a relative folder
19
+ // in the cwd ("C:\\Users\\...\\lighthouse.*"), even for a Linux Chrome.
20
+ const userDataDir = await mkdtemp(join(tmpdir(), "site-eval-chrome-"));
21
+ const chrome = await chromeLauncher.launch({
22
+ chromeFlags: [
23
+ "--headless=new",
24
+ "--no-first-run",
25
+ `--user-data-dir=${userDataDir}`,
26
+ ],
27
+ userDataDir: false,
28
+ });
29
+ const runs = [];
30
+ try {
31
+ for (const [i, url] of urls.entries()) {
32
+ for (const formFactor of ["mobile", "desktop"]) {
33
+ const audit = () => lighthouse(url, {
34
+ port: chrome.port,
35
+ output: "html",
36
+ logLevel: "error",
37
+ extraHeaders,
38
+ }, formFactor === "desktop" ? desktopConfig : undefined);
39
+ let result = await audit();
40
+ // Trace errors like NO_NAVSTART are often transient; one retry is usually enough
41
+ if (result?.lhr.runtimeError)
42
+ result = (await audit()) ?? result;
43
+ if (!result)
44
+ continue;
45
+ const { lhr } = result;
46
+ const reportFile = `lighthouse-${i + 1}-${formFactor}.html`;
47
+ await writeFile(join(outDir, reportFile), result.report);
48
+ const shot = lhr.audits["final-screenshot"]?.details?.data?.match(/^data:image\/jpeg;base64,(.+)$/)?.[1];
49
+ const screenshot = shot ? `screen-${i + 1}-${formFactor}.jpg` : null;
50
+ if (shot && screenshot)
51
+ await writeFile(join(outDir, screenshot), Buffer.from(shot, "base64"));
52
+ const resources = lhr.audits["resource-summary"]?.details?.items ?? [];
53
+ const bytesOf = (type) => resources.find((r) => r.resourceType === type)?.transferSize ?? null;
54
+ const metricError = Object.values(METRICS)
55
+ .map((id) => lhr.audits[id]?.errorMessage)
56
+ .find(Boolean);
57
+ runs.push({
58
+ url,
59
+ formFactor,
60
+ scores: Object.fromEntries(Object.entries(lhr.categories).map(([k, c]) => [
61
+ k,
62
+ c.score === null ? null : Math.round(c.score * 100),
63
+ ])),
64
+ metrics: Object.fromEntries(Object.entries(METRICS).map(([k, id]) => [
65
+ k,
66
+ lhr.audits[id]?.numericValue ?? null,
67
+ ])),
68
+ totalBytes: bytesOf("total"),
69
+ scriptBytes: bytesOf("script"),
70
+ imageBytes: bytesOf("image"),
71
+ thirdPartyBytes: bytesOf("third-party"),
72
+ error: lhr.runtimeError?.message ?? metricError ?? null,
73
+ reportFile,
74
+ screenshot,
75
+ });
76
+ }
77
+ }
78
+ }
79
+ finally {
80
+ chrome.kill();
81
+ await rm(userDataDir, { recursive: true, force: true });
82
+ }
83
+ return runs;
84
+ }
@@ -0,0 +1,10 @@
1
+ import type { FetchResult } from "./fetch.ts";
2
+ import type { PageData } from "./types.ts";
3
+ export declare function analyzePage(res: FetchResult, origin: string): PageData;
4
+ /**
5
+ * Merges what the server sent (what Google and AI crawlers read first) with what a
6
+ * visitor's browser shows after JavaScript (chat widgets, WhatsApp buttons, prices
7
+ * loaded later). Contact checks use the rendered page, so a widget isn't reported
8
+ * missing; anything only there after JavaScript is listed in `jsOnly`.
9
+ */
10
+ export declare function withRendered(raw: PageData, dom: PageData): PageData;