seo-supervisor 1.2.0 → 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.
- package/.claude-plugin/icon.png +0 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +16 -3
- package/CHANGELOG.md +430 -0
- package/NOTICE +7 -0
- package/README.md +230 -25
- package/agents/seo-auditor.md +16 -0
- package/agents/seo-reviewer.md +16 -0
- package/bin/agents.mjs +194 -29
- package/bin/extras.mjs +422 -0
- package/bin/prompt.mjs +34 -14
- package/bin/seo-supervisor.mjs +386 -53
- package/commands/seo-audit.md +29 -3
- package/commands/seo-brief.md +28 -0
- package/commands/seo-connect.md +27 -0
- package/commands/seo-fix.md +24 -3
- package/commands/seo-grow.md +26 -0
- package/commands/seo-launch.md +17 -3
- package/commands/seo-review.md +13 -1
- package/commands/seo-rewrite.md +25 -0
- package/commands/seo-setup.md +17 -1
- package/commands/seo-watch.md +28 -0
- package/hooks/hooks.json +117 -0
- package/package.json +20 -7
- package/skills/seo-supervisor/NOTICE +7 -0
- package/skills/seo-supervisor/SKILL.md +302 -21
- package/skills/seo-supervisor/audience.md +61 -0
- package/skills/seo-supervisor/examples/drafts/security.md +41 -0
- package/skills/seo-supervisor/examples/hooks/README.md +28 -0
- package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
- package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
- package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
- package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
- package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
- package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
- package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
- package/skills/seo-supervisor/examples/sample-audit.json +94 -2
- package/skills/seo-supervisor/examples/sample-report.html +111 -61
- package/skills/seo-supervisor/examples/sample-report.md +147 -44
- package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
- package/skills/seo-supervisor/examples/snippets.md +648 -1
- package/skills/seo-supervisor/grow.md +342 -0
- package/skills/seo-supervisor/og-images.md +85 -0
- package/skills/seo-supervisor/page-types.md +124 -0
- package/skills/seo-supervisor/planning.md +19 -7
- package/skills/seo-supervisor/profile-template.md +41 -0
- package/skills/seo-supervisor/report-format.md +177 -10
- package/skills/seo-supervisor/rewrite.md +59 -0
- package/skills/seo-supervisor/rules/ai-search.md +65 -12
- package/skills/seo-supervisor/rules/content.md +33 -9
- package/skills/seo-supervisor/rules/crawl-index.md +33 -6
- package/skills/seo-supervisor/rules/internal-linking.md +49 -6
- package/skills/seo-supervisor/rules/launch-monitoring.md +17 -8
- package/skills/seo-supervisor/rules/media.md +13 -1
- package/skills/seo-supervisor/rules/metadata.md +41 -9
- package/skills/seo-supervisor/rules/performance.md +50 -5
- package/skills/seo-supervisor/rules/rendering.md +39 -2
- package/skills/seo-supervisor/rules/search-intent.md +32 -0
- package/skills/seo-supervisor/rules/sitemaps-robots.md +24 -12
- package/skills/seo-supervisor/rules/structured-data.md +37 -14
- package/skills/seo-supervisor/rules/trust-security.md +25 -2
- package/skills/seo-supervisor/rules/urls.md +10 -2
- package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
- package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
- package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
- package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
- package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
- package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
- package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
- package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
- package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
- package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
- package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
- package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
- package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
- package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
- package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
- package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
- package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
- package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
- package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
- package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
- package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
- package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
- package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
- package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
- package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
- package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
- package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
- package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
- package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
- package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
- package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
- package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
- package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
- package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
- package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
- package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
- package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
- package/skills/seo-supervisor/scripts/content-scan.mjs +515 -158
- package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
- package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
- package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
- package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
- package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
- package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
- package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
- package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
- package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
- package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
- package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
- package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
- package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
- package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
- package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
- package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
- package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
- package/skills/seo-supervisor/scripts/google.mjs +1341 -0
- package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
- package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
- package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
- package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
- package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
- package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
- package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
- package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
- package/skills/seo-supervisor/scripts/guard.mjs +74 -0
- package/skills/seo-supervisor/scripts/images.mjs +408 -0
- package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
- package/skills/seo-supervisor/scripts/issues.mjs +217 -0
- package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
- package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
- package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
- package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
- package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
- package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
- package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
- package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
- package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
- package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
- package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
- package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
- package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
- package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
- package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
- package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
- package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
- package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
- package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
- package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
- package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
- package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
- package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
- package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
- package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
- package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
- package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
- package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
- package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
- package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
- package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
- package/skills/seo-supervisor/scripts/osm.mjs +359 -0
- package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
- package/skills/seo-supervisor/scripts/render-report.mjs +324 -690
- package/skills/seo-supervisor/scripts/report/client.js +37 -0
- package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
- package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
- package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
- package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
- package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
- package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
- package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
- package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
- package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
- package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
- package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
- package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
- package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
- package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
- package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
- package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
- package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
- package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
- package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
- package/skills/seo-supervisor/scripts/report/styles.css +223 -0
- package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
- package/skills/seo-supervisor/scripts/report-plan.mjs +112 -33
- package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
- package/skills/seo-supervisor/scripts/seo-crawl.mjs +1086 -638
- package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
- package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
- package/skills/seo-supervisor/site-types/content.md +34 -1
- package/skills/seo-supervisor/site-types/ecommerce.md +38 -1
- package/skills/seo-supervisor/site-types/local-business.md +96 -6
- package/skills/seo-supervisor/site-types/services.md +46 -0
- package/skills/seo-supervisor/site-types/tools.md +3 -3
- package/skills/seo-supervisor/strategy.md +232 -0
- package/skills/seo-supervisor/troubleshooting.md +56 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Image, favicon, stylesheet and schema image checks, and the image and media data for the report.
|
|
3
|
+
// Files are read with firstBytes, which never leaves the crawled site.
|
|
4
|
+
import { RULES } from "../crawl/catalog.mjs";
|
|
5
|
+
import { clean, urlOr } from "../crawl/fetch.mjs";
|
|
6
|
+
import { isBusinessType } from "../lib/business.mjs";
|
|
7
|
+
import { pool } from "../crawl/queue.mjs";
|
|
8
|
+
import { quote } from "../lib/findings.mjs";
|
|
9
|
+
import { imageSize, imageMeta } from "../lib/image-size.mjs";
|
|
10
|
+
import { altProblem, cdnOf, uncached } from "./media.mjs";
|
|
11
|
+
import { medianScores } from "./lighthouse.mjs";
|
|
12
|
+
import { estSaving } from "../images.mjs";
|
|
13
|
+
import { SUPERSEDED } from "./schema.mjs";
|
|
14
|
+
|
|
15
|
+
// Still 429 or 503 after firstBytes' retry means rate-limited, not broken, so the broken-file checks skip it.
|
|
16
|
+
const busy = r => r?.status === 429 || r?.status === 503;
|
|
17
|
+
// images and shareImages come from checkPages in site-pages.mjs.
|
|
18
|
+
export async function checkAssets(site, { images, shareImages }) {
|
|
19
|
+
const {
|
|
20
|
+
htmlPages,
|
|
21
|
+
add,
|
|
22
|
+
evalRules,
|
|
23
|
+
notes,
|
|
24
|
+
notChecked,
|
|
25
|
+
startOrigin: START_ORIGIN,
|
|
26
|
+
conc: CONC,
|
|
27
|
+
firstBytes,
|
|
28
|
+
toCrawl,
|
|
29
|
+
indexable,
|
|
30
|
+
isHome,
|
|
31
|
+
} = site;
|
|
32
|
+
// Home page checks run only on the real home page, never on a deep start URL. A crawl started at / judges where /
|
|
33
|
+
// lands, even after a redirect to /en/.
|
|
34
|
+
const home = site.home?.html && (isHome(site.home) || site.start.pathname === "/") ? site.home : null;
|
|
35
|
+
// Only on-site images are read, so no third party is contacted, even through a page that redirected off the site.
|
|
36
|
+
const onSiteImages = [...images].filter(([src]) => new URL(src).origin === START_ORIGIN),
|
|
37
|
+
imageList = onSiteImages.slice(0, 50);
|
|
38
|
+
const shareList = [...shareImages].slice(0, 20);
|
|
39
|
+
const productImgs = new Map(); // crawl URL -> { src, page }
|
|
40
|
+
for (const p of htmlPages)
|
|
41
|
+
if (indexable(p))
|
|
42
|
+
for (const s of p.productImages || []) {
|
|
43
|
+
const src = urlOr(s, p.finalUrl),
|
|
44
|
+
c = src && clean(toCrawl(src.href));
|
|
45
|
+
if (c && new URL(c).origin === START_ORIGIN && !productImgs.has(c))
|
|
46
|
+
productImgs.set(c, { src: src.href, page: p.finalUrl });
|
|
47
|
+
}
|
|
48
|
+
const productList = [...productImgs].slice(0, 20);
|
|
49
|
+
const onSite = c => !!c && new URL(c).origin === START_ORIGIN;
|
|
50
|
+
const declared = home?.html ? [...new Set(home.icons.map(h => urlOr(h, home.base)?.href).filter(Boolean))] : [];
|
|
51
|
+
const icons = home?.html
|
|
52
|
+
? [...new Set([...declared.map(d => clean(toCrawl(d))).filter(onSite), START_ORIGIN + "/favicon.ico"])].slice(0, 5)
|
|
53
|
+
: [];
|
|
54
|
+
// Stylesheets only: site-hygiene.mjs reads scripts whole for secret keys and reports their errors the same way.
|
|
55
|
+
const cssUse = new Map();
|
|
56
|
+
for (const p of htmlPages)
|
|
57
|
+
if (indexable(p)) for (const s of p.stylesheets || []) if (!cssUse.has(s)) cssUse.set(s, p.finalUrl);
|
|
58
|
+
const ownCss = [...cssUse].slice(0, 50);
|
|
59
|
+
// One pool fetches every file below, schema images included. firstBytes keeps each answer, so the loops below
|
|
60
|
+
// make no new requests and a file several checks use is fetched once.
|
|
61
|
+
const files = [
|
|
62
|
+
...new Set([
|
|
63
|
+
...imageList.map(([s]) => s),
|
|
64
|
+
...shareList.map(([c]) => c),
|
|
65
|
+
...productList.map(([c]) => c),
|
|
66
|
+
...icons,
|
|
67
|
+
...ownCss.map(([s]) => s),
|
|
68
|
+
...schemaImageUrls(site).list.map(([c]) => c),
|
|
69
|
+
]),
|
|
70
|
+
];
|
|
71
|
+
const answers = await pool(files, CONC, u => firstBytes(u)),
|
|
72
|
+
busyFiles = files.filter((u, i) => busy(answers[i]));
|
|
73
|
+
if (busyFiles.length)
|
|
74
|
+
notes.push(
|
|
75
|
+
`${busyFiles.length} file(s) on the site (images, stylesheets or icons) still answered 429 or 503 (too many requests, or server busy) after the crawler paused and asked again, e.g. ${quote(busyFiles[0])}, so whether they load wasn't checked.`,
|
|
76
|
+
);
|
|
77
|
+
// A file that redirects off the site isn't followed or judged. Sources: own-file-broken in crawl/catalog.mjs.
|
|
78
|
+
for (const [kind, list] of [
|
|
79
|
+
["image", imageList],
|
|
80
|
+
["stylesheet", ownCss],
|
|
81
|
+
])
|
|
82
|
+
for (const [src, page] of list) {
|
|
83
|
+
const r = await firstBytes(src);
|
|
84
|
+
if (r && r.status >= 400 && !busy(r)) add("own-file-broken", page, `${kind} ${src} → ${r.status}`);
|
|
85
|
+
}
|
|
86
|
+
const imageRows = [];
|
|
87
|
+
const imageInfo = new Map(); // caching, CDN and creator data per weighed image
|
|
88
|
+
let weighed = 0; // PERF-08 counts as checked only when at least one image could be weighed
|
|
89
|
+
for (const [src, page] of imageList) {
|
|
90
|
+
const r = await firstBytes(src);
|
|
91
|
+
if (!r || r.status < 200 || r.status > 299 || !r.size) continue;
|
|
92
|
+
weighed++;
|
|
93
|
+
const { size } = r,
|
|
94
|
+
type = r.type.split(";")[0].trim().toLowerCase(),
|
|
95
|
+
px = imageSize(r.bytes),
|
|
96
|
+
kb = Math.round(size / 1024);
|
|
97
|
+
imageInfo.set(src, { uncached: uncached(r.headers), cdn: cdnOf(r.headers), ...imageMeta(r.bytes) });
|
|
98
|
+
// 500 KB is a local threshold, not Google's; that finding replaces heavy-image rather than adding to it.
|
|
99
|
+
if (size > 500 * 1024) add("image-over-500kb", page, `${src} · ${kb} KB`);
|
|
100
|
+
else if (size > 200 * 1024) add("heavy-image", page, `${src} · ${kb} KB`);
|
|
101
|
+
if (/^image\/(jpeg|png)$/.test(type) && size > 100 * 1024)
|
|
102
|
+
add("legacy-image-format", page, `${src} · ${type} · ${kb} KB`);
|
|
103
|
+
imageRows.push({
|
|
104
|
+
url: src,
|
|
105
|
+
bytes: size,
|
|
106
|
+
width: px?.width ?? null,
|
|
107
|
+
height: px?.height ?? null,
|
|
108
|
+
format: px?.type || type.match(/^image\/([a-z0-9.-]+)/)?.[1] || null,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (weighed) evalRules("PERF-08");
|
|
112
|
+
if (onSiteImages.length > 50)
|
|
113
|
+
notes.push(`Image weight was checked for the first 50 of ${onSiteImages.length} images.`);
|
|
114
|
+
// The first 64 KB that firstBytes reads is enough for the pixel size.
|
|
115
|
+
let shareRead = 0,
|
|
116
|
+
shareAway = 0;
|
|
117
|
+
for (const [crawlSrc, { src, page }] of shareList) {
|
|
118
|
+
const r = await firstBytes(crawlSrc);
|
|
119
|
+
if (!r) {
|
|
120
|
+
shareAway++;
|
|
121
|
+
continue;
|
|
122
|
+
} // redirects off the crawled site, so not fetched
|
|
123
|
+
if (busy(r)) continue;
|
|
124
|
+
if (r.status !== 200 && r.status !== 206) {
|
|
125
|
+
add("og-image-broken", page, `${src} → ${r.status || `no response (${r.error})`}`);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const size = imageSize(r.bytes);
|
|
129
|
+
if (!size) {
|
|
130
|
+
if (/html/.test(r.type)) add("og-image-broken", page, `${src} → an HTML page, not an image`);
|
|
131
|
+
continue;
|
|
132
|
+
} // SVG, AVIF: size unknown
|
|
133
|
+
shareRead++;
|
|
134
|
+
if (size.width < 1200) add("og-image-small", page, `${src} · ${size.width}×${size.height} px`);
|
|
135
|
+
}
|
|
136
|
+
if (shareAway)
|
|
137
|
+
notes.push(
|
|
138
|
+
`${shareAway} share image(s) (og:image) redirect away from the crawled site (often to the public origin), so they couldn't be read and their size wasn't checked.`,
|
|
139
|
+
);
|
|
140
|
+
if (shareImages.size && !shareRead)
|
|
141
|
+
notes.push("No share image (og:image) could be read, so share image sizes weren't checked.");
|
|
142
|
+
if (shareImages.size > 20)
|
|
143
|
+
notes.push(`Share image size was checked for the first 20 of ${shareImages.size} og:images.`);
|
|
144
|
+
let productRead = 0;
|
|
145
|
+
for (const [crawlSrc, { src, page }] of productList) {
|
|
146
|
+
const r = await firstBytes(crawlSrc),
|
|
147
|
+
size = r && (r.status === 200 || r.status === 206) ? imageSize(r.bytes) : null;
|
|
148
|
+
if (!size) continue; // off the site, broken, SVG or AVIF: not measured
|
|
149
|
+
productRead++;
|
|
150
|
+
// Google recommends at least 50,000 pixels (width × height) for merchant listing images.
|
|
151
|
+
// https://developers.google.com/search/docs/appearance/structured-data/merchant-listing
|
|
152
|
+
const px = size.width * size.height;
|
|
153
|
+
if (px < 50000)
|
|
154
|
+
add("product-image-small", page, `${src} · ${size.width}×${size.height} px (${px.toLocaleString("en")} pixels)`);
|
|
155
|
+
}
|
|
156
|
+
if (htmlPages.some(p => indexable(p) && p.productImages?.length) && !productRead)
|
|
157
|
+
notes.push(
|
|
158
|
+
"No Product schema image on the crawled site could be read (they're on another host, missing, or SVG or AVIF), so product image sizes weren't checked.",
|
|
159
|
+
);
|
|
160
|
+
if (productImgs.size > 20)
|
|
161
|
+
notes.push(`Product image size was checked for the first 20 of ${productImgs.size} Product schema images.`);
|
|
162
|
+
if (home && home.html) {
|
|
163
|
+
if (![...home.types, ...home.schemaOther].some(isBusinessType)) add("org-missing", home.finalUrl);
|
|
164
|
+
if (![...home.types, ...home.schemaOther].includes("WebSite")) add("website-missing", home.finalUrl);
|
|
165
|
+
}
|
|
166
|
+
// Google wants a square favicon of 48 px or more in BMP, GIF, ICO, PNG, JPEG, PPM or TIFF. A type whose size can't
|
|
167
|
+
// be read (BMP, TIFF) passes. https://developers.google.com/search/docs/appearance/favicon-in-search
|
|
168
|
+
if (home && home.html) {
|
|
169
|
+
const away = declared.some(d => !onSite(clean(toCrawl(d))));
|
|
170
|
+
const tried = await Promise.all(icons.map(async c => ({ path: new URL(c).pathname, r: await firstBytes(c) })));
|
|
171
|
+
const loaded = tried.filter(
|
|
172
|
+
t => t.r && (t.r.status === 200 || t.r.status === 206) && t.r.bytes.length && !/html/i.test(t.r.type),
|
|
173
|
+
);
|
|
174
|
+
const svg = t => /svg/i.test(t.r.type) || /^\s*(<\?xml|<svg)/i.test(t.r.bytes.toString("latin1", 0, 100)),
|
|
175
|
+
size = t => imageSize(t.r.bytes);
|
|
176
|
+
const good = t => {
|
|
177
|
+
const s = size(t);
|
|
178
|
+
return s ? s.type !== "webp" && s.width === s.height && s.width >= 48 : !svg(t) && /^image\//i.test(t.r.type);
|
|
179
|
+
};
|
|
180
|
+
const say = t => {
|
|
181
|
+
const s = size(t);
|
|
182
|
+
return `${t.path}: ${s ? `${s.width}×${s.height} px${s.type === "webp" ? ", WebP" : ""}` : svg(t) ? "SVG" : t.r.type || "unknown type"}`;
|
|
183
|
+
};
|
|
184
|
+
const status = t => (t.r.status === 200 ? "an HTML page" : t.r.status || `no response (${t.r.error})`);
|
|
185
|
+
// An icon that redirects off the site (to a CDN or the public origin) isn't followed, so it can't be judged.
|
|
186
|
+
const movedAway = tried.find(t => !t.r);
|
|
187
|
+
if (loaded.some(good)) evalRules("META-10");
|
|
188
|
+
else if (away || movedAway)
|
|
189
|
+
notChecked.push({
|
|
190
|
+
rule: "META-10",
|
|
191
|
+
area: `META-10 ${RULES["META-10"][0]}`,
|
|
192
|
+
reason: away
|
|
193
|
+
? "The home page's icon is on another host (often a CDN), and only the crawled site is fetched."
|
|
194
|
+
: `${movedAway.path} redirects away from the crawled site (often to a CDN), and only the crawled site is fetched.`,
|
|
195
|
+
});
|
|
196
|
+
else {
|
|
197
|
+
evalRules("META-10");
|
|
198
|
+
if (loaded.length) add("favicon-unsuitable", home.finalUrl, loaded.map(say).join("; "));
|
|
199
|
+
else
|
|
200
|
+
add(
|
|
201
|
+
"favicon-missing",
|
|
202
|
+
home.finalUrl,
|
|
203
|
+
(declared.length ? "" : "no icon link on the home page, and ") +
|
|
204
|
+
tried.map(t => `${t.path} → ${status(t)}`).join("; "),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// One site-wide suggestion, only when there's a next page to load. A single-page app's server HTML shows neither
|
|
209
|
+
// its links nor the router that loads them, so it can't be judged.
|
|
210
|
+
if (htmlPages.length > 1) {
|
|
211
|
+
if (htmlPages.some(p => p.preloads)) evalRules("PERF-09");
|
|
212
|
+
else if (htmlPages.filter(p => p.clientOnly).length > htmlPages.length / 2)
|
|
213
|
+
notChecked.push({
|
|
214
|
+
rule: "PERF-09",
|
|
215
|
+
area: `PERF-09 ${RULES["PERF-09"][0]}`,
|
|
216
|
+
reason:
|
|
217
|
+
"Most pages are built in the browser (a single-page app), so the server HTML shows neither their links nor the router that loads them. A single-page app's router usually loads the next page itself.",
|
|
218
|
+
});
|
|
219
|
+
else {
|
|
220
|
+
evalRules("PERF-09");
|
|
221
|
+
add("no-speculation-rules", (home?.html ? home : htmlPages[0]).finalUrl, `none of ${htmlPages.length} pages`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return { imageRows, imageInfo };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Builds extra.images from the rows checkAssets weighed, so it makes no requests. images comes from checkPages.
|
|
228
|
+
export function imageList(site, { images, imageRows }) {
|
|
229
|
+
const { htmlPages, extra, indexable } = site;
|
|
230
|
+
const usedOn = new Map(); // image URL -> pages using it, keyed as in `images`
|
|
231
|
+
for (const p of htmlPages)
|
|
232
|
+
if (!p.clientOnly && indexable(p))
|
|
233
|
+
for (const i of p.imgs) {
|
|
234
|
+
const s = urlOr(i.src, p.base)?.href;
|
|
235
|
+
if (s && images.has(s)) (usedOn.get(s) || usedOn.set(s, []).get(s)).push(p.finalUrl);
|
|
236
|
+
}
|
|
237
|
+
extra.images = imageRows
|
|
238
|
+
.sort((a, b) => b.bytes - a.bytes)
|
|
239
|
+
.slice(0, 100)
|
|
240
|
+
.map(x => ({ ...x, pages: [...new Set(usedOn.get(x.url))].slice(0, 10), estSaving: estSaving(x) }));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Up to 50 on-site schema images as [crawl URL, { src, page }], and the off-site ones. checkAssets fetches them early.
|
|
244
|
+
function schemaImageUrls({ htmlPages, startOrigin: START_ORIGIN, toCrawl, indexable }) {
|
|
245
|
+
const schemaImgs = new Map(),
|
|
246
|
+
away = new Set(); // crawl URL -> { src, page }; images on other hosts
|
|
247
|
+
for (const p of htmlPages) {
|
|
248
|
+
if (p.clientOnly || !indexable(p)) continue;
|
|
249
|
+
for (const s of p.schemaImages) {
|
|
250
|
+
const src = urlOr(s, p.base);
|
|
251
|
+
if (!src || !/^https?:$/.test(src.protocol)) continue;
|
|
252
|
+
const c = clean(toCrawl(src.href));
|
|
253
|
+
if (new URL(c).origin !== START_ORIGIN) away.add(src.href);
|
|
254
|
+
else if (!schemaImgs.has(c)) schemaImgs.set(c, { src: src.href, page: p.finalUrl });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return { list: [...schemaImgs].slice(0, 50), size: schemaImgs.size, away };
|
|
258
|
+
}
|
|
259
|
+
// JSON-LD placeholders, superseded types and broken schema images. Off-site images are never fetched.
|
|
260
|
+
export async function schemaImages(site) {
|
|
261
|
+
const { htmlPages, add, notes, firstBytes, indexable } = site;
|
|
262
|
+
for (const p of htmlPages) {
|
|
263
|
+
if (p.clientOnly || !indexable(p)) continue;
|
|
264
|
+
if (p.schemaPlaceholder) add("schema-placeholder", p.finalUrl, `“${p.schemaPlaceholder}”`);
|
|
265
|
+
if (p.superseded.length)
|
|
266
|
+
add("schema-superseded", p.finalUrl, p.superseded.map(t => `${t} → ${SUPERSEDED[t]}`).join(", "));
|
|
267
|
+
}
|
|
268
|
+
const { list, size, away } = schemaImageUrls(site);
|
|
269
|
+
for (const [crawlSrc, { src, page }] of list) {
|
|
270
|
+
// already fetched in checkAssets' pool
|
|
271
|
+
const r = await firstBytes(crawlSrc);
|
|
272
|
+
if (!r)
|
|
273
|
+
away.add(src); // redirects off the crawled site, so not followed
|
|
274
|
+
else if (busy(r)) continue;
|
|
275
|
+
else if (r.status !== 200 && r.status !== 206)
|
|
276
|
+
add("schema-image-broken", page, `${src} → ${r.status || `no response (${r.error})`}`);
|
|
277
|
+
else if (/html/i.test(r.type)) add("schema-image-broken", page, `${src} → an HTML page, not an image`);
|
|
278
|
+
}
|
|
279
|
+
if (away.size)
|
|
280
|
+
notes.push(
|
|
281
|
+
`${away.size} schema image(s) are on another host (often a CDN) or redirect there, e.g. ${quote([...away][0])}, so they weren't checked: only the crawled site is fetched.`,
|
|
282
|
+
);
|
|
283
|
+
if (size > 50) notes.push(`Schema images were checked for the first 50 of ${size}.`);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Alt text, image preload and prerender findings, then extra.media: LCP elements, server times, DOM shape, image
|
|
287
|
+
// credits and caching. speed and lighthouse are the outside checks' results; imageInfo is checkAssets'.
|
|
288
|
+
export function mediaData(site, { speed, lighthouse, imageInfo }) {
|
|
289
|
+
const { htmlPages, add, extra, startOrigin: START_ORIGIN, expectOrigin: EXPECT_ORIGIN, indexable } = site;
|
|
290
|
+
const media = {},
|
|
291
|
+
read = htmlPages.filter(p => indexable(p) && !p.clientOnly),
|
|
292
|
+
path = u => urlOr(u)?.pathname ?? u;
|
|
293
|
+
for (const p of read) {
|
|
294
|
+
const u = p.finalUrl,
|
|
295
|
+
bad = p.imgs
|
|
296
|
+
.filter(i => "alt" in i)
|
|
297
|
+
.map(i => [i.alt, altProblem(i.alt, i.src)])
|
|
298
|
+
.filter(([, why]) => why);
|
|
299
|
+
if (bad.length)
|
|
300
|
+
add("img-alt-quality", u, `${bad.length} image(s), e.g. “${bad[0][0].trim().slice(0, 60)}” (${bad[0][1]})`);
|
|
301
|
+
if (p.imagePreloads > 1)
|
|
302
|
+
add("image-preloads", u, `${p.imagePreloads} image preloads: ${p.preloadHrefs.join(", ")}`);
|
|
303
|
+
if (p.prerender.length) add("prerender-hint", u, `<link rel="prerender" href="${p.prerender[0]}">`);
|
|
304
|
+
}
|
|
305
|
+
const heroes = new Map();
|
|
306
|
+
for (const [source, runs] of [
|
|
307
|
+
["PageSpeed", (speed?.samples || []).map(s => [s.url, s.lab?.lcpElement])],
|
|
308
|
+
["Lighthouse", (lighthouse || []).map(x => [x.url, x.lcpElement])],
|
|
309
|
+
])
|
|
310
|
+
for (const [url, el] of runs)
|
|
311
|
+
if (el && !heroes.has(path(url)))
|
|
312
|
+
heroes.set(path(url), {
|
|
313
|
+
url,
|
|
314
|
+
element: el.element,
|
|
315
|
+
...(el.src ? { src: el.src } : {}),
|
|
316
|
+
source,
|
|
317
|
+
hinted: el.fetchpriorityHigh,
|
|
318
|
+
eager: el.eager,
|
|
319
|
+
discoverable: el.discoverable,
|
|
320
|
+
});
|
|
321
|
+
for (const h of heroes.values()) if (h.hinted === false && h.src) add("hero-no-fetchpriority", h.url, h.src);
|
|
322
|
+
// A lab run's LCP element overrules the per-page checks' first-image guess (often a logo) for lazy-lcp, both ways.
|
|
323
|
+
const guess = site.findings.get("lazy-lcp"),
|
|
324
|
+
page = u => path(u).replace(/\/+$/, "");
|
|
325
|
+
for (const h of heroes.values()) {
|
|
326
|
+
const at = guess ? guess.evidence.findIndex(e => page(e.url) === page(h.url)) : -1;
|
|
327
|
+
if (h.eager === true && at >= 0) {
|
|
328
|
+
guess.evidence.splice(at, 1);
|
|
329
|
+
guess.count--;
|
|
330
|
+
} else if (h.eager === false && at < 0)
|
|
331
|
+
add("lazy-lcp", h.url, `${h.src || h.element} (${h.source}: the LCP image has loading="lazy")`);
|
|
332
|
+
// An LCP image only CSS or a script requests isn't discoverable from the HTML.
|
|
333
|
+
// https://web.dev/articles/optimize-lcp
|
|
334
|
+
if (h.discoverable === false) add("lcp-not-discoverable", h.url, h.src || h.element);
|
|
335
|
+
}
|
|
336
|
+
if (guess && !guess.count) site.findings.delete("lazy-lcp");
|
|
337
|
+
if (heroes.size) media.heroImages = [...heroes.values()].map(({ hinted, eager, discoverable, ...h }) => h);
|
|
338
|
+
const times = htmlPages
|
|
339
|
+
.filter(p => Number.isFinite(p.ms))
|
|
340
|
+
.map(p => ({ url: p.finalUrl, ms: p.ms }))
|
|
341
|
+
.sort((a, b) => a.ms - b.ms);
|
|
342
|
+
// 0.8 s is web.dev's "good" TTFB for real visitors, applied here to a single request from this machine.
|
|
343
|
+
// https://web.dev/articles/ttfb
|
|
344
|
+
if (times.length)
|
|
345
|
+
media.serverTimes = {
|
|
346
|
+
pages: times.length,
|
|
347
|
+
median: times[(times.length - 1) >> 1].ms,
|
|
348
|
+
p95: times[Math.ceil(times.length * 0.95) - 1].ms,
|
|
349
|
+
slow: times
|
|
350
|
+
.filter(t => t.ms > 800)
|
|
351
|
+
.reverse()
|
|
352
|
+
.slice(0, 10),
|
|
353
|
+
};
|
|
354
|
+
// Depth over 32 and over 60 children are local lines taken from older Lighthouse advice.
|
|
355
|
+
const deep = read
|
|
356
|
+
.filter(p => p.domShape.depth > 32)
|
|
357
|
+
.map(p => ({ url: p.finalUrl, depth: p.domShape.depth }))
|
|
358
|
+
.sort((a, b) => b.depth - a.depth);
|
|
359
|
+
const wide = read
|
|
360
|
+
.filter(p => p.domShape.widest.children > 60)
|
|
361
|
+
.map(p => ({ url: p.finalUrl, ...p.domShape.widest }))
|
|
362
|
+
.sort((a, b) => b.children - a.children);
|
|
363
|
+
if (deep.length || wide.length) media.domShape = { deep: deep.slice(0, 20), wide: wide.slice(0, 20) };
|
|
364
|
+
const info = [...imageInfo],
|
|
365
|
+
hosts = {};
|
|
366
|
+
if (info.length)
|
|
367
|
+
media.imageCredits = {
|
|
368
|
+
read: info.length,
|
|
369
|
+
creator: info.filter(([, i]) => i.creator).length,
|
|
370
|
+
ai: info
|
|
371
|
+
.filter(([, i]) => i.ai)
|
|
372
|
+
.map(([s]) => s)
|
|
373
|
+
.slice(0, 20),
|
|
374
|
+
aiCount: info.filter(([, i]) => i.ai).length,
|
|
375
|
+
c2pa: info.filter(([, i]) => i.c2pa).length,
|
|
376
|
+
noCreator: info
|
|
377
|
+
.filter(([, i]) => !i.creator)
|
|
378
|
+
.map(([s]) => s)
|
|
379
|
+
.slice(0, 20),
|
|
380
|
+
};
|
|
381
|
+
for (const p of read)
|
|
382
|
+
for (const i of p.imgs) {
|
|
383
|
+
const x = urlOr(i.src, p.base);
|
|
384
|
+
if (x && /^https?:$/.test(x.protocol) && ![START_ORIGIN, EXPECT_ORIGIN].includes(x.origin))
|
|
385
|
+
hosts[x.host] = (hosts[x.host] || 0) + 1;
|
|
386
|
+
}
|
|
387
|
+
if (info.length || Object.keys(hosts).length)
|
|
388
|
+
media.imageCache = {
|
|
389
|
+
checked: info.length,
|
|
390
|
+
uncached: info
|
|
391
|
+
.filter(([, i]) => i.uncached)
|
|
392
|
+
.map(([s]) => s)
|
|
393
|
+
.slice(0, 20),
|
|
394
|
+
uncachedCount: info.filter(([, i]) => i.uncached).length,
|
|
395
|
+
cdn: info.map(([, i]) => i.cdn).find(Boolean) || null,
|
|
396
|
+
otherHosts: Object.fromEntries(
|
|
397
|
+
Object.entries(hosts)
|
|
398
|
+
.sort((a, b) => b[1] - a[1])
|
|
399
|
+
.slice(0, 10),
|
|
400
|
+
),
|
|
401
|
+
};
|
|
402
|
+
if (lighthouse?.length > 1) media.lighthouseMedians = medianScores(lighthouse);
|
|
403
|
+
if (Object.keys(media).length) extra.media = media;
|
|
404
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Sample pages asked again as Googlebot and as AI search crawlers, each compared with a phone visitor.
|
|
3
|
+
import { readLight } from "../crawl/page.mjs";
|
|
4
|
+
import { isLocal } from "../crawl/fetch.mjs";
|
|
5
|
+
import { sleep } from "./crawl.mjs";
|
|
6
|
+
import { BOTS } from "./agents.mjs";
|
|
7
|
+
|
|
8
|
+
// ---------- what Googlebot gets ----------
|
|
9
|
+
// Google's smartphone Googlebot, with a current Chrome version.
|
|
10
|
+
// https://developers.google.com/search/docs/crawling-indexing/google-common-crawlers
|
|
11
|
+
const GOOGLEBOT_UA =
|
|
12
|
+
"Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.8103.79 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
|
|
13
|
+
// The same phone without the Googlebot token, so a site that serves phones differently serves both alike.
|
|
14
|
+
const PHONE_UA = GOOGLEBOT_UA.replace(/ \(compatible; Googlebot.*$/, "");
|
|
15
|
+
// A response as a page, or null when it isn't HTML, with the sitemap's hreflang alternates merged in as analyze()
|
|
16
|
+
// does. page is analyze()'s context (crawl/page.mjs).
|
|
17
|
+
export const readPage = (r, page) => {
|
|
18
|
+
if (!(r.status === 200 && /html/.test(r.ct) && r.body)) return null;
|
|
19
|
+
const p = readLight(r.body, r.finalUrl, r.headers);
|
|
20
|
+
return { ...p, hreflang: [...p.hreflang, ...page.sitemapHreflang(r.finalUrl)] };
|
|
21
|
+
};
|
|
22
|
+
const noindex = p => p.robots.includes("noindex"),
|
|
23
|
+
canonOf = p => p.canonical ?? "none";
|
|
24
|
+
// A bot challenge by its headers alone, for the main crawl (crawl/queue.mjs): Cloudflare sets cf-mitigated on every
|
|
25
|
+
// challenge page, AWS WAF sets x-amzn-waf-action. The challenge-platform script isn't proof on its own there, since
|
|
26
|
+
// Cloudflare's JavaScript detections load it on ordinary pages too.
|
|
27
|
+
// https://developers.cloudflare.com/cloudflare-challenges/challenge-types/challenge-pages/detect-response/
|
|
28
|
+
// https://docs.aws.amazon.com/waf/latest/developerguide/waf-captcha-and-challenge-actions.html
|
|
29
|
+
export const challengeHeaders = r =>
|
|
30
|
+
/^challenge$/i.test(r.headers.get("cf-mitigated") || "") ||
|
|
31
|
+
/^(challenge|captcha)$/i.test(r.headers.get("x-amzn-waf-action") || "");
|
|
32
|
+
const challenged = r => challengeHeaders(r) || /\/cdn-cgi\/challenge-platform\//.test(r.body || "");
|
|
33
|
+
// A 429 or 5xx is asked once more a second later, so a rate limit or flaky backend hitting one side isn't judged.
|
|
34
|
+
const busy = r => r.status === 429 || r.status >= 500;
|
|
35
|
+
|
|
36
|
+
// Runs last, since a firewall may ban the address that sent a fake Googlebot. Only the crawled site is asked.
|
|
37
|
+
// botSample is the home page and up to 9 sample pages (sampleUrls). Returns how many pages were compared.
|
|
38
|
+
export async function compareGooglebot(site, { page, botSample }) {
|
|
39
|
+
const { add, start: START, startOrigin: START_ORIGIN, conc: CONC, follow } = site;
|
|
40
|
+
const pageOf = r => readPage(r, page),
|
|
41
|
+
askAgain = async (u, ua) => {
|
|
42
|
+
await sleep(1000);
|
|
43
|
+
return follow(u, ua);
|
|
44
|
+
};
|
|
45
|
+
// A local build has no CDN or firewall in front, so a refusal there is the app's own (prerender middleware, bot
|
|
46
|
+
// detection). CDN and firewall rules only show when a staging or live server is crawled.
|
|
47
|
+
const NO_FIREWALL = isLocal(START_ORIGIN) || /^(10|192\.168|172\.(1[6-9]|2\d|3[01]))\./.test(START.hostname);
|
|
48
|
+
let botCompared = 0;
|
|
49
|
+
for (let i = 0; i < botSample.length; i += CONC)
|
|
50
|
+
await Promise.all(
|
|
51
|
+
botSample.slice(i, i + CONC).map(async u => {
|
|
52
|
+
let [vr, gr] = await Promise.all([follow(u, PHONE_UA), follow(u, GOOGLEBOT_UA)]);
|
|
53
|
+
if (busy(vr)) vr = await askAgain(u, PHONE_UA);
|
|
54
|
+
const v = pageOf(vr),
|
|
55
|
+
at = vr.finalUrl;
|
|
56
|
+
if (!v) return; // the visitor didn't get the page either: nothing to compare
|
|
57
|
+
if (busy(gr)) gr = await askAgain(u, GOOGLEBOT_UA);
|
|
58
|
+
const g = pageOf(gr),
|
|
59
|
+
challenge = challenged(gr) && !challenged(vr);
|
|
60
|
+
botCompared++;
|
|
61
|
+
const got = `Googlebot got ${challenge ? `a bot challenge (${gr.status})` : gr.status || `no answer (${gr.error})`}, a visitor 200`;
|
|
62
|
+
// A firewall that verifies Googlebot by IP is right to refuse this request.
|
|
63
|
+
if ((challenge || [403, 429, 503].includes(gr.status)) && !NO_FIREWALL)
|
|
64
|
+
return add("googlebot-firewall", at, got);
|
|
65
|
+
if (gr.status >= 400 || gr.status === 0 || challenge) return add("googlebot-blocked", at, got);
|
|
66
|
+
if (g && noindex(g) && !noindex(v))
|
|
67
|
+
return add("googlebot-blocked", at, "Googlebot gets a noindex that a visitor doesn't");
|
|
68
|
+
const diffs = !g
|
|
69
|
+
? [`Googlebot got ${gr.status} ${gr.ct || "with no content type"} instead of the page`]
|
|
70
|
+
: [
|
|
71
|
+
gr.finalUrl !== at && `Googlebot is sent to ${gr.finalUrl}`,
|
|
72
|
+
noindex(v) && !noindex(g) && "only a visitor gets noindex",
|
|
73
|
+
canonOf(g) !== canonOf(v) && `canonical: ${canonOf(v)} → ${canonOf(g)}`,
|
|
74
|
+
(g.title ?? "") !== (v.title ?? "") && `title: “${v.title ?? "none"}” → “${g.title ?? "none"}”`,
|
|
75
|
+
v.words >= 50 && g.words < v.words / 2 && `${g.words} words for Googlebot, ${v.words} for a visitor`,
|
|
76
|
+
].filter(Boolean);
|
|
77
|
+
if (diffs.length) add("googlebot-differs", at, diffs.join("; "));
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
return botCompared;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// The Googlebot comparison with AI search crawlers' user agents, on the home page and up to 2 more sample pages.
|
|
84
|
+
// Posing as another company's crawler counts as outside contact, so it needs --outside as well as --ai-bot-probe. An
|
|
85
|
+
// error or challenge the visitor didn't get is a decision (MAP-06): a firewall checking the vendor's IPs is right.
|
|
86
|
+
export async function aiBotProbe(site, { page, botSample, aiProbe: AI_PROBE, outside: OUTSIDE }) {
|
|
87
|
+
const { add, notes, extra, follow } = site;
|
|
88
|
+
const pageOf = r => readPage(r, page),
|
|
89
|
+
askAgain = async (u, ua) => {
|
|
90
|
+
await sleep(1000);
|
|
91
|
+
return follow(u, ua);
|
|
92
|
+
};
|
|
93
|
+
// User agents as the vendors publish them; Anthropic names only the Claude-SearchBot token, so its string is built
|
|
94
|
+
// around that.
|
|
95
|
+
// https://developers.openai.com/api/docs/bots
|
|
96
|
+
// https://docs.perplexity.ai/guides/bots
|
|
97
|
+
// https://support.claude.com/en/articles/8896518
|
|
98
|
+
const AI_PROBE_UAS = Object.fromEntries(BOTS.filter(b => b.probeUa).map(b => [b.name, b.probeUa])); // data/ai-bots.json
|
|
99
|
+
if (AI_PROBE && !OUTSIDE)
|
|
100
|
+
notes.push(
|
|
101
|
+
"--ai-bot-probe runs only with outside checks on (--outside) and the owner's own yes: it asks a few pages again as OAI-SearchBot, Claude-SearchBot and PerplexityBot. It didn't run.",
|
|
102
|
+
);
|
|
103
|
+
else if (AI_PROBE)
|
|
104
|
+
await Promise.all(
|
|
105
|
+
botSample.slice(0, 3).map(async u => {
|
|
106
|
+
const uas = Object.entries(AI_PROBE_UAS);
|
|
107
|
+
let [vr, ...brs] = await Promise.all([follow(u, PHONE_UA), ...uas.map(([, ua]) => follow(u, ua))]);
|
|
108
|
+
if (busy(vr)) vr = await askAgain(u, PHONE_UA);
|
|
109
|
+
if (!pageOf(vr)) return; // the visitor didn't get the page either: nothing to compare
|
|
110
|
+
const got = [];
|
|
111
|
+
let fightMode = false;
|
|
112
|
+
for (let [i, br] of brs.entries()) {
|
|
113
|
+
if (busy(br)) br = await askAgain(u, uas[i][1]);
|
|
114
|
+
// A 402 is Cloudflare's pay per crawl asking for payment, priced in crawler-price: paid access, not a refusal.
|
|
115
|
+
// https://developers.cloudflare.com/ai-crawl-control/features/pay-per-crawl/use-pay-per-crawl-as-ai-owner/crawl-pages/
|
|
116
|
+
if (br.status === 402) {
|
|
117
|
+
const price = br.headers.get("crawler-price");
|
|
118
|
+
(extra.aiBotPaid ??= []).push({
|
|
119
|
+
url: vr.finalUrl,
|
|
120
|
+
bot: uas[i][0],
|
|
121
|
+
...(price ? { price: price.slice(0, 100) } : {}),
|
|
122
|
+
});
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
// A Cloudflare challenge points to Bot Fight Mode, which custom firewall rules can't skip (sources at
|
|
126
|
+
// ai-bot-refused in agents.mjs).
|
|
127
|
+
const challenge = challenged(br) && !challenged(vr),
|
|
128
|
+
cf =
|
|
129
|
+
challenge &&
|
|
130
|
+
(/^challenge$/i.test(br.headers.get("cf-mitigated") || "") ||
|
|
131
|
+
/\/cdn-cgi\/challenge-platform\//.test(br.body || ""));
|
|
132
|
+
fightMode ||= cf;
|
|
133
|
+
if (challenge || br.status >= 400 || br.status === 0)
|
|
134
|
+
got.push(
|
|
135
|
+
`${uas[i][0]} got ${challenge ? `a ${cf ? "Cloudflare " : ""}bot challenge (${br.status})` : br.status || `no answer (${br.error})`}`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
if (got.length)
|
|
139
|
+
add(
|
|
140
|
+
"ai-bot-refused",
|
|
141
|
+
vr.finalUrl,
|
|
142
|
+
`${got.join("; ")}, a visitor 200${fightMode ? ". Cloudflare's Bot Fight Mode is a likely cause: custom firewall rules can't make an exception to it" : ""}`,
|
|
143
|
+
);
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
}
|