seo-supervisor 0.0.0-stage → 2.0.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 (218) hide show
  1. package/.claude-plugin/icon.png +0 -0
  2. package/.claude-plugin/marketplace.json +16 -0
  3. package/.claude-plugin/plugin.json +27 -0
  4. package/CHANGELOG.md +461 -0
  5. package/LICENSE +25 -0
  6. package/NOTICE +7 -0
  7. package/README.md +402 -2
  8. package/agents/seo-auditor.md +16 -0
  9. package/agents/seo-reviewer.md +16 -0
  10. package/bin/agents.mjs +230 -0
  11. package/bin/extras.mjs +422 -0
  12. package/bin/prompt.mjs +96 -0
  13. package/bin/seo-supervisor.mjs +477 -0
  14. package/commands/seo-audit.md +33 -0
  15. package/commands/seo-brief.md +28 -0
  16. package/commands/seo-connect.md +27 -0
  17. package/commands/seo-fix.md +34 -0
  18. package/commands/seo-grow.md +26 -0
  19. package/commands/seo-launch.md +21 -0
  20. package/commands/seo-review.md +19 -0
  21. package/commands/seo-rewrite.md +25 -0
  22. package/commands/seo-setup.md +35 -0
  23. package/commands/seo-watch.md +28 -0
  24. package/hooks/hooks.json +117 -0
  25. package/package.json +58 -4
  26. package/skills/seo-supervisor/NOTICE +7 -0
  27. package/skills/seo-supervisor/SKILL.md +480 -0
  28. package/skills/seo-supervisor/audience.md +61 -0
  29. package/skills/seo-supervisor/examples/drafts/security.md +41 -0
  30. package/skills/seo-supervisor/examples/hooks/README.md +28 -0
  31. package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
  32. package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
  33. package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
  34. package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
  35. package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
  36. package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
  37. package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
  38. package/skills/seo-supervisor/examples/sample-audit.json +532 -0
  39. package/skills/seo-supervisor/examples/sample-report.html +704 -0
  40. package/skills/seo-supervisor/examples/sample-report.md +360 -0
  41. package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
  42. package/skills/seo-supervisor/examples/security-tools-profile.md +73 -0
  43. package/skills/seo-supervisor/examples/snippets.md +781 -0
  44. package/skills/seo-supervisor/frameworks/nextjs.md +98 -0
  45. package/skills/seo-supervisor/frameworks/rails.md +34 -0
  46. package/skills/seo-supervisor/frameworks/spa.md +14 -0
  47. package/skills/seo-supervisor/grow.md +342 -0
  48. package/skills/seo-supervisor/og-images.md +85 -0
  49. package/skills/seo-supervisor/page-types.md +124 -0
  50. package/skills/seo-supervisor/planning.md +157 -0
  51. package/skills/seo-supervisor/profile-template.md +96 -0
  52. package/skills/seo-supervisor/report-format.md +313 -0
  53. package/skills/seo-supervisor/rewrite.md +59 -0
  54. package/skills/seo-supervisor/rules/ai-search.md +93 -0
  55. package/skills/seo-supervisor/rules/content.md +84 -0
  56. package/skills/seo-supervisor/rules/crawl-index.md +92 -0
  57. package/skills/seo-supervisor/rules/internal-linking.md +104 -0
  58. package/skills/seo-supervisor/rules/launch-monitoring.md +57 -0
  59. package/skills/seo-supervisor/rules/media.md +42 -0
  60. package/skills/seo-supervisor/rules/metadata.md +71 -0
  61. package/skills/seo-supervisor/rules/performance.md +78 -0
  62. package/skills/seo-supervisor/rules/rendering.md +79 -0
  63. package/skills/seo-supervisor/rules/search-intent.md +32 -0
  64. package/skills/seo-supervisor/rules/sitemaps-robots.md +49 -0
  65. package/skills/seo-supervisor/rules/structured-data.md +98 -0
  66. package/skills/seo-supervisor/rules/trust-security.md +48 -0
  67. package/skills/seo-supervisor/rules/urls.md +54 -0
  68. package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
  69. package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
  70. package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
  71. package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
  72. package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
  73. package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
  74. package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
  75. package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
  76. package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
  77. package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
  78. package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
  79. package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
  80. package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
  81. package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
  82. package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
  83. package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
  84. package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
  85. package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
  86. package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
  87. package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
  88. package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
  89. package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
  90. package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
  91. package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
  92. package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
  93. package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
  94. package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
  95. package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
  96. package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
  97. package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
  98. package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
  99. package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
  100. package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
  101. package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
  102. package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
  103. package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
  104. package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
  105. package/skills/seo-supervisor/scripts/content-scan.mjs +530 -0
  106. package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
  107. package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
  108. package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
  109. package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
  110. package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
  111. package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
  112. package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
  113. package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
  114. package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
  115. package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
  116. package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
  117. package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
  118. package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
  119. package/skills/seo-supervisor/scripts/fonts/OFL-BricolageGrotesque.txt +93 -0
  120. package/skills/seo-supervisor/scripts/fonts/OFL-Geist.txt +93 -0
  121. package/skills/seo-supervisor/scripts/fonts/OFL-GeistMono.txt +93 -0
  122. package/skills/seo-supervisor/scripts/fonts/bricolage-grotesque.woff2 +0 -0
  123. package/skills/seo-supervisor/scripts/fonts/geist-mono.woff2 +0 -0
  124. package/skills/seo-supervisor/scripts/fonts/geist.woff2 +0 -0
  125. package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
  126. package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
  127. package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
  128. package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
  129. package/skills/seo-supervisor/scripts/google.mjs +1341 -0
  130. package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
  131. package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
  132. package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
  133. package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
  134. package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
  135. package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
  136. package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
  137. package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
  138. package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
  139. package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
  140. package/skills/seo-supervisor/scripts/guard.mjs +74 -0
  141. package/skills/seo-supervisor/scripts/images.mjs +408 -0
  142. package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
  143. package/skills/seo-supervisor/scripts/issues.mjs +217 -0
  144. package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
  145. package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
  146. package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
  147. package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
  148. package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
  149. package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
  150. package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
  151. package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
  152. package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
  153. package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
  154. package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
  155. package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
  156. package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
  157. package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
  158. package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
  159. package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
  160. package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
  161. package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
  162. package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
  163. package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
  164. package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
  165. package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
  166. package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
  167. package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
  168. package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
  169. package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
  170. package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
  171. package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
  172. package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
  173. package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
  174. package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
  175. package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
  176. package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
  177. package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
  178. package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
  179. package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
  180. package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
  181. package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
  182. package/skills/seo-supervisor/scripts/osm.mjs +359 -0
  183. package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
  184. package/skills/seo-supervisor/scripts/render-report.mjs +340 -0
  185. package/skills/seo-supervisor/scripts/report/client.js +37 -0
  186. package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
  187. package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
  188. package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
  189. package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
  190. package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
  191. package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
  192. package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
  193. package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
  194. package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
  195. package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
  196. package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
  197. package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
  198. package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
  199. package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
  200. package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
  201. package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
  202. package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
  203. package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
  204. package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
  205. package/skills/seo-supervisor/scripts/report/styles.css +223 -0
  206. package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
  207. package/skills/seo-supervisor/scripts/report-plan.mjs +241 -0
  208. package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
  209. package/skills/seo-supervisor/scripts/seo-crawl.mjs +1151 -0
  210. package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
  211. package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
  212. package/skills/seo-supervisor/site-types/content.md +55 -0
  213. package/skills/seo-supervisor/site-types/ecommerce.md +64 -0
  214. package/skills/seo-supervisor/site-types/local-business.md +118 -0
  215. package/skills/seo-supervisor/site-types/services.md +68 -0
  216. package/skills/seo-supervisor/site-types/tools.md +127 -0
  217. package/skills/seo-supervisor/strategy.md +232 -0
  218. package/skills/seo-supervisor/troubleshooting.md +56 -0
@@ -0,0 +1,1151 @@
1
+ #!/usr/bin/env node
2
+ // @ts-check
3
+ // Read-only SEO crawler: GET and HEAD only, plus a TLS handshake with --check-live.
4
+ // Regex HTML parsing is enough for audit evidence. Swap in a real parser if a site breaks it.
5
+
6
+ import { mkdirSync, writeFileSync, readFileSync, existsSync } from "node:fs";
7
+ import { basename, dirname, join, resolve } from "node:path";
8
+ import { createHash } from "node:crypto";
9
+ import { fileCrawl } from "./seo-diff.mjs";
10
+ import { chromeProxyArgs } from "./lib/proxy.mjs";
11
+ import { parseArgs } from "./lib/args.mjs";
12
+ import { Fail, runMain, warnProxy } from "./lib/cli.mjs";
13
+ import { loopback } from "./lib/net.mjs";
14
+ import { redact, hideSecrets } from "./lib/redact.mjs";
15
+ import { createFindings, quote } from "./lib/findings.mjs";
16
+ import { RULES, CHECKS } from "./crawl/catalog.mjs";
17
+ import { PAGE_MAX, clean, createFetcher, isLocal, isPublic, mapOrigin, urlOr } from "./crawl/fetch.mjs";
18
+ import { createCrawler } from "./crawl/queue.mjs";
19
+ import { checkRobots, versionedNote, aiBotAccess, aiRobotRules } from "./checks/robots.mjs";
20
+ import { SITEMAP_KEEP, findSitemaps, checkSitemapFiles, checkSitemapEntries } from "./checks/sitemap.mjs";
21
+ import { probeSite } from "./checks/probes.mjs";
22
+ import { checkPages } from "./checks/site-pages.mjs";
23
+ import { checkAssets, imageList, schemaImages, mediaData } from "./checks/assets.mjs";
24
+ import {
25
+ checkLinks,
26
+ slashStyle,
27
+ oldUrls,
28
+ outboundLinks,
29
+ linkedOnce,
30
+ linkStrength,
31
+ pageWords,
32
+ otherSites,
33
+ } from "./checks/links.mjs";
34
+ import { compareGooglebot, aiBotProbe, readPage } from "./checks/bots.mjs";
35
+ import { cookiesAndPolicies, securityHeaders } from "./checks/site-security.mjs";
36
+ import { agentData, bingAiPrefs, landmarks } from "./checks/site-agents.mjs";
37
+ import {
38
+ pageMarkup,
39
+ descStartsWithTitle,
40
+ pageSignals,
41
+ shopChecks,
42
+ contentChecks,
43
+ localData,
44
+ } from "./checks/site-content.mjs";
45
+ import { hygieneChecks, markdownCheck } from "./checks/site-hygiene.mjs";
46
+ import { checkCoverage } from "./checks/coverage.mjs";
47
+ import { checkLanguages, otherSiteTargets, linksBack } from "./checks/hreflang.mjs";
48
+ import { checkLive } from "./checks/tls.mjs";
49
+ import {
50
+ checkSpeed,
51
+ sampleUrls,
52
+ PSI_ENDPOINT,
53
+ speedTrend,
54
+ CRUX_HISTORY_ENDPOINT,
55
+ labLcpBreakdown,
56
+ } from "./checks/speed.mjs";
57
+ import { findBrowser, openSession, renderPage, renderFindings, renderAll } from "./checks/render.mjs";
58
+ import { checkPages as browserChecks } from "./checks/visual.mjs";
59
+ import { checkLighthouse, findLighthouse, ALL_CAP } from "./checks/lighthouse.mjs";
60
+ import { trustSignals } from "./checks/trust.mjs";
61
+ import { checkBusinessType, detectBusinessType } from "./checks/business-type.mjs";
62
+ import { slowNote } from "./checks/crawl.mjs";
63
+ import { maskKeys } from "./checks/hygiene.mjs";
64
+ warnProxy(); // once, before any request
65
+
66
+ const VERSION = "2.0.0";
67
+ const UA = "seo-supervisor-crawler/" + VERSION;
68
+
69
+ // ---------- args ----------
70
+ // An unknown option or unusable value stops the crawl (exit 2) before anything is asked of the site.
71
+ // Each option in FLAGS and BOOLEANS needs its own line here, at most 100 characters wide (test/help.test.mjs).
72
+ const USAGE = `Usage: node seo-crawl.mjs --url http://localhost:3000 [options]
73
+
74
+ Crawls a site and writes what it finds to one JSON file. Read-only: it sends only GET and HEAD
75
+ requests. Point it at a local or staging server when you can; against production keep
76
+ --concurrency low.
77
+
78
+ Basics
79
+ --url <address> where the crawl starts (required), like http://localhost:3000
80
+ --site-origin <address> the public address canonicals and sitemaps should use,
81
+ like https://www.example.com
82
+ --trailing-slash <style> auto (the default: detect the site's style, flag a mix), always
83
+ or never
84
+ --brand <name> flag titles that repeat the brand name
85
+ --ignore-noindex before launch: check noindex pages as if they could be indexed
86
+ --banned <pattern> flag visible text that matches (banned claims, wrong names)
87
+ --verify <pattern> flag claims the owner hasn't confirmed yet, as decisions
88
+
89
+ Scope
90
+ --max <n> crawl at most n pages (default 1000)
91
+ --concurrency <n> requests at once (default 8 on this computer, 4 on any other server)
92
+ --include <paths> crawl only these sections: comma-separated path starts, like /blog/
93
+ (the start page is still crawled, as the way in)
94
+ --exclude <paths> skip these sections, like /blog/tag/
95
+ --include-query crawl addresses with a ?query as pages of their own
96
+
97
+ Outside checks (each contacts more than the server being crawled, so each needs the owner's yes)
98
+ --check-live live site only: the certificate, the http-to-https and www/bare-domain
99
+ redirects, and HSTS (the "always use https" header) on --site-origin
100
+ --outside real-user speed from Google PageSpeed Insights for up to 10 public
101
+ pages (set PSI_API_KEY); a Chrome or Edge render of up to 10 pages on
102
+ desktop and phone, with screenshots (CHROME_PATH picks the browser);
103
+ Chrome's back/forward cache test and lab speed; with CRUX_API_KEY,
104
+ the site's 25-week speed trend
105
+ --render all with --outside: render every indexable page (up to 200, about 5 s
106
+ a page) instead of 10; it prints the time it expects first
107
+ --lighthouse [all|<n>] with --outside: Lighthouse on 5 sample pages, on every indexable
108
+ page (all: up to 200, about 20 s a page) or on n of them. Install it
109
+ first: npx seo-supervisor --with-lighthouse, or set LIGHTHOUSE_PATH
110
+ --desktop with --outside: send the same pages to PageSpeed again for desktop
111
+ (information only)
112
+ --render-page <address> with --outside: render one page you pick
113
+ --render-steps "<steps>" what to do on that page first, like "scroll; click .more; wait 1000"
114
+ (it never types)
115
+ --clean-screenshots with --outside: also save screenshots with cookie bars and chat
116
+ boxes hidden
117
+ --ai-bot-probe with --outside: ask up to 3 pages again as AI search crawlers, to see
118
+ whether a firewall turns them away
119
+ --hreflang-other-sites with --outside: visit up to 20 language versions on other sites, to
120
+ see whether they link back
121
+ --outbound-links visit up to 100 links to other sites, to find broken ones (never
122
+ private or local addresses)
123
+ --psi-endpoint <address> send the PageSpeed requests here instead of to Google (for tests)
124
+ --crux-endpoint <address> send the speed-trend requests here instead of to Google (for tests)
125
+
126
+ Data inputs
127
+ --urls <file> old addresses or redirect sources to test: one per line, a CSV's first
128
+ column, or a JSON array
129
+ --next-manifest <file> test every fixed-path redirect in a Next.js build's
130
+ .next/routes-manifest.json
131
+ --gsc-indexing <file> Search Console's Page indexing export (its Chart.csv): Google's
132
+ indexed count beside the crawl's, information only
133
+
134
+ Output
135
+ --out <file> where the crawl is written (default seo-audit/seo-crawl.json);
136
+ screenshots go in screenshots/ next to it
137
+ --help, -h show this help`;
138
+ const FLAGS = [
139
+ "url",
140
+ "site-origin",
141
+ "trailing-slash",
142
+ "brand",
143
+ "banned",
144
+ "verify",
145
+ "urls",
146
+ "next-manifest",
147
+ "psi-endpoint",
148
+ "crux-endpoint",
149
+ "render",
150
+ "lighthouse",
151
+ "render-page",
152
+ "render-steps",
153
+ "include",
154
+ "exclude",
155
+ "gsc-indexing",
156
+ "max",
157
+ "concurrency",
158
+ "out",
159
+ ];
160
+ const BOOLEANS = [
161
+ "ignore-noindex",
162
+ "check-live",
163
+ "outside",
164
+ "outbound-links",
165
+ "desktop",
166
+ "hreflang-other-sites",
167
+ "ai-bot-probe",
168
+ "clean-screenshots",
169
+ "include-query",
170
+ ];
171
+ /** @type {{ args: ReturnType<typeof parseArgs>, browser: string | null } | undefined} */
172
+ let options;
173
+ await runMain(() => {
174
+ const a = parseArgs(process.argv.slice(2), { flags: FLAGS, booleans: BOOLEANS, positionals: 0, usage: USAGE });
175
+ if (typeof a.url !== "string")
176
+ throw new Fail(
177
+ `${USAGE.slice(0, USAGE.indexOf("\n"))}\n--url is required. Every option: node seo-crawl.mjs --help`,
178
+ );
179
+ const no = (k, why) => {
180
+ throw new Fail(`seo-crawl: --${k} ${why}`);
181
+ };
182
+ for (const k of ["url", "site-origin"])
183
+ if (k in a && !(URL.canParse(a[k]) && /^https?:$/.test(new URL(a[k]).protocol)))
184
+ no(k, `needs a full web address, like http://localhost:3000 (got “${a[k]}”).`);
185
+ for (const k of ["max", "concurrency"])
186
+ if (k in a && !/^[1-9]\d*$/.test(a[k]))
187
+ no(k, `needs a whole number of 1 or more, like --${k} ${k === "max" ? 1000 : 4}.`);
188
+ for (const k of ["banned", "verify"])
189
+ if (typeof a[k] === "string")
190
+ try {
191
+ new RegExp(a[k], "i");
192
+ } catch (e) {
193
+ no(k, `isn't a valid pattern (${e.message}).`);
194
+ }
195
+ // With --outside, find the browser first: a CHROME_PATH that points at nothing stops the crawl before it starts.
196
+ let browser = null;
197
+ if (a.outside)
198
+ try {
199
+ browser = findBrowser();
200
+ } catch (e) {
201
+ throw new Fail(`seo-crawl: ${e.message}`);
202
+ }
203
+ options = { args: a, browser };
204
+ });
205
+ if (!options) process.exit(); // runMain said why and set the exit code; nothing has been asked of the site yet
206
+ const { args, browser } = options;
207
+ const START = new URL(args.url);
208
+ const START_ORIGIN = START.origin;
209
+ const MAX = Number(args.max || 1000);
210
+ const IGNORE_NOINDEX = !!args["ignore-noindex"];
211
+ const BANNED = typeof args.banned === "string" ? new RegExp(args.banned, "i") : null;
212
+ const VERIFY = typeof args.verify === "string" ? new RegExp(args.verify, "i") : null;
213
+ const URL_LIST = typeof args.urls === "string" ? args.urls : null;
214
+ const NEXT_MANIFEST = typeof args["next-manifest"] === "string" ? args["next-manifest"] : null;
215
+ // Locally the server's own speed is the limit, so 8 at once; 4 against any other server.
216
+ const CONC = Number(args.concurrency || (loopback(START.hostname) ? 8 : 4));
217
+ const SLASH = ["always", "never"].includes(args["trailing-slash"]) ? args["trailing-slash"] : "auto";
218
+ const BRAND = typeof args.brand === "string" ? args.brand : "";
219
+ const INCLUDE_QUERY = !!args["include-query"];
220
+ const CHECK_LIVE = !!args["check-live"];
221
+ const OUTSIDE = !!args.outside; // nothing leaves the machine without it
222
+ const LIGHTHOUSE_ALL = args.lighthouse === "all"; // --lighthouse all, or --lighthouse=all
223
+ const LIGHTHOUSE = !!args.lighthouse;
224
+ const RENDER_ALL = args.render === "all"; // with --outside: every indexable page, not the sample
225
+ const DESKTOP = !!args.desktop; // a separate opt-in: it sends the sample URLs to Google a second time
226
+ const OUT = resolve(typeof args.out === "string" ? args.out : "seo-audit/seo-crawl.json");
227
+ let SITE_ORIGIN = typeof args["site-origin"] === "string" ? new URL(args["site-origin"]).origin : "";
228
+ // Public-origin URLs mapped onto the crawl origin. SITE_ORIGIN may still be found while the crawl runs (robots.txt's
229
+ // Sitemap: line, the sitemap, the home page's canonical), so every module gets this function, never the value.
230
+ const toCrawl = u => mapOrigin(u, SITE_ORIGIN, START_ORIGIN);
231
+ const { get, follow, firstBytes, fetchSitemap, xRobotsLines, blocked, slow } = createFetcher({
232
+ startOrigin: START_ORIGIN,
233
+ ua: UA,
234
+ toCrawl,
235
+ });
236
+ const notes = [];
237
+ // --include and --exclude: comma-separated path prefixes, so one crawl can cover one section such as /blog/.
238
+ const pathList = k =>
239
+ typeof args[k] === "string"
240
+ ? args[k]
241
+ .split(",")
242
+ .map(s => s.trim())
243
+ .filter(Boolean)
244
+ .map(s => "/" + s.replace(/^\/+/, ""))
245
+ : [];
246
+ const INCLUDE = pathList("include"),
247
+ EXCLUDE = pathList("exclude"),
248
+ SECTION = INCLUDE.length > 0 || EXCLUDE.length > 0;
249
+ const inSection = path =>
250
+ (!INCLUDE.length || INCLUDE.some(p => path.startsWith(p))) && !EXCLUDE.some(p => path.startsWith(p));
251
+ const AI_PROBE = !!args["ai-bot-probe"];
252
+ const RENDER_PAGE = typeof args["render-page"] === "string" ? args["render-page"] : null;
253
+ const RENDER_STEPS = typeof args["render-steps"] === "string" ? args["render-steps"] : "";
254
+ const CLEAN_SHOTS = !!args["clean-screenshots"];
255
+ // Every finding's URL and detail is scrubbed of secret keys, secret query values and home folders, whichever check adds
256
+ // it, so no secret reaches the crawl file through another check's evidence. Notes and notChecked reasons get the same
257
+ // scrub on output, emails included.
258
+ const { findings, add, evaluated, evalRules, notChecked, skip, list } = createFindings(
259
+ CHECKS,
260
+ s => redact(maskKeys(s), { emails: false }),
261
+ RULES,
262
+ );
263
+
264
+ // Sitemap <xhtml:link> hreflang by crawl URL, built on first use: `sm` is only read later, before the crawl starts.
265
+ let smHreflang;
266
+ const sitemapHreflang = u =>
267
+ (smHreflang ||= new Map(sm.entries.filter(e => e.hreflang).map(e => [clean(toCrawl(e.loc)), e.hreflang]))).get(
268
+ clean(u),
269
+ ) || [];
270
+ // analyze()'s context (crawl/page.mjs). toCrawl and sitemapHreflang are passed as functions: their data arrives later.
271
+ const page = { start: START, startOrigin: START_ORIGIN, banned: BANNED, verify: VERIFY, toCrawl, sitemapHreflang };
272
+
273
+ // ---------- crawl ----------
274
+ const crawler = createCrawler({
275
+ start: START,
276
+ startOrigin: START_ORIGIN,
277
+ max: MAX,
278
+ conc: CONC,
279
+ includeQuery: INCLUDE_QUERY,
280
+ inSection,
281
+ fetcher: { follow, xRobotsLines },
282
+ page,
283
+ toCrawl,
284
+ notes,
285
+ });
286
+ const { pages, queue, seen, enqueue } = crawler;
287
+
288
+ // ---------- main ----------
289
+ const t0 = Date.now();
290
+ const robotsRes = await follow(START_ORIGIN + "/robots.txt", undefined, 5); // Google stops after 5 hops here, 10 for pages
291
+ const { robots, robotsDown, star } = checkRobots(robotsRes, { add, evalRules, startOrigin: START_ORIGIN });
292
+ const smUrls = robots && robots.sitemaps.length ? robots.sitemaps : [START_ORIGIN + "/sitemap.xml"];
293
+ const firstSm = smUrls[0];
294
+ if (!SITE_ORIGIN) {
295
+ try {
296
+ const o = new URL(firstSm).origin;
297
+ if (o !== START_ORIGIN) SITE_ORIGIN = o;
298
+ } catch {}
299
+ }
300
+ const smListed = !!(robots && robots.sitemaps.length);
301
+ const sm = await findSitemaps(smUrls, smListed, {
302
+ startOrigin: START_ORIGIN,
303
+ notes,
304
+ fetchSitemap,
305
+ toCrawl,
306
+ conc: CONC,
307
+ });
308
+ if (!SITE_ORIGIN && sm.entries.length) {
309
+ try {
310
+ const o = new URL(sm.entries[0].loc).origin;
311
+ if (o !== START_ORIGIN && !isLocal(o)) SITE_ORIGIN = o;
312
+ } catch {}
313
+ }
314
+ checkSitemapFiles(sm, smUrls, { add, findings });
315
+ // The home page goes first: its canonical may give the public origin.
316
+ enqueue(START.href);
317
+ await crawler.run();
318
+ const home = pages.get(START.href);
319
+ if (!SITE_ORIGIN && home && home.canonicals && home.canonicals[0]) {
320
+ try {
321
+ const o = new URL(home.canonicals[0], home.base).origin;
322
+ if (o !== START_ORIGIN && !isLocal(o)) SITE_ORIGIN = o;
323
+ } catch {}
324
+ }
325
+ const EXPECT_ORIGIN = SITE_ORIGIN || START_ORIGIN;
326
+ if (SITE_ORIGIN && SITE_ORIGIN !== START_ORIGIN)
327
+ notes.push(`Public origin ${SITE_ORIGIN} was mapped onto ${START_ORIGIN} for crawling.`);
328
+ const smSet = checkSitemapEntries(sm, firstSm, {
329
+ add,
330
+ notes,
331
+ evalRules,
332
+ expectOrigin: EXPECT_ORIGIN,
333
+ startOrigin: START_ORIGIN,
334
+ toCrawl,
335
+ inSection,
336
+ crawler: { seen, queue },
337
+ });
338
+ await crawler.run();
339
+ const { fetched, capped } = crawler; // final from here: the queue runs no more
340
+ // A page over the read limit (crawl/queue.mjs) isn't read, but it's surely past Googlebot's 2 MB too (REND-08).
341
+ for (const p of pages.values())
342
+ if (p.over) add("html-over-2mb", p.finalUrl, `over ${PAGE_MAX / 1048576} MB once unpacked, so it wasn't read`);
343
+ // Pages a bot challenge answered instead (crawl/queue.mjs): not checked, and not reported as broken either.
344
+ if (crawler.challenges.length)
345
+ notes.push(
346
+ `${crawler.challenges.length} page(s) answered with a bot challenge (from Cloudflare or AWS WAF) instead of the page, e.g. ${quote(crawler.challenges[0])}, so they weren't checked. Let the crawler through (allow this machine's address, or the user agent ${UA}) or crawl a staging copy, then run it again.`,
347
+ );
348
+
349
+ // Soft 404, llms.txt, Markdown, security.txt and the home page's security headers.
350
+ const mdHome = await probeSite({
351
+ start: START,
352
+ startOrigin: START_ORIGIN,
353
+ expectOrigin: EXPECT_ORIGIN,
354
+ checkLive: CHECK_LIVE,
355
+ conc: CONC,
356
+ home,
357
+ add,
358
+ evalRules,
359
+ notes,
360
+ follow,
361
+ get,
362
+ pages,
363
+ });
364
+
365
+ // ---------- per-page checks ----------
366
+ evalRules(
367
+ "AI-01",
368
+ "REND-08",
369
+ "CONTENT-04",
370
+ "REND-04",
371
+ "CONTENT-09",
372
+ "CRAWL-02",
373
+ "CRAWL-06",
374
+ "CRAWL-07",
375
+ "CRAWL-08",
376
+ "URL-01",
377
+ "URL-04",
378
+ "URL-05",
379
+ "REND-01",
380
+ "META-01",
381
+ "META-02",
382
+ "META-04",
383
+ "META-05",
384
+ "CONTENT-01",
385
+ "CONTENT-02",
386
+ "CONTENT-05",
387
+ "CONTENT-08",
388
+ "SCHEMA-01",
389
+ "SCHEMA-02",
390
+ "SCHEMA-03",
391
+ "SCHEMA-04",
392
+ "SCHEMA-05",
393
+ "SCHEMA-07",
394
+ "MAP-03",
395
+ "LINK-01",
396
+ "LINK-02",
397
+ "LINK-05",
398
+ "LINK-06",
399
+ "PERF-03",
400
+ "PERF-04",
401
+ "PERF-06",
402
+ "REND-09",
403
+ "META-06",
404
+ "MEDIA-03",
405
+ );
406
+ if (BRAND) evalRules("META-03");
407
+ if (BANNED || VERIFY) evalRules("CONTENT-10");
408
+ const all = [...pages.values()];
409
+ const byFinal = new Map();
410
+ for (const p of all) if (p.finalUrl) byFinal.set(p.finalUrl, p);
411
+ // One record per page: a link or canonical to a URL that redirects fetches its page again, so the direct fetch is kept.
412
+ const byPage = new Map();
413
+ for (const p of all) if (p.html && (!byPage.has(p.finalUrl) || p.url === p.finalUrl)) byPage.set(p.finalUrl, p);
414
+ const htmlPages = [...byPage.values()];
415
+ const finalOf = u => pages.get(u)?.finalUrl || u;
416
+ const isHome = p => new URL(p.finalUrl).pathname === "/";
417
+
418
+ const canonicalFor = p => {
419
+ const c = p.canonicals && p.canonicals[0];
420
+ return c ? (urlOr(c, p.base)?.href ?? null) : null;
421
+ };
422
+ const samePath = (a, b) => new URL(a).pathname === new URL(b).pathname;
423
+ const indexable = p =>
424
+ p.html &&
425
+ (IGNORE_NOINDEX || !p.noindex) &&
426
+ (() => {
427
+ const c = canonicalFor(p);
428
+ return !c || samePath(toCrawl(c), p.finalUrl);
429
+ })();
430
+ // The site's own hosts, with or without www: on an HTTPS site an http:// link to them costs a redirect.
431
+ const bareHost = h => h.replace(/^www\./, "");
432
+ const selfHosts = new Set([START_ORIGIN, EXPECT_ORIGIN].map(o => bareHost(new URL(o).host)));
433
+ const extra = {}; // data for the report, filled by the site-wide checks below
434
+ // Shared context for the site-wide checks. From here on only the page records' own fields, `all` (old URLs join it),
435
+ // extra, notes, notChecked and the finding store change.
436
+ const site = {
437
+ all,
438
+ pages,
439
+ byPage,
440
+ byFinal,
441
+ htmlPages,
442
+ home,
443
+ smSet,
444
+ robots,
445
+ star,
446
+ add,
447
+ evalRules,
448
+ evaluated,
449
+ findings,
450
+ notes,
451
+ notChecked,
452
+ extra,
453
+ ignoreNoindex: IGNORE_NOINDEX,
454
+ brand: BRAND,
455
+ start: START,
456
+ startOrigin: START_ORIGIN,
457
+ expectOrigin: EXPECT_ORIGIN,
458
+ conc: CONC,
459
+ toCrawl,
460
+ get,
461
+ follow,
462
+ firstBytes,
463
+ finalOf,
464
+ isHome,
465
+ canonicalFor,
466
+ samePath,
467
+ indexable,
468
+ bareHost,
469
+ selfHosts,
470
+ };
471
+ const { checkedPages, images, shareImages, titleWords, brandWords, acronyms, localBusiness } = checkPages(site);
472
+ // Runs before the Googlebot test. Each image is asked once; extra.images reuses the rows.
473
+ const { imageRows, imageInfo } = await checkAssets(site, { images, shareImages });
474
+ const { inbound } = checkLinks(site);
475
+ const style = await slashStyle(site, SLASH);
476
+
477
+ // ---------- old URLs / redirect sources ----------
478
+ const redirectSources = await oldUrls(site, { urlList: URL_LIST, nextManifest: NEXT_MANIFEST });
479
+
480
+ // ---------- live origin: certificate, http→https and other-host redirects, HSTS ----------
481
+ // One deeper page tests whether the other host's redirect keeps the path.
482
+ const live =
483
+ CHECK_LIVE && EXPECT_ORIGIN.startsWith("https:") && isPublic(EXPECT_ORIGIN)
484
+ ? await checkLive(EXPECT_ORIGIN, {
485
+ add,
486
+ path: (p => p && new URL(p.finalUrl).pathname)(htmlPages.find(p => !isHome(p) && indexable(p))),
487
+ })
488
+ : null;
489
+ if (live) notes.push(...live.notes);
490
+ if (live && !live.unresolved) evalRules("TRUST-07", "URL-03");
491
+ else
492
+ for (const rule of ["TRUST-07", "URL-03"])
493
+ notChecked.push({
494
+ rule,
495
+ area: `${rule} ${RULES[rule][0]}`,
496
+ reason: live
497
+ ? `${new URL(EXPECT_ORIGIN).hostname} doesn't resolve in DNS yet; run --check-live once the site is live.`
498
+ : CHECK_LIVE
499
+ ? "--check-live needs a public https:// origin; pass --site-origin."
500
+ : "Pass --check-live once the site is live.",
501
+ });
502
+
503
+ // ---------- outside checks: real-user speed ----------
504
+ /** @typedef {{ trend?: any, lcpBreakdown?: any, note?: string }} TrendResult */
505
+ /** @type {{ strategy: string, samples: any[], trend?: any, lcpBreakdown?: any, desktop?: any, tablet?: any, pageTrend?: any }} */
506
+ let speed;
507
+ let speedReason = OUTSIDE
508
+ ? "Speed data needs the public, live site; pass --site-origin."
509
+ : "Outside checks are off. With the owner's go-ahead, --outside fetches real-user speed data from Google PageSpeed Insights.";
510
+ const SPEED_ON = OUTSIDE && isPublic(EXPECT_ORIGIN),
511
+ PSI_AT = typeof args["psi-endpoint"] === "string" ? args["psi-endpoint"] : PSI_ENDPOINT,
512
+ CRUX_AT = typeof args["crux-endpoint"] === "string" ? args["crux-endpoint"] : CRUX_HISTORY_ENDPOINT;
513
+ const speedUrls = SPEED_ON
514
+ ? sampleUrls(
515
+ htmlPages
516
+ .filter(p => indexable(p) && !p.clientOnly)
517
+ .map(p => {
518
+ const x = new URL(p.finalUrl);
519
+ return EXPECT_ORIGIN + x.pathname + x.search;
520
+ }),
521
+ )
522
+ : [];
523
+ let speedLimited = false;
524
+ if (SPEED_ON) {
525
+ const r = await checkSpeed(speedUrls, { add, endpoint: PSI_AT, key: process.env.PSI_API_KEY });
526
+ if (r.samples.length) speed = { strategy: "mobile", samples: r.samples };
527
+ notes.push(...r.notes);
528
+ speedLimited = r.limited;
529
+ // PERF-01 counts as checked only when real-user data came back for at least one page.
530
+ if (r.samples.some(s => s.field)) {
531
+ evalRules("PERF-01");
532
+ speedReason = null;
533
+ } else
534
+ speedReason = r.limited
535
+ ? "PageSpeed refused the requests. Set PSI_API_KEY (a free Google Cloud API key for the PageSpeed Insights API) and re-run."
536
+ : "No real-user data came back for the sampled pages (too few Chrome visits, or PageSpeed failed); see the notes.";
537
+ }
538
+ if (speedReason) notChecked.push({ rule: "PERF-01", area: `PERF-01 ${RULES["PERF-01"][0]}`, reason: speedReason });
539
+ // The 25-week trend for the whole origin, only with a key (CRUX_API_KEY, or a PSI_API_KEY with the CrUX API enabled).
540
+ const CRUX_KEY = process.env.CRUX_API_KEY || process.env.PSI_API_KEY;
541
+ if (SPEED_ON && CRUX_KEY) {
542
+ const t = /** @type {TrendResult} */ (
543
+ await speedTrend(EXPECT_ORIGIN, { key: CRUX_KEY, endpoint: CRUX_AT }).catch(e => ({
544
+ note: `CrUX history failed (${e.message}).`,
545
+ }))
546
+ );
547
+ if (t.trend)
548
+ speed = {
549
+ ...(speed || { strategy: "mobile", samples: [] }),
550
+ trend: t.trend,
551
+ ...(t.lcpBreakdown ? { lcpBreakdown: t.lcpBreakdown } : {}),
552
+ };
553
+ if (t.note) notes.push(t.note);
554
+ }
555
+ // Desktop never makes a finding or counts in the score: PERF-01 is about phones, the version Google indexes.
556
+ if (DESKTOP && !OUTSIDE)
557
+ notes.push(
558
+ "--desktop runs only with outside checks on (--outside): it sends the sample URLs to Google PageSpeed Insights again, for desktop. It didn't run.",
559
+ );
560
+ else if (DESKTOP && !SPEED_ON)
561
+ notes.push("--desktop didn't run: speed data needs the public, live site; pass --site-origin.");
562
+ else if (DESKTOP && speedLimited)
563
+ notes.push(
564
+ "--desktop didn't run: PageSpeed refused the phone requests, so the desktop ones weren't sent. Set PSI_API_KEY (a free Google Cloud API key for the PageSpeed Insights API) and re-run.",
565
+ );
566
+ else if (DESKTOP) {
567
+ const d = await checkSpeed(speedUrls, {
568
+ add: () => {},
569
+ endpoint: PSI_AT,
570
+ key: process.env.PSI_API_KEY,
571
+ strategy: "desktop",
572
+ });
573
+ const t = CRUX_KEY
574
+ ? await speedTrend(EXPECT_ORIGIN, { key: CRUX_KEY, endpoint: CRUX_AT, formFactor: "DESKTOP" }).catch(e => ({
575
+ note: `CrUX history (desktop) failed (${e.message}).`,
576
+ }))
577
+ : {};
578
+ notes.push(...d.notes, ...(t.note ? [t.note] : []));
579
+ if (d.samples.length || t.trend)
580
+ speed = {
581
+ ...(speed || { strategy: "mobile", samples: [] }),
582
+ desktop: {
583
+ strategy: "desktop",
584
+ samples: d.samples,
585
+ ...(t.trend ? { trend: t.trend } : {}),
586
+ ...(t.lcpBreakdown ? { lcpBreakdown: t.lcpBreakdown } : {}),
587
+ },
588
+ };
589
+ }
590
+
591
+ // ---------- outside checks: what JavaScript changes ----------
592
+ const renderSample = sampleUrls(htmlPages.filter(p => indexable(p) && !p.refreshTo).map(p => p.finalUrl)); // a meta refresh would render its target
593
+ // --render all: every page meant to rank (as Lighthouse's all mode takes them), capped, after the time estimate.
594
+ const renderEvery =
595
+ browser && RENDER_ALL
596
+ ? renderAll([...new Set(htmlPages.filter(p => indexable(p) && !p.refreshTo).map(p => p.finalUrl))], {
597
+ log: console.log,
598
+ })
599
+ : null;
600
+ const renderList = renderEvery?.urls || renderSample;
601
+ // One Chrome behind the site's guard serves the renders (each in an isolated tab), then the phone and desktop loads.
602
+ // Lighthouse starts its own.
603
+ let sessionError = /** @type {Error | null} */ (null);
604
+ const session =
605
+ browser && (renderList.length || RENDER_PAGE)
606
+ ? await openSession(browser, renderList[0] ?? START.href).catch(e => {
607
+ sessionError = e;
608
+ return null;
609
+ })
610
+ : null;
611
+ let renderFailure = null;
612
+ if (browser) {
613
+ let rendered = 0;
614
+ if (sessionError) renderFailure = String(sessionError.message).split("\n")[0].slice(0, 120);
615
+ else
616
+ for (const u of renderList) {
617
+ try {
618
+ const [rawRes, dom] = await Promise.all([get(u, { manual: false }), renderPage(browser, u, {}, session)]);
619
+ if (rawRes.status !== 200 || !rawRes.body) {
620
+ renderFailure ||= `the raw HTML of ${u} couldn't be fetched again`;
621
+ continue;
622
+ }
623
+ rendered++;
624
+ renderFindings(u, rawRes.body, dom, { add, clientRendered: !!byPage.get(u)?.clientOnly });
625
+ } catch (e) {
626
+ renderFailure ||= String(e.message).split("\n")[0].slice(0, 120);
627
+ }
628
+ }
629
+ if (rendered) {
630
+ evalRules("REND-06");
631
+ notes.push(
632
+ `Rendered ${rendered} of ${renderList.length} ${renderEvery ? "" : "sample "}page(s) in headless ${/edge/i.test(browser) ? "Edge" : "Chrome"} and compared them with the raw HTML.${renderFailure ? ` Some failed: ${renderFailure}` : ""}`,
633
+ );
634
+ } else
635
+ notChecked.push({
636
+ rule: "REND-06",
637
+ area: `REND-06 ${RULES["REND-06"][0]}`,
638
+ reason: `The browser at ${browser} couldn't render the sample pages (${renderFailure || "no pages to render"}).`,
639
+ });
640
+ } else
641
+ notChecked.push({
642
+ rule: "REND-06",
643
+ area: `REND-06 ${RULES["REND-06"][0]}`,
644
+ reason: OUTSIDE
645
+ ? "Chrome or Edge isn't installed (or set CHROME_PATH), so rendered pages couldn't be compared with the raw HTML."
646
+ : "Outside checks are off. With the owner's go-ahead, --outside renders sample pages in headless Chrome (running the site's own scripts) and compares them with the raw HTML.",
647
+ });
648
+
649
+ // ---------- outside checks: phone and desktop loads, screenshots, lab speed ----------
650
+ let labSpeed,
651
+ visualReason = OUTSIDE
652
+ ? "Chrome or Edge isn't installed (or set CHROME_PATH), so pages couldn't be loaded at phone size."
653
+ : "Outside checks are off. With the owner's go-ahead, --outside loads sample pages in headless Chrome at desktop and phone size (running the site's own scripts) and saves screenshots.";
654
+ let bfTested = 0,
655
+ bfReason = OUTSIDE
656
+ ? "Chrome or Edge isn't installed (or set CHROME_PATH)"
657
+ : "outside checks are off (with the owner's go-ahead, --outside runs it in headless Chrome)";
658
+ /** @type {{ checked: number, pages: any[], chosen: any, notes: string[] } | null} */
659
+ let more = null; // the render checks (REND-11), read from the same loads; their notes and data go in further down
660
+ if (browser) {
661
+ // --render-page's raw HTML is read first for the comparison.
662
+ let chosen = null;
663
+ if (RENDER_PAGE) {
664
+ const u = urlOr(RENDER_PAGE, START.href);
665
+ if (u && /^https?:$/.test(u.protocol)) {
666
+ const res = await get(u.href, { manual: false }).catch(() => null);
667
+ chosen = { url: u.href, steps: RENDER_STEPS, raw: res?.status === 200 && res.body ? res.body : null };
668
+ } else notes.push(`--render-page needs an http or https address; “${RENDER_PAGE}” isn't one, so it didn't run.`);
669
+ }
670
+ const failed = e => {
671
+ const why = String(e.message).split("\n")[0].slice(0, 160);
672
+ return {
673
+ visual: { checked: 0, lab: [], notes: [`the browser didn't start: ${why}`], bfTested: 0 },
674
+ more: { checked: 0, pages: [], chosen: null, notes: [`the browser didn't start for the render checks: ${why}`] },
675
+ };
676
+ };
677
+ const both = sessionError
678
+ ? failed(sessionError)
679
+ : await browserChecks(browser, renderSample, {
680
+ add,
681
+ screenshotDir: resolve(dirname(OUT), "screenshots"),
682
+ rawWords: new Map(htmlPages.filter(p => !p.clientOnly).map(p => [p.finalUrl, p.words])),
683
+ clean: CLEAN_SHOTS,
684
+ chosen,
685
+ session,
686
+ }).catch(failed);
687
+ await session?.close();
688
+ const v = both.visual;
689
+ more = both.more;
690
+ if (v.lab.length) labSpeed = v.lab;
691
+ if (v.checked) {
692
+ evalRules("REND-07", "PERF-07");
693
+ visualReason = null;
694
+ notes.push(...v.notes);
695
+ } else
696
+ visualReason = `The browser at ${browser} couldn't load the sample pages (${v.notes[0] || "no pages to load"}).`;
697
+ bfTested = v.bfTested || 0;
698
+ bfReason = !renderSample.length
699
+ ? "no page meant to rank could be tested"
700
+ : renderSample.length < 2
701
+ ? "only one page could be tested, and Back needs a second page to come back from"
702
+ : !v.checked
703
+ ? "the browser couldn't load the sample pages"
704
+ : "it timed out on every page (see the notes)";
705
+ }
706
+ if (visualReason)
707
+ for (const rule of ["REND-07", "PERF-07"])
708
+ notChecked.push({ rule, area: `${rule} ${RULES[rule][0]}`, reason: visualReason });
709
+ // PERF-10 passes only when Chrome's own test ran; without it the HTML hints can still raise a finding, but not pass it.
710
+ if (bfTested) evalRules("PERF-10");
711
+ else if (!findings.has("bfcache-no-store") && !findings.has("bfcache-unload"))
712
+ notChecked.push({
713
+ rule: "PERF-10",
714
+ area: `PERF-10 ${RULES["PERF-10"][0]}`,
715
+ reason: `Chrome's back/forward cache test didn't run: ${bfReason}.${checkedPages ? " The HTML hints (Cache-Control: no-store, inline unload handlers) found nothing." : ""}`,
716
+ });
717
+
718
+ // ---------- outside checks: Lighthouse, an optional add-on (scores only, no findings) ----------
719
+ let lighthouse;
720
+ const lighthouseBin = LIGHTHOUSE && OUTSIDE ? findLighthouse() : null;
721
+ if (LIGHTHOUSE && !OUTSIDE)
722
+ notes.push(
723
+ "--lighthouse runs only with outside checks on (--outside): Lighthouse loads each page and runs its scripts, analytics included. It didn't run.",
724
+ );
725
+ else if (LIGHTHOUSE && !lighthouseBin)
726
+ notes.push(
727
+ "Lighthouse isn't installed, so it didn't run. Add it with `npx seo-supervisor --with-lighthouse` (about 170 MB, outside the project), or `npm i -g lighthouse`.",
728
+ );
729
+ else if (lighthouseBin) {
730
+ // all: every page meant to rank, without the sample's one-per-folder pick; the estimate prints before the runs.
731
+ const every = [...new Set(htmlPages.filter(p => indexable(p) && !p.refreshTo).map(p => p.finalUrl))];
732
+ // --lighthouse 20: that many pages meant to rank, the sample first and then the rest, up to all mode's cap.
733
+ const asked = /^\d+$/.test(args.lighthouse) ? Math.min(Number(args.lighthouse), ALL_CAP) : 0;
734
+ const r = await checkLighthouse(
735
+ lighthouseBin,
736
+ LIGHTHOUSE_ALL ? every : asked ? [...new Set([...renderSample, ...every])] : renderSample,
737
+ { chromePath: browser, all: LIGHTHOUSE_ALL || asked > 0, ...(asked ? { max: asked } : {}), log: console.log },
738
+ );
739
+ if (r.results.length) lighthouse = r.results;
740
+ notes.push(...r.notes);
741
+ }
742
+ // Which part of LCP takes longest: real visitors' (from the trend above), else a PageSpeed or Lighthouse lab run's.
743
+ const labLcp = speed?.lcpBreakdown
744
+ ? null
745
+ : labLcpBreakdown([...(speed?.samples || []).map(s => ({ url: s.url, ...s.lab })), ...(lighthouse || [])]);
746
+ if (labLcp) speed = { ...(speed || { strategy: "mobile", samples: [] }), lcpBreakdown: labLcp };
747
+
748
+ // ---------- site-wide checks and data, in this order (data for the report goes on `extra`) ----------
749
+
750
+ // Unnamed controls, WebMCP tools, agent files and writing notes.
751
+ await agentData(site, UA);
752
+
753
+ // A business type guessed from the home page and the schema, and a finding when the schema is too general.
754
+ extra.businessType = home?.html
755
+ ? checkBusinessType(
756
+ htmlPages.map(p => ({
757
+ url: p.finalUrl,
758
+ title: p.title,
759
+ h1: p.headings.find(h => h.level === 1)?.text,
760
+ text: p.bizText,
761
+ types: [...p.types, ...p.schemaOther],
762
+ })),
763
+ add,
764
+ )
765
+ : detectBusinessType([]);
766
+
767
+ pageMarkup(site);
768
+ cookiesAndPolicies(site);
769
+ // Other sites are visited only with --outbound-links, a separate opt-in.
770
+ const OUTBOUND = !!args["outbound-links"];
771
+ const outbound = await outboundLinks(site, OUTBOUND);
772
+
773
+ descStartsWithTitle(site);
774
+
775
+ // hreflang sources that disagree, missing versions, lang against hreflang, untranslated versions, invalid lang values,
776
+ // and the Translate widget as the only translation.
777
+ checkLanguages(
778
+ htmlPages.filter(p => indexable(p) && !p.clientOnly),
779
+ { add, origin: EXPECT_ORIGIN },
780
+ );
781
+
782
+ imageList(site, { images, imageRows });
783
+
784
+ if (RENDER_ALL && !OUTSIDE)
785
+ notes.push(
786
+ "--render all runs only with outside checks on (--outside): rendering runs each page's own scripts, analytics included. It didn't run.",
787
+ );
788
+ if (renderEvery?.note) notes.push(renderEvery.note);
789
+
790
+ // Kept for seo-diff.mjs. A redirect that never ends (a loop, or more than 10 hops) has no target.
791
+ {
792
+ const body = robots ? robotsRes.body : null,
793
+ met = all.filter(p => p.chain?.length > 1).sort((a, b) => (a.url < b.url ? -1 : 1));
794
+ extra.robotsTxt = {
795
+ status: robotsRes.status,
796
+ hash: body == null ? null : createHash("sha256").update(body).digest("hex"),
797
+ text: body?.slice(0, 50 * 1024) ?? null,
798
+ };
799
+ extra.redirects = met
800
+ .slice(0, 500)
801
+ .map(p => ({ from: p.url, to: p.error === "too many redirects" ? null : p.finalUrl, status: p.chain[0].status }));
802
+ if (met.length > 500)
803
+ notes.push(`The crawl met ${met.length} redirects; the first 500 are kept for the next audit's comparison.`);
804
+ }
805
+
806
+ securityHeaders(site);
807
+ for (const r of extra.redirects || []) {
808
+ r.from = hideSecrets(r.from);
809
+ if (r.to) r.to = hideSecrets(r.to);
810
+ }
811
+ // The browser's private-address guard can't run behind a proxy.
812
+ if ((browser || lighthouseBin) && chromeProxyArgs().length)
813
+ notes.push(
814
+ "A proxy is set (HTTPS_PROXY or HTTP_PROXY), so headless Chrome and Lighthouse went through it, and the guard that keeps them off private and cloud-metadata addresses didn't run for renders and Lighthouse. The proxy decides what they can reach.",
815
+ );
816
+
817
+ versionedNote(robots, notes);
818
+ checkCoverage(site, {
819
+ section: SECTION,
820
+ include: INCLUDE,
821
+ exclude: EXCLUDE,
822
+ crawler: { seen, fetched, capped },
823
+ sm,
824
+ gscIndexing: args["gsc-indexing"],
825
+ });
826
+ // Other sites' hreflang targets are visited only with --outside and --hreflang-other-sites: 20 at most, never a private
827
+ // address. A target must name the page back; a 404 or 410 is a bad target, anything else that isn't a page is a note.
828
+ {
829
+ const others = otherSiteTargets(
830
+ htmlPages.filter(p => indexable(p) && !p.clientOnly),
831
+ EXPECT_ORIGIN,
832
+ ),
833
+ yes = !!args["hreflang-other-sites"];
834
+ if (others.size && OUTSIDE && yes) {
835
+ const list = [...others].slice(0, 20),
836
+ away = [];
837
+ for (let i = 0; i < list.length; i += CONC)
838
+ await Promise.all(
839
+ list.slice(i, i + CONC).map(async ([target, from]) => {
840
+ // A page on another site that trips a check is "couldn't check", never the end of the crawl.
841
+ const r = await follow(target),
842
+ there = (() => {
843
+ try {
844
+ return readPage(r, page);
845
+ } catch {
846
+ return null;
847
+ }
848
+ })();
849
+ if (r.status === 404 || r.status === 410)
850
+ for (const f of from) add("hreflang-bad-target", f.url, `${f.lang} → ${target} (status ${r.status})`);
851
+ else if (!there)
852
+ away.push(`${quote(target)} (${r.error || `status ${r.status}`})`); // quoted: the target is site text
853
+ else
854
+ for (const f of from)
855
+ if (!linksBack(there.hreflang, r.finalUrl, f.url, toCrawl))
856
+ add("hreflang-no-return", f.url, `${f.lang} → ${target} doesn't link back`);
857
+ }),
858
+ );
859
+ if (away.length)
860
+ notes.push(
861
+ `${away.length} hreflang target(s) on other sites couldn't be checked for a return link, e.g. ${away[0]}.`,
862
+ );
863
+ if (others.size > 20) notes.push(`hreflang on other sites: the first 20 of ${others.size} targets were checked.`);
864
+ } else if (others.size) {
865
+ if (yes)
866
+ notes.push(
867
+ "--hreflang-other-sites runs only with outside checks on (--outside), since it visits other sites. It didn't run.",
868
+ );
869
+ notChecked.push({
870
+ rule: "META-08",
871
+ area: "META-08 hreflang return links on other sites",
872
+ reason: `${others.size} hreflang target(s) on other sites, e.g. ${others.keys().next().value}, weren't visited to see whether they link back: that contacts other sites, so it needs outside checks on (--outside) and the owner's own yes (--hreflang-other-sites).`,
873
+ });
874
+ }
875
+ }
876
+
877
+ aiBotAccess({ robots, robotsRes, star }, { add, extra, startOrigin: START_ORIGIN });
878
+ bingAiPrefs(site);
879
+ // Comment links, Back traps, paywalls, late head tags, site identity.
880
+ pageSignals(site);
881
+
882
+ aiRobotRules({ robots, robotsRes }, { add, extra, startOrigin: START_ORIGIN });
883
+
884
+ // Also #fragment links.
885
+ linkedOnce(site, { section: SECTION, capped });
886
+
887
+ // Duplicate analytics, secret keys in pages and scripts, hidden links, app files, PDFs.
888
+ await hygieneChecks(site, UA);
889
+
890
+ await markdownCheck(site, { mdHome, renderSample });
891
+
892
+ linkStrength(site, { section: SECTION, capped });
893
+
894
+ // The page-words file for keyword-ideas.mjs.
895
+ pageWords(site, { out: OUT, stamp: t0 });
896
+
897
+ // Click-only elements and missing landmarks.
898
+ landmarks(site);
899
+ // ---------- the bot probes, the last requests to the site: a firewall may ban the address that sent them ----------
900
+ // The home page and up to 9 sample pages as Googlebot, then a few as AI search crawlers with --ai-bot-probe. Every
901
+ // other request to the site, schema images and browser loads included, has already gone.
902
+ const botSample = sampleUrls(htmlPages.map(p => p.url));
903
+ const botCompared = await compareGooglebot(site, { page, botSample });
904
+ await aiBotProbe(site, { page, botSample, aiProbe: AI_PROBE, outside: OUTSIDE });
905
+ // After every request this crawl makes: what the private-address guard stopped, and whether the crawler slowed down.
906
+ if (blocked.size)
907
+ notes.push(
908
+ `The crawler didn't fetch ${blocked.size} address(es) outside the crawled site that are private, local or cloud-metadata addresses: ${[
909
+ ...blocked,
910
+ ]
911
+ .slice(0, 3)
912
+ .map(([u, why]) => `${quote(u)} (${why})`)
913
+ .join("; ")}. A redirect there is reported as the redirect itself.`,
914
+ );
915
+ const slowed = slowNote(slow);
916
+ if (slowed) notes.push(slowed);
917
+
918
+ // Also schema placeholders and deprecated types.
919
+ await schemaImages(site);
920
+
921
+ shopChecks(site);
922
+
923
+ mediaData(site, { speed, lighthouse, imageInfo });
924
+ // Only once the phone trend came back: a site without it has no tablet or page data either. A 404 is no news.
925
+ if (SPEED_ON && CRUX_KEY && speed?.trend) {
926
+ const [tab, homeT] = /** @type {TrendResult[]} */ ([
927
+ await speedTrend(EXPECT_ORIGIN, { key: CRUX_KEY, endpoint: CRUX_AT, formFactor: "TABLET" }).catch(e => ({
928
+ note: `CrUX history (tablet) failed (${e.message}).`,
929
+ })),
930
+ await speedTrend(EXPECT_ORIGIN + "/", { key: CRUX_KEY, endpoint: CRUX_AT, page: true }).catch(e => ({
931
+ note: `CrUX history for the home page failed (${e.message}).`,
932
+ })),
933
+ ]);
934
+ for (const t of [tab, homeT]) if (t.note && !/not enough Chrome visits/.test(t.note)) notes.push(t.note);
935
+ if (tab.trend) speed.tablet = { trend: tab.trend, ...(tab.lcpBreakdown ? { lcpBreakdown: tab.lcpBreakdown } : {}) };
936
+ if (homeT.trend) speed.pageTrend = { url: EXPECT_ORIGIN + "/", trend: homeT.trend };
937
+ }
938
+
939
+ // REND-11 data from the browser loads above, and --render-page's result.
940
+ if (RENDER_PAGE && !OUTSIDE)
941
+ notes.push(
942
+ "--render-page runs only with outside checks on (--outside): rendering runs the page's own scripts, analytics included. It didn't run.",
943
+ );
944
+ let moreReason = OUTSIDE
945
+ ? "Chrome or Edge isn't installed (or set CHROME_PATH), so the phone menu and ads couldn't be checked."
946
+ : "Outside checks are off. With the owner's go-ahead, --outside loads sample pages in headless Chrome at phone size (running the site's own scripts) to try the menu button and measure ads.";
947
+ if (more) {
948
+ notes.push(...more.notes);
949
+ if (more.pages.length) extra.renderSample = more.pages;
950
+ if (more.chosen) extra.renderedPage = more.chosen;
951
+ if (more.checked) {
952
+ evalRules("REND-11");
953
+ moreReason = null;
954
+ } else
955
+ moreReason = `The browser at ${browser} couldn't load the sample pages at phone size (${more.notes[0] || "no pages to load"}).`;
956
+ }
957
+ if (moreReason) notChecked.push({ rule: "REND-11", area: `REND-11 ${RULES["REND-11"][0]}`, reason: moreReason });
958
+
959
+ // Descriptions against their pages, templated descriptions, stale guides, keyword use.
960
+ contentChecks(site, { titleWords, brandWords, acronyms });
961
+
962
+ localData(site, localBusiness);
963
+
964
+ otherSites(site, outbound);
965
+
966
+ // E-E-A-T signals for the trust view, never findings or scored; last, so the security findings are in. HTTPS counts
967
+ // with no open TRUST-01 or TRUST-07 finding, and is unknown without a public origin. Locally a missing security header
968
+ // is often one a CDN adds in production, so it doesn't count against HTTPS; a header sent but wrong still does.
969
+ const localHeaders = isLocal(START_ORIGIN) && findings.has("sec-headers");
970
+ extra.trustSignals = trustSignals(htmlPages, {
971
+ origin: EXPECT_ORIGIN,
972
+ localHeaders,
973
+ https: !isPublic(EXPECT_ORIGIN)
974
+ ? null
975
+ : EXPECT_ORIGIN.startsWith("https:") &&
976
+ ![...findings.keys()].some(
977
+ k => !(localHeaders && k === "sec-headers") && ["TRUST-01", "TRUST-07"].includes(CHECKS[k][0]),
978
+ ),
979
+ orgSchema: (home?.html && home.trust.org) || htmlPages.find(p => p.trust.org)?.trust.org || null,
980
+ unsourcedStats: htmlPages.filter(p => p.trust.unsourcedStat).length,
981
+ });
982
+
983
+ // ---------- what the crawler cannot check ----------
984
+ // CRAWL-09 never passes here: a real Googlebot comes from Google's IP addresses, which no request from here can.
985
+ const NOT_CRAWLABLE = [
986
+ ...(["googlebot-blocked", "googlebot-differs", "googlebot-firewall"].some(k => findings.has(k))
987
+ ? []
988
+ : [
989
+ [
990
+ "CRAWL-09",
991
+ "Bot protection and firewall",
992
+ botCompared
993
+ ? `A Googlebot user agent got the same status, robots tag, canonical, title and text as a visitor on ${botCompared} page(s)${isLocal(START_ORIGIN) ? " of the local build, where no CDN or firewall sits in between; crawl the live site to include them" : ""}. A real Googlebot comes from Google's IP addresses, which a firewall can treat differently; confirm with the live test in Search Console's URL Inspection.`
994
+ : "A local crawl can't see CDN or WAF behaviour toward Googlebot; check the CDN settings and URL Inspection after launch.",
995
+ ],
996
+ ]),
997
+ [
998
+ "CRAWL-11",
999
+ "Drafts and publish flags",
1000
+ "The crawler can't see publish flags; check the content layer (scripts/content-scan.mjs).",
1001
+ ],
1002
+ ["SCHEMA-08", "Rich result eligibility", "Run one URL per template through Google's Rich Results Test."],
1003
+ ["META-07", "Search Console and Bing verification", "Check DNS or ask the owner."],
1004
+ ["LINK-03", "Circular linking design", "Needs a read of the related-content code and data."],
1005
+ ["CONTENT-03", "Keyword targeting and cannibalization", "Needs the content plan or Search Console query data."],
1006
+ [
1007
+ "CONTENT-11",
1008
+ "Spam policies (scaled content, doorways, site reputation, back-button hijacking)",
1009
+ 'Needs a read of content strategy and scripts. The crawler covers parts of it: near-duplicate pages, links in comment sections without rel="ugc" or "nofollow", and inline scripts that may trap the Back button; scripts loaded from files aren\'t read.',
1010
+ ],
1011
+ [
1012
+ "AI-02",
1013
+ "AI crawler access through the CDN/WAF",
1014
+ "robots.txt is checked; firewall behaviour toward OAI-SearchBot, Claude-SearchBot and PerplexityBot isn't visible locally.",
1015
+ ],
1016
+ ];
1017
+ for (const [rule, area, reason] of NOT_CRAWLABLE) skip(rule, reason, `${rule} ${area}`);
1018
+ // MAP-01 is half the robots.txt Sitemap: line, so only a sitemap finding settles it while robots.txt is down.
1019
+ if (robotsDown)
1020
+ for (const rule of ["MAP-01", "MAP-05", "MAP-06"])
1021
+ if (![...findings.keys()].some(k => CHECKS[k][0] === rule))
1022
+ skip(
1023
+ rule,
1024
+ `robots.txt answered ${robotsRes.status ? `status ${robotsRes.status}` : "nothing"}, so its ${rule === "MAP-01" ? "Sitemap: line" : "rules"} couldn't be read. Re-run once it returns 200.`,
1025
+ );
1026
+ // A page missing from the sitemap URLs read may be in the part past SITEMAP_KEEP.
1027
+ if (sm.cut && findings.delete("missing-from-sitemap") && evaluated.delete("MAP-03"))
1028
+ skip(
1029
+ "MAP-03",
1030
+ sm.filesLeft
1031
+ ? "Some crawled pages aren't in the first 60 sitemap files, the most this audit reads, so they may still be in the files after them."
1032
+ : `Some crawled pages aren't among the first ${SITEMAP_KEEP.toLocaleString("en-US")} sitemap URLs, the most this audit reads, so they may still be in the rest of the sitemap.`,
1033
+ );
1034
+ if (!redirectSources.length)
1035
+ skip(
1036
+ "URL-07",
1037
+ "No redirect list given. Pass --urls (old site URLs) or --next-manifest .next/routes-manifest.json.",
1038
+ "URL-07 Old-URL redirects",
1039
+ );
1040
+ if (!BANNED && !VERIFY)
1041
+ skip(
1042
+ "CONTENT-10",
1043
+ "Pass --banned and --verify with the profile's claim lists.",
1044
+ "CONTENT-10 Banned and unconfirmed claims",
1045
+ );
1046
+ if (IGNORE_NOINDEX && evaluated.delete("CRAWL-02"))
1047
+ skip(
1048
+ "CRAWL-02",
1049
+ "Pre-launch run: noindex is expected now. Re-check after launch (CRAWL-03).",
1050
+ "CRAWL-02 Pages meant to rank are not noindex",
1051
+ );
1052
+
1053
+ // ---------- output ----------
1054
+ const out = list({ source: "crawler", prefix: "C" });
1055
+ const failedRules = new Set(out.map(f => f.rule));
1056
+ const passed = [...evaluated]
1057
+ .filter(r => !failedRules.has(r))
1058
+ .sort()
1059
+ .map(r => ({ rule: r, title: RULES[r][0], category: RULES[r][1] }));
1060
+ // Every note and every notChecked reason, whichever check wrote it and whenever, through one scrub.
1061
+ const scrubText = s => redact(maskKeys(String(s)));
1062
+ const noteList = notes.map(scrubText);
1063
+ const report = {
1064
+ tool: "seo-supervisor-crawler",
1065
+ version: VERSION,
1066
+ crawledAt: new Date().toISOString(),
1067
+ durationMs: Date.now() - t0,
1068
+ startUrl: START.href,
1069
+ siteOrigin: EXPECT_ORIGIN,
1070
+ options: {
1071
+ max: MAX,
1072
+ concurrency: CONC,
1073
+ ignoreNoindex: IGNORE_NOINDEX,
1074
+ banned: BANNED ? String(BANNED) : null,
1075
+ verify: VERIFY ? String(VERIFY) : null,
1076
+ redirectSources: redirectSources.length,
1077
+ trailingSlash: SLASH,
1078
+ detectedSlashStyle: style,
1079
+ includeQuery: INCLUDE_QUERY,
1080
+ brand: BRAND || null,
1081
+ },
1082
+ // capped: stopped at --max. sitemapComplete: every sitemap file answered 200 and none went unread past a limit.
1083
+ // seo-diff.mjs compares internal links and sitemap listing only when they say the crawl and the sitemap were whole.
1084
+ stats: {
1085
+ fetched,
1086
+ capped,
1087
+ htmlPages: htmlPages.length,
1088
+ sitemapUrls: sm.entries.length,
1089
+ sitemapFiles: sm.files,
1090
+ sitemapComplete: !sm.cut && sm.files.every(f => f.status === 200),
1091
+ robotsTxt: robotsRes.status,
1092
+ },
1093
+ notes: noteList,
1094
+ findings: out,
1095
+ passed,
1096
+ notChecked: notChecked.map(n => ({ ...n, reason: scrubText(n.reason) })),
1097
+ ...extra,
1098
+ ...(speed ? { speed } : {}),
1099
+ ...(labSpeed ? { labSpeed } : {}),
1100
+ ...(lighthouse ? { lighthouse } : {}),
1101
+ errors: all.filter(p => !p.html && (p.status >= 400 || p.status === 0)).map(p => ({ url: p.url, status: p.status })),
1102
+ pages: htmlPages.map(p => ({
1103
+ url: p.finalUrl,
1104
+ status: p.status,
1105
+ depth: p.depth ?? null,
1106
+ inSitemap: smSet.has(p.url),
1107
+ noindex: p.noindex,
1108
+ canonical: canonicalFor(p),
1109
+ title: p.title,
1110
+ description: p.description,
1111
+ ogTitle: p.ogTitle,
1112
+ ogImage: p.ogImage,
1113
+ h1Text: p.headings.find(h => h.level === 1)?.text ?? null,
1114
+ words: p.words,
1115
+ h1: p.h1Count,
1116
+ schema: p.types,
1117
+ schemaOther: p.schemaOther,
1118
+ schemaProps: p.schemaProps,
1119
+ linksOut: p.links.length,
1120
+ linksIn: inbound.get(p.finalUrl) || 0,
1121
+ h2s: p.headings
1122
+ .filter(h => h.level === 2)
1123
+ .map(h => h.text)
1124
+ .slice(0, 50),
1125
+ h3s: p.headings
1126
+ .filter(h => h.level === 3)
1127
+ .map(h => h.text)
1128
+ .slice(0, 50),
1129
+ ogDescription: p.ogDescription,
1130
+ ogUrl: p.ogUrl,
1131
+ hreflang: (p.hreflang || []).map(h => ({ lang: h.lang, href: h.href })),
1132
+ })),
1133
+ };
1134
+ mkdirSync(dirname(OUT), { recursive: true });
1135
+ // File the previous seo-crawl.json in history/ before replacing it, so "Since last audit" still has it. Other --out
1136
+ // names (a branch crawl, say) stay out of the history.
1137
+ if (basename(OUT) === "seo-crawl.json" && existsSync(OUT))
1138
+ try {
1139
+ fileCrawl(join(dirname(OUT), "history"), OUT, JSON.parse(readFileSync(OUT, "utf8")));
1140
+ } catch (e) {
1141
+ console.log(`note: the previous ${OUT} couldn't be filed in history/ (${e.message})`);
1142
+ }
1143
+ writeFileSync(OUT, JSON.stringify(report, null, 2));
1144
+ const counts = out.reduce((m, f) => ((m[f.severity] = (m[f.severity] || 0) + 1), m), {});
1145
+ console.log(
1146
+ `seo-crawl: ${htmlPages.length} HTML pages (${fetched} fetched), ${sm.entries.length} sitemap URLs, ${out.length} findings ` +
1147
+ JSON.stringify(counts) +
1148
+ `, ${passed.length} rules passed`,
1149
+ );
1150
+ for (const n of noteList) console.log("note: " + n);
1151
+ console.log("wrote " + OUT);