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,552 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Renders pages in an installed Chrome or Edge and compares the result with the raw HTML. The page's own scripts,
|
|
3
|
+
// analytics included, run behind a guard that keeps them off private addresses.
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { lookup } from "node:dns";
|
|
6
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
7
|
+
import { createServer, request as httpRequest } from "node:http";
|
|
8
|
+
import { connect, isIP } from "node:net";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { CHROME_FLAGS, containerArgs, launchChrome, ownProxyArgs, quietProfile } from "../lib/cdp.mjs";
|
|
12
|
+
import { chromeProxyArgs } from "../lib/proxy.mjs";
|
|
13
|
+
import { redact } from "../lib/redact.mjs";
|
|
14
|
+
import { installedBrowser } from "../lib/settings-dir.mjs";
|
|
15
|
+
import { jsonLdNodes, norm, stripNonContent, typesOf } from "../lib/html.mjs";
|
|
16
|
+
import { privateIp } from "./outbound.mjs";
|
|
17
|
+
|
|
18
|
+
export const CHECKS = {
|
|
19
|
+
// Google asks sites not to change the canonical with JavaScript, and not all bots run it.
|
|
20
|
+
// https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics
|
|
21
|
+
"render-changes-head": [
|
|
22
|
+
"REND-06",
|
|
23
|
+
"high",
|
|
24
|
+
n => `JavaScript changes the canonical or robots tag on ${n} page(s)`,
|
|
25
|
+
"Search engines read the raw HTML first and the rendered page later. When the two disagree, which value wins isn't predictable, and a robots or canonical change can drop a page. Google asks sites not to change the canonical with JavaScript.",
|
|
26
|
+
"Output the final canonical and robots tag in the server HTML and don't change them in client code.",
|
|
27
|
+
],
|
|
28
|
+
// Low: Google accepts a title or description set by JavaScript, so this matters only to crawlers that don't run it.
|
|
29
|
+
"render-changes-text": [
|
|
30
|
+
"REND-06",
|
|
31
|
+
"low",
|
|
32
|
+
n => `JavaScript changes the title, meta description or H1 on ${n} page(s)`,
|
|
33
|
+
"Google runs the page's JavaScript and uses what it sets, and says setting or changing the title or meta description this way is fine. Crawlers that don't run JavaScript, most AI crawlers among them, only ever see the server's title, description and H1, so they get a different summary of the page.",
|
|
34
|
+
"If the server HTML's title, description or H1 is a placeholder or out of date, output the final one in the server HTML. If both versions are fine, nothing needs to change.",
|
|
35
|
+
],
|
|
36
|
+
"render-adds-content": [
|
|
37
|
+
"REND-01",
|
|
38
|
+
"medium",
|
|
39
|
+
n => `${n} page(s) get their H1, schema or many links only after JavaScript runs`,
|
|
40
|
+
"Crawlers that don't run JavaScript (most AI crawlers, and Google's first pass) miss whatever only appears after rendering.",
|
|
41
|
+
"Render the H1, JSON-LD and navigation links on the server; keep client JavaScript for interactivity.",
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// A CHROME_PATH with no file there (a typo, or a Git Bash /c/... path on Windows) throws rather than quietly running a
|
|
46
|
+
// browser nobody chose.
|
|
47
|
+
export function findBrowser(env = process.env, platform = process.platform, exists = existsSync) {
|
|
48
|
+
if (env.CHROME_PATH && !exists(env.CHROME_PATH))
|
|
49
|
+
throw new Error(
|
|
50
|
+
`CHROME_PATH is set to “${env.CHROME_PATH}”, but there's no file there, so that browser can't start. Set it to the full path of Chrome or Edge, or unset it to use the installed one.`,
|
|
51
|
+
);
|
|
52
|
+
const pf = env.PROGRAMFILES ?? env.ProgramFiles,
|
|
53
|
+
pf86 = env["PROGRAMFILES(X86)"] ?? env["ProgramFiles(x86)"],
|
|
54
|
+
local = env.LOCALAPPDATA ?? env.LocalAppData;
|
|
55
|
+
const candidates =
|
|
56
|
+
{
|
|
57
|
+
win32: [pf, pf86, local]
|
|
58
|
+
.filter(Boolean)
|
|
59
|
+
.flatMap(base => [
|
|
60
|
+
`${base}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
61
|
+
`${base}\\Microsoft\\Edge\\Application\\msedge.exe`,
|
|
62
|
+
]),
|
|
63
|
+
darwin: [
|
|
64
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
65
|
+
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
66
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
67
|
+
],
|
|
68
|
+
linux: [
|
|
69
|
+
"/usr/bin/google-chrome",
|
|
70
|
+
"/usr/bin/google-chrome-stable",
|
|
71
|
+
"/usr/bin/chromium",
|
|
72
|
+
"/usr/bin/chromium-browser",
|
|
73
|
+
"/usr/bin/microsoft-edge",
|
|
74
|
+
"/snap/bin/chromium",
|
|
75
|
+
],
|
|
76
|
+
}[platform] || [];
|
|
77
|
+
// Last, the browser `npx seo-supervisor --with-browser` installed in the settings folder.
|
|
78
|
+
return [env.CHROME_PATH, ...candidates].find(p => p && exists(p)) || installedBrowser(env) || null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Why Chrome showed something other than the site's page, or null. Compared as is, an error page would read as a
|
|
82
|
+
// JavaScript title change. Newer Chrome prints "Page load failed" and dumps nothing; older ones dump an error page.
|
|
83
|
+
// The markers are tag attributes, which page text can't fake: the dump escapes text's "<" as "<".
|
|
84
|
+
export function chromeError(dom, stderr = "") {
|
|
85
|
+
const failed = stderr.match(/Page load failed: (net::ERR_\w+)/);
|
|
86
|
+
if (failed) return failed[1];
|
|
87
|
+
if (
|
|
88
|
+
/<[a-z][^>]*="chrome-error:\/\/|<div\b[^>]*\bid="main-frame-error"|<body\b[^>]*\bclass="[^"]*\bneterror\b/i.test(
|
|
89
|
+
dom,
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
return dom.match(/\b(?:net::)?ERR_[A-Z_]+\b/)?.[0] || "Chrome's error page";
|
|
93
|
+
return dom.trim() ? null : "an empty page";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// When given, guard's flags replace launchChrome's proxy flags. host ({ platform, uid, env, exists }) is for tests.
|
|
97
|
+
export const renderArgs = (profile, url, host = {}, guard = null) => [
|
|
98
|
+
"--headless=new",
|
|
99
|
+
"--disable-gpu",
|
|
100
|
+
"--no-first-run",
|
|
101
|
+
"--no-default-browser-check",
|
|
102
|
+
"--disable-extensions",
|
|
103
|
+
...CHROME_FLAGS,
|
|
104
|
+
...containerArgs(host),
|
|
105
|
+
...(guard || ownProxyArgs(host.env)),
|
|
106
|
+
`--user-data-dir=${profile}`,
|
|
107
|
+
"--virtual-time-budget=5000",
|
|
108
|
+
"--dump-dom",
|
|
109
|
+
url,
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
// ---------- the browser guard ----------
|
|
113
|
+
// Page scripts must not reach private addresses or the cloud metadata service (169.254.169.254), whose answers could
|
|
114
|
+
// end up in the report. The site's own addresses stay open (a local build's API on another port), as does loopback
|
|
115
|
+
// for a local site. Every address a name resolves to is checked, so a public name for a private address is refused.
|
|
116
|
+
// The returned check resolves to the host's addresses, or null when the host is refused.
|
|
117
|
+
export async function addressCheck(siteUrl, { dns = lookup } = {}) {
|
|
118
|
+
const resolve = host =>
|
|
119
|
+
isIP(host)
|
|
120
|
+
? Promise.resolve([host])
|
|
121
|
+
: new Promise((ok, fail) => dns(host, { all: true }, (e, list) => (e ? fail(e) : ok(list.map(a => a.address)))));
|
|
122
|
+
const bare = h => h.replace(/^\[|\]$/g, "");
|
|
123
|
+
const own = new Set(await resolve(bare(new URL(siteUrl).hostname)).catch(() => []));
|
|
124
|
+
if ([...own].some(a => /^127\.|^::1$/.test(a))) own.add("127.0.0.1").add("::1");
|
|
125
|
+
const seen = new Map();
|
|
126
|
+
return host => {
|
|
127
|
+
host = bare(host);
|
|
128
|
+
if (!seen.has(host))
|
|
129
|
+
seen.set(
|
|
130
|
+
host,
|
|
131
|
+
resolve(host).then(
|
|
132
|
+
list => (list.length && list.every(a => own.has(a) || !privateIp(a)) ? list : null),
|
|
133
|
+
() => null,
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
return seen.get(host);
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** A local proxy for every request a guarded Chrome makes. It connects only to the address it checked, so a name can't
|
|
141
|
+
* pass the check and then resolve elsewhere. Returns null when HTTPS_PROXY or HTTP_PROXY is set, since the guard
|
|
142
|
+
* doesn't chain to another proxy; add that if the guard is needed behind a company proxy. */
|
|
143
|
+
export async function startGuard(siteUrl, { dns = lookup, env = process.env } = {}) {
|
|
144
|
+
if (chromeProxyArgs(env).length) return null;
|
|
145
|
+
const check = await addressCheck(siteUrl, { dns }),
|
|
146
|
+
blocked = [],
|
|
147
|
+
sockets = new Set();
|
|
148
|
+
const refuse = what => {
|
|
149
|
+
if (blocked.length < 100) blocked.push(what);
|
|
150
|
+
};
|
|
151
|
+
let closed = false; // a request still being checked when Chrome hangs up or the guard closes opens nothing
|
|
152
|
+
// Node connects to the checked addresses only, trying each in turn (localhost may be ::1 or 127.0.0.1).
|
|
153
|
+
const pinned = list => (name, opts, cb) =>
|
|
154
|
+
opts?.all
|
|
155
|
+
? cb(
|
|
156
|
+
null,
|
|
157
|
+
list.map(address => ({ address, family: isIP(address) })),
|
|
158
|
+
)
|
|
159
|
+
: cb(null, list[0], isIP(list[0]));
|
|
160
|
+
const server = createServer(async (req, res) => {
|
|
161
|
+
let u, ips;
|
|
162
|
+
try {
|
|
163
|
+
u = new URL(req.url);
|
|
164
|
+
ips = /^http:$/.test(u.protocol) && (await check(u.hostname));
|
|
165
|
+
} catch {}
|
|
166
|
+
if (closed || res.destroyed) return res.destroy();
|
|
167
|
+
if (!ips) {
|
|
168
|
+
if (u) refuse(u.href);
|
|
169
|
+
res
|
|
170
|
+
.writeHead(403, { "content-type": "text/plain" })
|
|
171
|
+
.end("seo-supervisor: not a public address, so the browser may not load it");
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const headers = { ...req.headers };
|
|
175
|
+
delete headers["proxy-connection"];
|
|
176
|
+
delete headers["proxy-authorization"];
|
|
177
|
+
const up = httpRequest(
|
|
178
|
+
{
|
|
179
|
+
host: u.hostname.replace(/^\[|\]$/g, ""),
|
|
180
|
+
port: u.port || 80,
|
|
181
|
+
lookup: pinned(ips),
|
|
182
|
+
method: req.method,
|
|
183
|
+
path: u.pathname + u.search,
|
|
184
|
+
headers,
|
|
185
|
+
setHost: false,
|
|
186
|
+
},
|
|
187
|
+
r => {
|
|
188
|
+
res.writeHead(r.statusCode, r.headers);
|
|
189
|
+
r.pipe(res);
|
|
190
|
+
},
|
|
191
|
+
);
|
|
192
|
+
up.on("error", () => res.destroy());
|
|
193
|
+
res.on("close", () => up.destroy());
|
|
194
|
+
req.pipe(up);
|
|
195
|
+
});
|
|
196
|
+
server.on("connect", async (req, sock, head) => {
|
|
197
|
+
let target, ips, up;
|
|
198
|
+
sockets.add(sock);
|
|
199
|
+
sock
|
|
200
|
+
.on("close", () => {
|
|
201
|
+
sockets.delete(sock);
|
|
202
|
+
up?.destroy();
|
|
203
|
+
})
|
|
204
|
+
.on("error", () => {});
|
|
205
|
+
try {
|
|
206
|
+
target = new URL(`http://${req.url}`);
|
|
207
|
+
ips = await check(target.hostname);
|
|
208
|
+
} catch {}
|
|
209
|
+
if (closed || sock.destroyed) return sock.destroy();
|
|
210
|
+
if (!ips) {
|
|
211
|
+
refuse(req.url);
|
|
212
|
+
sock.end("HTTP/1.1 403 Forbidden\r\n\r\n");
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
up = connect(
|
|
216
|
+
{ host: target.hostname.replace(/^\[|\]$/g, ""), port: Number(target.port) || 443, lookup: pinned(ips) },
|
|
217
|
+
() => {
|
|
218
|
+
sock.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
219
|
+
up.write(head);
|
|
220
|
+
up.pipe(sock).on("error", () => {});
|
|
221
|
+
sock.pipe(up);
|
|
222
|
+
},
|
|
223
|
+
);
|
|
224
|
+
up.on("close", () => sock.destroy()).on("error", () => sock.destroy());
|
|
225
|
+
});
|
|
226
|
+
await /** @type {Promise<void>} */ (new Promise(ok => server.listen(0, "127.0.0.1", ok)));
|
|
227
|
+
server.unref(); // a guard left open never keeps the process alive
|
|
228
|
+
const port = /** @type {import("node:net").AddressInfo} */ (server.address()).port;
|
|
229
|
+
return {
|
|
230
|
+
port,
|
|
231
|
+
blocked,
|
|
232
|
+
// <-loopback> sends loopback and link-local (169.254.x.x) through the proxy too, and WebRTC may use UDP only
|
|
233
|
+
// through it. The site goes direct so its errors stay Chrome's; update.googleapis.com goes direct to CHROME_FLAGS'
|
|
234
|
+
// rule that makes it unresolvable. https://chromium.googlesource.com/chromium/src/+/HEAD/net/docs/proxy.md
|
|
235
|
+
args: [
|
|
236
|
+
`--proxy-server=http://127.0.0.1:${port}`,
|
|
237
|
+
`--proxy-bypass-list=<-loopback>;${new URL(siteUrl).host};update.googleapis.com`,
|
|
238
|
+
"--force-webrtc-ip-handling-policy=disable_non_proxied_udp",
|
|
239
|
+
],
|
|
240
|
+
close: () => {
|
|
241
|
+
closed = true;
|
|
242
|
+
for (const s of sockets) s.destroy();
|
|
243
|
+
server.closeAllConnections();
|
|
244
|
+
return new Promise(ok => server.close(() => ok()));
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Service workers are off: their requests aren't the tab's, and one would serve the next load from its cache.
|
|
250
|
+
// WebSockets stay for Chrome's back/forward cache test. Cross-site frames and WebSockets, which the tab doesn't see,
|
|
251
|
+
// go through the guard's proxy instead.
|
|
252
|
+
const NO_SW = "delete Navigator.prototype.serviceWorker";
|
|
253
|
+
export async function guardTab(page, checkAddress) {
|
|
254
|
+
page.on("Fetch.requestPaused", ({ requestId, request }) => {
|
|
255
|
+
const u = new URL(request.url);
|
|
256
|
+
(/^https?:$/.test(u.protocol) ? checkAddress(u.hostname) : Promise.resolve(true))
|
|
257
|
+
.then(ok =>
|
|
258
|
+
page.send(
|
|
259
|
+
ok ? "Fetch.continueRequest" : "Fetch.failRequest",
|
|
260
|
+
ok ? { requestId } : { requestId, errorReason: "AddressUnreachable" },
|
|
261
|
+
),
|
|
262
|
+
)
|
|
263
|
+
.catch(() => {});
|
|
264
|
+
});
|
|
265
|
+
await page.send("Fetch.enable", { patterns: [{ urlPattern: "*" }] });
|
|
266
|
+
await page.send("Page.addScriptToEvaluateOnNewDocument", { source: NO_SW });
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** One guarded Chrome for a site's whole outside check: the renders and visual.mjs's phone and desktop loads.
|
|
270
|
+
* close() closes the browser and the guard.
|
|
271
|
+
* @param {string} browser
|
|
272
|
+
* @param {string} siteUrl
|
|
273
|
+
* @param {{ dns?: typeof lookup }} [options] */
|
|
274
|
+
export async function openSession(browser, siteUrl, { dns } = {}) {
|
|
275
|
+
const checkAddress = await addressCheck(siteUrl, { dns }),
|
|
276
|
+
guard = await startGuard(siteUrl, { dns });
|
|
277
|
+
const chrome = await launchChrome(browser, { args: guard?.args || [] }).catch(async e => {
|
|
278
|
+
await guard?.close();
|
|
279
|
+
throw e;
|
|
280
|
+
}); // a browser that won't start leaves no guard open
|
|
281
|
+
return {
|
|
282
|
+
...chrome,
|
|
283
|
+
checkAddress,
|
|
284
|
+
close: async () => {
|
|
285
|
+
await chrome.close();
|
|
286
|
+
await guard?.close();
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// A browser context per render, so cookies, storage and cache never carry over, and the same 5 s of virtual time the
|
|
292
|
+
// one-shot render gets from --virtual-time-budget. timeoutMs is real time.
|
|
293
|
+
async function renderIn(session, url, timeoutMs, dns) {
|
|
294
|
+
const checkAddress = session.checkAddress || (await addressCheck(url, { dns }));
|
|
295
|
+
const page = await session.newPage({ isolated: true });
|
|
296
|
+
let timer;
|
|
297
|
+
try {
|
|
298
|
+
const budget = new Promise(ok => page.on("Emulation.virtualTimeBudgetExpired", ok));
|
|
299
|
+
await guardTab(page, checkAddress);
|
|
300
|
+
await page.send("Page.enable");
|
|
301
|
+
const nav = await page.send("Page.navigate", { url });
|
|
302
|
+
if (nav.errorText) throw new Error(redact(`Chrome couldn't load ${url}: ${nav.errorText}`));
|
|
303
|
+
// Set after navigating: on the blank tab the budget runs out before the page arrives.
|
|
304
|
+
await page.send("Emulation.setVirtualTimePolicy", { policy: "pauseIfNetworkFetchesPending", budget: 5000 });
|
|
305
|
+
await Promise.race([
|
|
306
|
+
budget,
|
|
307
|
+
new Promise((_, no) => {
|
|
308
|
+
timer = setTimeout(
|
|
309
|
+
no,
|
|
310
|
+
timeoutMs,
|
|
311
|
+
new Error(redact(`Chrome didn't finish rendering ${url} in ${timeoutMs / 1000} s`)),
|
|
312
|
+
);
|
|
313
|
+
}),
|
|
314
|
+
]);
|
|
315
|
+
const dom = String(
|
|
316
|
+
(await page.send("Runtime.evaluate", { expression: "document.documentElement.outerHTML", returnByValue: true }))
|
|
317
|
+
.result?.value ?? "",
|
|
318
|
+
);
|
|
319
|
+
const why = chromeError(dom),
|
|
320
|
+
gate = why ? null : gateOf(dom);
|
|
321
|
+
if (why) throw new Error(redact(`Chrome couldn't load ${url}: ${why}`));
|
|
322
|
+
if (gate) throw new Error(redact(`Chrome showed ${gate} at ${url}, so it wasn't compared with the raw HTML`));
|
|
323
|
+
return dom;
|
|
324
|
+
} finally {
|
|
325
|
+
clearTimeout(timer);
|
|
326
|
+
await page.close().catch(() => {});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// The DOM after scripts ran, in a tab of session's browser or else a one-shot Chrome with a throwaway profile. No
|
|
331
|
+
// switch turns service workers off there, so the guard checks their requests and each profile is deleted after use.
|
|
332
|
+
// Errors are redacted because Chrome's command line names the temporary profile, under the home folder.
|
|
333
|
+
/**
|
|
334
|
+
* @param {string} browser
|
|
335
|
+
* @param {string} url
|
|
336
|
+
* @param {{ timeoutMs?: number, dns?: typeof lookup }} [options]
|
|
337
|
+
* @param {Awaited<ReturnType<typeof launchChrome>> & { checkAddress?: (host: string) => Promise<string[] | null> } | null} [session] */
|
|
338
|
+
export async function renderPage(browser, url, { timeoutMs = 20000, dns } = {}, session = null) {
|
|
339
|
+
if (session) return renderIn(session, url, timeoutMs, dns);
|
|
340
|
+
const profile = quietProfile(mkdtempSync(join(tmpdir(), "seo-supervisor-render-")));
|
|
341
|
+
const guard = await startGuard(url, { dns });
|
|
342
|
+
const args = renderArgs(profile, url, {}, guard?.args);
|
|
343
|
+
try {
|
|
344
|
+
return await new Promise((ok, fail) =>
|
|
345
|
+
execFile(browser, args, { timeout: timeoutMs, maxBuffer: 32 * 1024 * 1024 }, (err, stdout, stderr) => {
|
|
346
|
+
const why = err ? null : chromeError(stdout, stderr),
|
|
347
|
+
gate = err || why ? null : gateOf(stdout);
|
|
348
|
+
if (err) {
|
|
349
|
+
err.message = redact(err.message);
|
|
350
|
+
err.stderr = stderr;
|
|
351
|
+
fail(err);
|
|
352
|
+
} else if (why) fail(Object.assign(new Error(redact(`Chrome couldn't load ${url}: ${why}`)), { stderr }));
|
|
353
|
+
else if (gate)
|
|
354
|
+
fail(new Error(redact(`Chrome showed ${gate} at ${url}, so it wasn't compared with the raw HTML`)));
|
|
355
|
+
else ok(stdout);
|
|
356
|
+
}),
|
|
357
|
+
);
|
|
358
|
+
} finally {
|
|
359
|
+
try {
|
|
360
|
+
rmSync(profile, { recursive: true, force: true });
|
|
361
|
+
} catch {}
|
|
362
|
+
await guard?.close();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// A page takes a browser start and up to 5 s of virtual time, about 5 s on a typical site. The cap keeps a
|
|
367
|
+
// --render all run near a quarter of an hour.
|
|
368
|
+
export const RENDER_SECONDS_PER_PAGE = 5,
|
|
369
|
+
RENDER_ALL_CAP = 200;
|
|
370
|
+
|
|
371
|
+
/** The pages for --render all, home first. note says how many the cap left out, or is null.
|
|
372
|
+
* @param {string[]} urls
|
|
373
|
+
* @param {{ max?: number, log?: (message: string) => void }} [options] */
|
|
374
|
+
export function renderAll(urls, { max = RENDER_ALL_CAP, log = () => {} } = {}) {
|
|
375
|
+
const home = u => new URL(u).pathname === "/";
|
|
376
|
+
const list = [...urls].sort((a, b) => +home(b) - +home(a)).slice(0, max);
|
|
377
|
+
const minutes = Math.max(1, Math.round((list.length * RENDER_SECONDS_PER_PAGE) / 60));
|
|
378
|
+
log(
|
|
379
|
+
`Rendering ${list.length} page${list.length === 1 ? "" : "s"} in the browser, about ${minutes} minute${minutes === 1 ? "" : "s"} (roughly ${RENDER_SECONDS_PER_PAGE} seconds a page), one at a time.`,
|
|
380
|
+
);
|
|
381
|
+
return {
|
|
382
|
+
urls: list,
|
|
383
|
+
note:
|
|
384
|
+
urls.length > max
|
|
385
|
+
? `Rendering stopped at ${max} pages, the cap for --render all; ${urls.length - max} more page(s) weren't rendered.`
|
|
386
|
+
: null,
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Chrome's DOM dump writes characters out literally, so both sides are fully decoded before comparing.
|
|
391
|
+
const NAMED = {
|
|
392
|
+
amp: "&",
|
|
393
|
+
lt: "<",
|
|
394
|
+
gt: ">",
|
|
395
|
+
quot: '"',
|
|
396
|
+
apos: "'",
|
|
397
|
+
nbsp: " ",
|
|
398
|
+
ndash: "–",
|
|
399
|
+
mdash: "—",
|
|
400
|
+
lsquo: "‘",
|
|
401
|
+
rsquo: "’",
|
|
402
|
+
ldquo: "“",
|
|
403
|
+
rdquo: "”",
|
|
404
|
+
hellip: "…",
|
|
405
|
+
middot: "·",
|
|
406
|
+
bull: "•",
|
|
407
|
+
laquo: "«",
|
|
408
|
+
raquo: "»",
|
|
409
|
+
copy: "©",
|
|
410
|
+
reg: "®",
|
|
411
|
+
trade: "™",
|
|
412
|
+
times: "×",
|
|
413
|
+
eacute: "é",
|
|
414
|
+
egrave: "è",
|
|
415
|
+
ecirc: "ê",
|
|
416
|
+
aacute: "á",
|
|
417
|
+
agrave: "à",
|
|
418
|
+
iacute: "í",
|
|
419
|
+
oacute: "ó",
|
|
420
|
+
uacute: "ú",
|
|
421
|
+
ntilde: "ñ",
|
|
422
|
+
ccedil: "ç",
|
|
423
|
+
ouml: "ö",
|
|
424
|
+
uuml: "ü",
|
|
425
|
+
auml: "ä",
|
|
426
|
+
szlig: "ß",
|
|
427
|
+
};
|
|
428
|
+
const decode = s =>
|
|
429
|
+
s
|
|
430
|
+
.replace(/&#x([0-9a-f]+);/gi, (m, h) => {
|
|
431
|
+
try {
|
|
432
|
+
return String.fromCodePoint(parseInt(h, 16));
|
|
433
|
+
} catch {
|
|
434
|
+
return m;
|
|
435
|
+
}
|
|
436
|
+
})
|
|
437
|
+
.replace(/&#(\d+);/g, (m, d) => {
|
|
438
|
+
try {
|
|
439
|
+
return String.fromCodePoint(Number(d));
|
|
440
|
+
} catch {
|
|
441
|
+
return m;
|
|
442
|
+
}
|
|
443
|
+
})
|
|
444
|
+
.replace(/&([a-z]+);/gi, (m, n) => NAMED[n.toLowerCase()] ?? m)
|
|
445
|
+
.replace(/[\s ]+/g, " ")
|
|
446
|
+
.trim();
|
|
447
|
+
const sameUrl = (a, b) => {
|
|
448
|
+
try {
|
|
449
|
+
return new URL(a, "https://x.invalid/").href === new URL(b, "https://x.invalid/").href;
|
|
450
|
+
} catch {
|
|
451
|
+
return a === b;
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
const attrsOf = tag =>
|
|
455
|
+
Object.fromEntries(
|
|
456
|
+
[...tag.matchAll(/([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/g)].map(m => [
|
|
457
|
+
m[1].toLowerCase(),
|
|
458
|
+
m[2] ?? m[3] ?? m[4],
|
|
459
|
+
]),
|
|
460
|
+
);
|
|
461
|
+
function read(html) {
|
|
462
|
+
const tags = name => [...html.matchAll(new RegExp(`<${name}\\b[^>]*>`, "gi"))].map(m => attrsOf(m[0]));
|
|
463
|
+
const title = html.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
|
|
464
|
+
const h1 = html.match(/<h1\b[^>]*>([\s\S]*?)<\/h1>/i);
|
|
465
|
+
return {
|
|
466
|
+
title: title ? decode(title[1]) : null,
|
|
467
|
+
canonical: (c => (c == null ? null : decode(c)))(
|
|
468
|
+
tags("link").find(l => (l.rel || "").toLowerCase().split(/\s+/).includes("canonical"))?.href,
|
|
469
|
+
),
|
|
470
|
+
robots:
|
|
471
|
+
tags("meta")
|
|
472
|
+
.find(m => (m.name || "").toLowerCase() === "robots")
|
|
473
|
+
?.content?.toLowerCase()
|
|
474
|
+
.replace(/\s+/g, "") ?? null,
|
|
475
|
+
description: (c => (c == null ? null : decode(c)))(
|
|
476
|
+
tags("meta").find(m => (m.name || "").toLowerCase() === "description")?.content,
|
|
477
|
+
),
|
|
478
|
+
h1: h1 ? decode(h1[1].replace(/<[^>]+>/g, " ")) : null,
|
|
479
|
+
jsonld: (html.match(/<script\b[^>]*application\/ld\+json/gi) || []).length,
|
|
480
|
+
types: [...new Set(jsonLdNodes(html).nodes.flatMap(typesOf).map(String))],
|
|
481
|
+
words: new Set(
|
|
482
|
+
norm(decode(stripNonContent(html.match(/<body\b[\s\S]*/i)?.[0] || "").replace(/<[^>]+>/g, " ")))
|
|
483
|
+
.split(" ")
|
|
484
|
+
.filter(Boolean),
|
|
485
|
+
),
|
|
486
|
+
links: (html.match(/<a\b[^>]*\bhref\s*=/gi) || []).length,
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// New @types and words are compared, not just counts, so swapped text or schema is caught. The local lines of 100 new
|
|
491
|
+
// words and a third of the page keep a consent banner in a fresh profile (a few dozen words) from counting.
|
|
492
|
+
export function compareRendered(rawHtml, renderedHtml) {
|
|
493
|
+
const a = read(rawHtml),
|
|
494
|
+
b = read(renderedHtml),
|
|
495
|
+
out = [];
|
|
496
|
+
for (const field of ["title", "canonical", "robots", "description", "h1"]) {
|
|
497
|
+
const same =
|
|
498
|
+
field === "canonical" && a.canonical && b.canonical
|
|
499
|
+
? sameUrl(a.canonical, b.canonical)
|
|
500
|
+
: (a[field] ?? "") === (b[field] ?? "");
|
|
501
|
+
if (!same) out.push({ field, raw: a[field], rendered: b[field] });
|
|
502
|
+
}
|
|
503
|
+
const types = b.types.filter(t => !a.types.includes(t)),
|
|
504
|
+
added = [...b.words].filter(w => !a.words.has(w));
|
|
505
|
+
if (types.length) out.push({ field: "jsonld-types", raw: a.types.join(", ") || null, rendered: types.join(", ") });
|
|
506
|
+
else if (b.jsonld > a.jsonld) out.push({ field: "jsonld-count", raw: a.jsonld, rendered: b.jsonld });
|
|
507
|
+
if (added.length >= 100 && added.length * 3 >= b.words.size)
|
|
508
|
+
out.push({
|
|
509
|
+
field: "words",
|
|
510
|
+
raw: `${a.words.size} words`,
|
|
511
|
+
rendered: `${added.length} words only after JavaScript, e.g. ${added.slice(0, 8).join(", ")}`,
|
|
512
|
+
});
|
|
513
|
+
// At least 10 more, since a consent banner in a fresh profile adds a few.
|
|
514
|
+
if (b.links > a.links * 1.5 && b.links - a.links >= 10)
|
|
515
|
+
out.push({ field: "link-count", raw: a.links, rendered: b.links });
|
|
516
|
+
return out;
|
|
517
|
+
}
|
|
518
|
+
// An H1 only JavaScript adds is render-adds-content's, with the JSON-LD, words and link count.
|
|
519
|
+
export const changesHead = x => ["canonical", "robots"].includes(x.field);
|
|
520
|
+
export const changesText = x => x.field === "title" || x.field === "description" || (x.field === "h1" && !!x.raw);
|
|
521
|
+
// A page the crawler already reported as client-rendered gets no render-adds-content, so it has one REND-01 finding.
|
|
522
|
+
// render-adds-text skips those pages too, as checkMore gets no raw word count for them.
|
|
523
|
+
export function renderFindings(url, rawHtml, renderedHtml, { add, clientRendered = false }) {
|
|
524
|
+
const d = compareRendered(rawHtml, renderedHtml),
|
|
525
|
+
say = x => `${x.field}: “${x.raw ?? "none"}” → “${x.rendered ?? "none"}”`;
|
|
526
|
+
const head = d.filter(changesHead),
|
|
527
|
+
text = d.filter(changesText),
|
|
528
|
+
body = d.filter(x => !head.includes(x) && !text.includes(x));
|
|
529
|
+
if (head.length) add("render-changes-head", url, head.map(say).join("; "));
|
|
530
|
+
if (text.length) add("render-changes-text", url, text.map(say).join("; "));
|
|
531
|
+
if (body.length && !clientRendered) add("render-adds-content", url, body.map(say).join("; "));
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// A login screen or paywall where the page should be, or null; never filled in or clicked through. A login needs the
|
|
535
|
+
// title or H1 to say so, so a login box in the header doesn't count. tp-modal and tp-backdrop are Piano's paywall.
|
|
536
|
+
// https://developers.google.com/search/docs/appearance/structured-data/paywalled-content
|
|
537
|
+
export function gateOf(html) {
|
|
538
|
+
const markup = html.replace(/<(script|style|template|noscript)\b[\s\S]*?<\/\1>|<!--[\s\S]*?-->/gi, " ");
|
|
539
|
+
const text = re => (markup.match(re)?.[1] || "").replace(/<[^>]+>/g, " ");
|
|
540
|
+
if (
|
|
541
|
+
/<input\b[^>]*\btype\s*=\s*["']?password\b/i.test(markup) &&
|
|
542
|
+
/\b(log ?in|sign ?in)\b/i.test(
|
|
543
|
+
`${text(/<title\b[^>]*>([\s\S]*?)<\/title>/i)} ${text(/<h1\b[^>]*>([\s\S]*?)<\/h1>/i)}`,
|
|
544
|
+
)
|
|
545
|
+
)
|
|
546
|
+
return "a login screen";
|
|
547
|
+
if (/"isAccessibleForFree"\s*:\s*(false|"false")/i.test(html))
|
|
548
|
+
return "a paywall (its structured data says isAccessibleForFree: false)";
|
|
549
|
+
if (/<[a-z][^>]*\s(?:id|class)\s*=\s*["'][^"']*\b(?:paywall|regwall|tp-modal|tp-backdrop)\b/i.test(markup))
|
|
550
|
+
return "a paywall";
|
|
551
|
+
return null;
|
|
552
|
+
}
|