@a.incantalupo/web-tools 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -2
- package/dist/audit/cli.d.ts +1 -0
- package/dist/audit/cli.js +238 -0
- package/dist/audit/crux.d.ts +6 -0
- package/dist/audit/crux.js +29 -0
- package/dist/audit/fetch.d.ts +17 -0
- package/dist/audit/fetch.js +51 -0
- package/dist/audit/findings.d.ts +9 -0
- package/dist/audit/findings.js +514 -0
- package/dist/audit/index.d.ts +6 -0
- package/dist/audit/index.js +3 -0
- package/dist/audit/lighthouse.d.ts +2 -0
- package/dist/audit/lighthouse.js +84 -0
- package/dist/audit/page.d.ts +10 -0
- package/dist/audit/page.js +156 -0
- package/dist/audit/profile.d.ts +11 -0
- package/dist/audit/profile.js +21 -0
- package/dist/audit/render.d.ts +8 -0
- package/dist/audit/render.js +63 -0
- package/dist/audit/rerender.d.ts +1 -0
- package/dist/audit/rerender.js +55 -0
- package/dist/audit/reviews.d.ts +2 -0
- package/dist/audit/reviews.js +36 -0
- package/dist/audit/scores.d.ts +3 -0
- package/dist/audit/scores.js +51 -0
- package/dist/audit/site.d.ts +19 -0
- package/dist/audit/site.js +78 -0
- package/dist/audit/summary.d.ts +2 -0
- package/dist/audit/summary.js +59 -0
- package/dist/audit/types.d.ts +132 -0
- package/dist/audit/types.js +1 -0
- package/dist/browser/cli.d.ts +1 -0
- package/dist/browser/cli.js +11 -0
- package/dist/browser/index.d.ts +15 -0
- package/dist/browser/index.js +59 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +34 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/refs/cli.d.ts +1 -0
- package/dist/refs/cli.js +193 -0
- package/dist/refs/glyphs.d.ts +1 -0
- package/dist/refs/glyphs.js +101 -0
- package/dist/refs/images.d.ts +1 -0
- package/dist/refs/images.js +163 -0
- package/dist/refs/snapshot.d.ts +1 -0
- package/dist/refs/snapshot.js +243 -0
- package/dist/refs/text.d.ts +1 -0
- package/dist/refs/text.js +728 -0
- package/package.json +29 -5
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export type Severity = "high" | "medium" | "low" | "pass" | "info";
|
|
2
|
+
export type Area = "performance" | "crawl" | "structured-data" | "content" | "local" | "conversion" | "hygiene" | "ai-visibility" | "reputation";
|
|
3
|
+
export type Finding = {
|
|
4
|
+
id: string;
|
|
5
|
+
area: Area;
|
|
6
|
+
severity: Severity;
|
|
7
|
+
title: string;
|
|
8
|
+
evidence: string;
|
|
9
|
+
pages?: string[];
|
|
10
|
+
};
|
|
11
|
+
export type PageData = {
|
|
12
|
+
url: string;
|
|
13
|
+
finalUrl: string;
|
|
14
|
+
status: number;
|
|
15
|
+
ttfbMs: number;
|
|
16
|
+
htmlBytes: number;
|
|
17
|
+
contentEncoding: string | null;
|
|
18
|
+
cacheControl: string | null;
|
|
19
|
+
title: string;
|
|
20
|
+
metaDescription: string;
|
|
21
|
+
h1Count: number;
|
|
22
|
+
canonical: string | null;
|
|
23
|
+
noindex: boolean;
|
|
24
|
+
lang: string | null;
|
|
25
|
+
jsonLdTypes: string[];
|
|
26
|
+
jsonLdErrors: number;
|
|
27
|
+
images: number;
|
|
28
|
+
imagesWithoutAlt: number;
|
|
29
|
+
legacyImageFormats: number;
|
|
30
|
+
scripts: number;
|
|
31
|
+
thirdPartyHosts: string[];
|
|
32
|
+
telLinks: number;
|
|
33
|
+
whatsappLinks: number;
|
|
34
|
+
mailtoLinks: number;
|
|
35
|
+
forms: number;
|
|
36
|
+
wordCount: number;
|
|
37
|
+
hasPrice: boolean;
|
|
38
|
+
mapsLinks: number;
|
|
39
|
+
insecureResources: number;
|
|
40
|
+
internalLinks: string[];
|
|
41
|
+
shareLinks: string[];
|
|
42
|
+
/** <meta name="generator">, e.g. "Joomla! - Open Source Content Management". */
|
|
43
|
+
generator: string | null;
|
|
44
|
+
/** CMS, page builders and dealer platforms recognised in the HTML. */
|
|
45
|
+
builtWith: string[];
|
|
46
|
+
/** "Realizzato da …" in the footer: the agency we'd be replacing. */
|
|
47
|
+
credits: string | null;
|
|
48
|
+
/** Opened in a real browser too (--render): contact fields come from the rendered page. */
|
|
49
|
+
rendered?: boolean;
|
|
50
|
+
/** What only appears after JavaScript runs (tel, whatsapp, forms, maps, price). */
|
|
51
|
+
jsOnly?: string[];
|
|
52
|
+
};
|
|
53
|
+
export type LighthouseRun = {
|
|
54
|
+
url: string;
|
|
55
|
+
formFactor: "mobile" | "desktop";
|
|
56
|
+
scores: Record<string, number | null>;
|
|
57
|
+
metrics: Record<string, number | null>;
|
|
58
|
+
totalBytes: number | null;
|
|
59
|
+
scriptBytes: number | null;
|
|
60
|
+
imageBytes: number | null;
|
|
61
|
+
thirdPartyBytes: number | null;
|
|
62
|
+
error: string | null;
|
|
63
|
+
reportFile: string;
|
|
64
|
+
/** What the page looked like at the end of the load (Lighthouse's final screenshot), a JPEG next to the report. */
|
|
65
|
+
screenshot: string | null;
|
|
66
|
+
};
|
|
67
|
+
/** Real visitors' numbers from the Chrome UX Report (75th percentile, last 28 days), phones. */
|
|
68
|
+
export type Crux = {
|
|
69
|
+
scope: "url" | "origin";
|
|
70
|
+
key: string;
|
|
71
|
+
formFactor: "PHONE" | "DESKTOP";
|
|
72
|
+
period: string;
|
|
73
|
+
lcpMs: number | null;
|
|
74
|
+
inpMs: number | null;
|
|
75
|
+
cls: number | null;
|
|
76
|
+
ttfbMs: number | null;
|
|
77
|
+
/** Share of visits where the main content showed within 2.5 s. */
|
|
78
|
+
lcpGood: number | null;
|
|
79
|
+
};
|
|
80
|
+
export type Reviews = {
|
|
81
|
+
name: string;
|
|
82
|
+
rating: number;
|
|
83
|
+
count: number;
|
|
84
|
+
scrapedAt: string;
|
|
85
|
+
/** Reviews read from the listing (Google may show fewer than the count). */
|
|
86
|
+
read: number;
|
|
87
|
+
last12Months: number;
|
|
88
|
+
last3Months: number;
|
|
89
|
+
withText: number;
|
|
90
|
+
/** Reviews the owner answered; null when the file doesn't say. */
|
|
91
|
+
replied: number | null;
|
|
92
|
+
/** 1-3 star reviews in the last 12 months, and how many of them got an answer. */
|
|
93
|
+
recentLow: number;
|
|
94
|
+
recentLowReplied: number | null;
|
|
95
|
+
};
|
|
96
|
+
export type Scores = {
|
|
97
|
+
overall: number;
|
|
98
|
+
areas: Partial<Record<Area, number>>;
|
|
99
|
+
};
|
|
100
|
+
export type EvalResult = {
|
|
101
|
+
target: string;
|
|
102
|
+
/** A preview host that blocks indexing on purpose: blocks are reported as info. */
|
|
103
|
+
preview?: boolean;
|
|
104
|
+
/** Pages were also opened in a real browser (--render). */
|
|
105
|
+
rendered?: boolean;
|
|
106
|
+
startedAt: string;
|
|
107
|
+
finishedAt: string;
|
|
108
|
+
pagesAnalyzed: number;
|
|
109
|
+
site: {
|
|
110
|
+
https: boolean;
|
|
111
|
+
robotsTxt: string | null;
|
|
112
|
+
sitemaps: Array<{
|
|
113
|
+
url: string;
|
|
114
|
+
urls: number;
|
|
115
|
+
newestLastmod: string | null;
|
|
116
|
+
}>;
|
|
117
|
+
llmsTxt: boolean;
|
|
118
|
+
aiBots: Record<string, "allowed" | "blocked">;
|
|
119
|
+
};
|
|
120
|
+
pages: PageData[];
|
|
121
|
+
lighthouse: LighthouseRun[];
|
|
122
|
+
/** Real-visitor data for the home page (or the whole site); null without an API key or when Google has too few visits. */
|
|
123
|
+
crux: {
|
|
124
|
+
home: Crux | null;
|
|
125
|
+
origin: Crux | null;
|
|
126
|
+
error: string | null;
|
|
127
|
+
} | null;
|
|
128
|
+
/** The business's Google listing first, then competitors (JSON files from a reviews scraper). */
|
|
129
|
+
reviews: Reviews[];
|
|
130
|
+
findings: Finding[];
|
|
131
|
+
scores: Scores;
|
|
132
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// stack-tools browser [url]: opens "my Chrome" (see index.ts), or says it's already open.
|
|
2
|
+
import { PROFILE, PORT, isOpen, openMyChrome } from "./index.js";
|
|
3
|
+
const url = process.argv[2];
|
|
4
|
+
if (await isOpen()) {
|
|
5
|
+
console.log(`Already open (port ${PORT}).${url ? " Open the URL in it yourself." : ""}`);
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
await openMyChrome(url);
|
|
9
|
+
console.log(`Opened. Profile: ${PROFILE}, port ${PORT} (127.0.0.1 only).`);
|
|
10
|
+
}
|
|
11
|
+
console.log("Sign in by hand where a tool needs it (Google for reviews), keep the window open, then run the tool with --mine.");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Browser, type BrowserContext } from "playwright-core";
|
|
2
|
+
export declare const PROFILE: string;
|
|
3
|
+
export declare const PORT: number;
|
|
4
|
+
export declare const executablePath: string;
|
|
5
|
+
export declare function isOpen(): Promise<boolean>;
|
|
6
|
+
/** Starts the window and returns once it accepts connections. */
|
|
7
|
+
export declare function openMyChrome(url?: string): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Attaches to the open window. Use `context.newPage()` for work and close only
|
|
10
|
+
* your own pages; `browser.close()` just disconnects and leaves the window open.
|
|
11
|
+
*/
|
|
12
|
+
export declare function connectMyChrome(): Promise<{
|
|
13
|
+
browser: Browser;
|
|
14
|
+
context: BrowserContext;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// "My Chrome": a normal Chromium window with its own profile that Alessandro opens
|
|
2
|
+
// (`stack-tools browser`), signs in to by hand and keeps open. Our tools then work in a new
|
|
3
|
+
// tab of it (`--mine`) instead of launching their own automated browser.
|
|
4
|
+
//
|
|
5
|
+
// It is started as a plain program, not by Playwright, so it has no automation
|
|
6
|
+
// flags and no "controlled by automated test software" bar; the tools attach over
|
|
7
|
+
// the DevTools protocol on 127.0.0.1 only. Nothing here disguises the browser:
|
|
8
|
+
// a site that still refuses it is respected.
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { chromium } from "playwright-core";
|
|
13
|
+
// The profile keeps your sign-ins.
|
|
14
|
+
export const PROFILE = process.env.MY_CHROME_PROFILE ?? join(homedir(), ".cache/stack-tools/chrome-profile");
|
|
15
|
+
export const PORT = Number(process.env.MY_CHROME_PORT ?? 9222);
|
|
16
|
+
export const executablePath = process.env.CHROME_PATH ??
|
|
17
|
+
join(homedir(), ".cache/ms-playwright/chromium-1194/chrome-linux/chrome");
|
|
18
|
+
const endpoint = `http://127.0.0.1:${PORT}`;
|
|
19
|
+
export async function isOpen() {
|
|
20
|
+
try {
|
|
21
|
+
const res = await fetch(`${endpoint}/json/version`, {
|
|
22
|
+
signal: AbortSignal.timeout(1500),
|
|
23
|
+
});
|
|
24
|
+
return res.ok;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Starts the window and returns once it accepts connections. */
|
|
31
|
+
export async function openMyChrome(url) {
|
|
32
|
+
const child = spawn(executablePath, [
|
|
33
|
+
`--user-data-dir=${PROFILE}`,
|
|
34
|
+
`--remote-debugging-port=${PORT}`,
|
|
35
|
+
"--remote-debugging-address=127.0.0.1",
|
|
36
|
+
"--no-first-run",
|
|
37
|
+
"--no-default-browser-check",
|
|
38
|
+
"--lang=it-IT",
|
|
39
|
+
...(url ? [url] : []),
|
|
40
|
+
], { detached: true, stdio: "ignore" });
|
|
41
|
+
child.unref();
|
|
42
|
+
for (let i = 0; i < 40; i++) {
|
|
43
|
+
if (await isOpen())
|
|
44
|
+
return;
|
|
45
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
46
|
+
}
|
|
47
|
+
throw new Error(`Chrome didn't open on port ${PORT} (${executablePath})`);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Attaches to the open window. Use `context.newPage()` for work and close only
|
|
51
|
+
* your own pages; `browser.close()` just disconnects and leaves the window open.
|
|
52
|
+
*/
|
|
53
|
+
export async function connectMyChrome() {
|
|
54
|
+
if (!(await isOpen()))
|
|
55
|
+
throw new Error("Your Chrome isn't open: run `stack-tools browser`, sign in where needed, keep the window open, then run this again.");
|
|
56
|
+
const browser = await chromium.connectOverCDP(endpoint);
|
|
57
|
+
const context = browser.contexts()[0] ?? (await browser.newContext());
|
|
58
|
+
return { browser, context };
|
|
59
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
3
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
4
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
5
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return path;
|
|
9
|
+
};
|
|
10
|
+
// stack-tools <command> [args]: the web stack's checks and captures, for any site.
|
|
11
|
+
// Each command is a module that reads its own arguments from process.argv.
|
|
12
|
+
const commands = {
|
|
13
|
+
browser: { file: "./browser/cli.js", about: "open your own Chromium window (sign in by hand; tools use it with --mine)" },
|
|
14
|
+
refs: { file: "./refs/cli.js", about: "desktop + mobile screenshots of sites: <url...> [--full] [--mine] [--out dir | --out-root dir]" },
|
|
15
|
+
snap: { file: "./refs/snapshot.js", keepName: true, about: "computed styles + screenshots of pages: <dir> <url...>" },
|
|
16
|
+
diff: { file: "./refs/snapshot.js", keepName: true, about: "what changed between two snaps: <before> <after>" },
|
|
17
|
+
text: { file: "./refs/text.js", about: "readability, text size, contrast, fields, tap targets, text at 200%: <url...> [--verbose] [--login email]" },
|
|
18
|
+
glyphs: { file: "./refs/glyphs.js", about: "characters the page fonts do not cover: <url...>" },
|
|
19
|
+
images: { file: "./refs/images.js", about: "which image file each slot downloads, weights, lazy LCP: <url...>" },
|
|
20
|
+
audit: { file: "./audit/cli.js", about: "audit a site (SEO, AI visibility, speed, contacts): <url> [--profile file.ts] [--render] [--teaser]" },
|
|
21
|
+
"audit-rerender": { file: "./audit/rerender.js", about: "rebuild an audit report from its findings.json: <dir> [--profile file.ts] [--teaser]" }
|
|
22
|
+
};
|
|
23
|
+
const name = process.argv[2];
|
|
24
|
+
const command = name ? commands[name] : undefined;
|
|
25
|
+
if (!command) {
|
|
26
|
+
console.log("Usage: stack-tools <command> [args]\n");
|
|
27
|
+
for (const [n, c] of Object.entries(commands))
|
|
28
|
+
console.log(` ${n.padEnd(15)} ${c.about}`);
|
|
29
|
+
process.exit(name && name !== "help" && name !== "--help" ? 1 : 0);
|
|
30
|
+
}
|
|
31
|
+
if (!command.keepName)
|
|
32
|
+
process.argv.splice(2, 1);
|
|
33
|
+
await import(__rewriteRelativeImportExtension(new URL(command.file, import.meta.url).href));
|
|
34
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// What projects import from the tools: the own-browser connection, the polite fetch helpers,
|
|
2
|
+
// and the audit's types and functions for writing an audit profile.
|
|
3
|
+
export * from "./browser/index.js";
|
|
4
|
+
export { extraHeaders, mapLimit, timedFetch, tryFetch } from "./audit/fetch.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/refs/cli.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// Screenshots of reference sites (and of our own previews) for design exploration:
|
|
2
|
+
// desktop and mobile, above the fold and full page, cookie banner dismissed.
|
|
3
|
+
//
|
|
4
|
+
// Usage: stack-tools refs <url...> [--out dir] [--full] [--mine]
|
|
5
|
+
//
|
|
6
|
+
// Some sites refuse automated browsers on purpose (Tesla: Akamai 403, Revolut:
|
|
7
|
+
// Cloudflare challenge). We report that and move on; we don't try to get past
|
|
8
|
+
// it. With --mine the shots are taken in a new tab of Alessandro's own Chrome
|
|
9
|
+
// (`stack-tools browser`), as he would see the page; a site that still
|
|
10
|
+
// refuses is captured by hand.
|
|
11
|
+
import { connectMyChrome } from "../browser/index.js";
|
|
12
|
+
import { chromium } from "playwright-core";
|
|
13
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { join, resolve } from "node:path";
|
|
16
|
+
import { parseArgs } from "node:util";
|
|
17
|
+
const { values, positionals: urls } = parseArgs({
|
|
18
|
+
allowPositionals: true,
|
|
19
|
+
options: {
|
|
20
|
+
out: { type: "string" },
|
|
21
|
+
"out-root": { type: "string" },
|
|
22
|
+
full: { type: "boolean", default: false },
|
|
23
|
+
mine: { type: "boolean", default: false },
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (!urls.length) {
|
|
27
|
+
console.error("Usage: stack-tools refs <url...> [--out dir] [--full] [--mine]");
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
const executablePath = process.env.CHROME_PATH ??
|
|
31
|
+
join(homedir(), ".cache/ms-playwright/chromium-1194/chrome-linux/chrome");
|
|
32
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
33
|
+
// Relative to where you ran the command: --out <dir>, or <out-root>/<date> (default ./design-refs).
|
|
34
|
+
const cwd = process.env.INIT_CWD ?? process.cwd();
|
|
35
|
+
const root = values.out
|
|
36
|
+
? resolve(cwd, values.out)
|
|
37
|
+
: resolve(cwd, values["out-root"] ?? "design-refs", date);
|
|
38
|
+
const devices = {
|
|
39
|
+
desktop: { viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1 },
|
|
40
|
+
mobile: {
|
|
41
|
+
viewport: { width: 390, height: 844 },
|
|
42
|
+
deviceScaleFactor: 2,
|
|
43
|
+
isMobile: true,
|
|
44
|
+
hasTouch: true,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
// Cookie/consent buttons, most specific first. Rejecting is enough to see the page.
|
|
48
|
+
const CONSENT = [
|
|
49
|
+
"#onetrust-reject-all-handler",
|
|
50
|
+
"#onetrust-accept-btn-handler",
|
|
51
|
+
"#didomi-notice-disagree-button",
|
|
52
|
+
"#didomi-notice-agree-button",
|
|
53
|
+
"[data-testid='uc-deny-all-button']",
|
|
54
|
+
"[data-testid='uc-accept-all-button']",
|
|
55
|
+
"#CybotCookiebotDialogBodyButtonDecline",
|
|
56
|
+
"#truste-consent-required",
|
|
57
|
+
];
|
|
58
|
+
const CONSENT_TEXT = /^(rifiuta( tutto| tutti)?|accetta( tutto| tutti)?|consenti tutti|solo necessari|reject all|accept all|accept|agree|ok|got it|ho capito)$/i;
|
|
59
|
+
// What a bot wall looks like: status or page title.
|
|
60
|
+
const debug = (...a) => process.env.DEBUG && console.log(" ·", ...a);
|
|
61
|
+
const BLOCKED_TITLE = /access denied|just a moment|attention required|security check|are you a robot|captcha/i;
|
|
62
|
+
// Never wait long on a banner: a frame that never answers (seen with an embedded map
|
|
63
|
+
// in Alessandro's window) must not hang the run.
|
|
64
|
+
const within = (p, ms, fallback) => Promise.race([p, new Promise((r) => setTimeout(() => r(fallback), ms))]);
|
|
65
|
+
async function dismissConsent(page) {
|
|
66
|
+
return within(findAndClickConsent(page), 8000, null);
|
|
67
|
+
}
|
|
68
|
+
async function findAndClickConsent(page) {
|
|
69
|
+
for (const frame of page.frames()) {
|
|
70
|
+
for (const sel of CONSENT) {
|
|
71
|
+
const el = frame.locator(sel).first();
|
|
72
|
+
if (await el.isVisible().catch(() => false)) {
|
|
73
|
+
await el.click({ timeout: 3000 }).catch(() => { });
|
|
74
|
+
return sel;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const byText = frame.getByRole("button", { name: CONSENT_TEXT }).first();
|
|
78
|
+
if (await byText.isVisible().catch(() => false)) {
|
|
79
|
+
const name = (await byText.textContent())?.trim() ?? "button";
|
|
80
|
+
await byText.click({ timeout: 3000 }).catch(() => { });
|
|
81
|
+
return `"${name}"`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
// Scroll through once so lazy images and scroll animations load before the full shot.
|
|
87
|
+
// The waits run here, not in the page: Chrome throttles timers in a tab that isn't in
|
|
88
|
+
// front, which made a page-side loop crawl in Alessandro's window (--mine).
|
|
89
|
+
async function scrollThrough(page) {
|
|
90
|
+
const { height, step } = await page.evaluate(() => ({
|
|
91
|
+
height: Math.min(document.body.scrollHeight, 20_000),
|
|
92
|
+
step: Math.round(window.innerHeight * 0.8),
|
|
93
|
+
}));
|
|
94
|
+
for (let y = 0; y < height; y += step) {
|
|
95
|
+
await page.evaluate((top) => window.scrollTo(0, top), y);
|
|
96
|
+
await page.waitForTimeout(150);
|
|
97
|
+
}
|
|
98
|
+
await page.evaluate(() => window.scrollTo(0, 0));
|
|
99
|
+
await page.waitForTimeout(800);
|
|
100
|
+
}
|
|
101
|
+
// Our own headless browser, or a tab in Alessandro's Chrome (--mine). In his Chrome
|
|
102
|
+
// the mobile shot is the same tab resized to 390 px: no device or user-agent change.
|
|
103
|
+
const mine = values.mine ? await connectMyChrome() : null;
|
|
104
|
+
const browser = mine?.browser ?? (await chromium.launch({ executablePath }));
|
|
105
|
+
async function openPage(options) {
|
|
106
|
+
if (mine) {
|
|
107
|
+
const page = await mine.context.newPage();
|
|
108
|
+
await page.bringToFront();
|
|
109
|
+
await page.setViewportSize(options.viewport);
|
|
110
|
+
return { page, done: () => page.close() };
|
|
111
|
+
}
|
|
112
|
+
const ctx = await browser.newContext({
|
|
113
|
+
...options,
|
|
114
|
+
locale: "it-IT",
|
|
115
|
+
});
|
|
116
|
+
return { page: await ctx.newPage(), done: () => ctx.close() };
|
|
117
|
+
}
|
|
118
|
+
const index = [`# Reference screenshots ${date}`, ""];
|
|
119
|
+
let blocked = 0;
|
|
120
|
+
try {
|
|
121
|
+
for (const url of urls) {
|
|
122
|
+
const host = new URL(url).hostname.replace(/^www\./, "");
|
|
123
|
+
const { pathname, search } = new URL(url);
|
|
124
|
+
const path = (pathname.replace(/\/+$/, "") + search).replace(/\W+/g, "-");
|
|
125
|
+
const name = `${host}${path}`;
|
|
126
|
+
const dir = join(root, name);
|
|
127
|
+
index.push(`## ${url}`, "");
|
|
128
|
+
for (const [device, options] of Object.entries(devices)) {
|
|
129
|
+
const { page, done } = await openPage(options);
|
|
130
|
+
try {
|
|
131
|
+
debug(device, "goto");
|
|
132
|
+
const res = await page.goto(url, { waitUntil: "load", timeout: 45_000 });
|
|
133
|
+
debug(device, "loaded");
|
|
134
|
+
await page.waitForTimeout(1500);
|
|
135
|
+
const status = res?.status() ?? 0;
|
|
136
|
+
const title = await page.title();
|
|
137
|
+
if (status === 404) {
|
|
138
|
+
const line = `not found (404): check the URL`;
|
|
139
|
+
console.log(`${name} ${device}: ${line}`);
|
|
140
|
+
index.push(`- ${device}: ${line}`);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (status >= 400 || BLOCKED_TITLE.test(title)) {
|
|
144
|
+
blocked++;
|
|
145
|
+
const line = `blocked (${status} "${title}"): the site refuses automated browsers. Capture it by hand.`;
|
|
146
|
+
console.log(`${name} ${device}: ${line}`);
|
|
147
|
+
index.push(`- ${device}: ${line}`);
|
|
148
|
+
break; // same answer on mobile
|
|
149
|
+
}
|
|
150
|
+
debug(device, "consent");
|
|
151
|
+
const consent = await dismissConsent(page);
|
|
152
|
+
debug(device, "shot");
|
|
153
|
+
if (consent)
|
|
154
|
+
await page.waitForTimeout(800);
|
|
155
|
+
await mkdir(dir, { recursive: true });
|
|
156
|
+
const fold = join(dir, `${device}.jpg`);
|
|
157
|
+
await page.screenshot({ path: fold, type: "jpeg", quality: 75, timeout: 60_000 });
|
|
158
|
+
const shots = [`${device}.jpg`];
|
|
159
|
+
if (values.full) {
|
|
160
|
+
debug(device, "scroll");
|
|
161
|
+
await scrollThrough(page);
|
|
162
|
+
debug(device, "full shot");
|
|
163
|
+
await page.screenshot({
|
|
164
|
+
path: join(dir, `${device}-full.jpg`),
|
|
165
|
+
type: "jpeg",
|
|
166
|
+
quality: 70,
|
|
167
|
+
fullPage: true,
|
|
168
|
+
timeout: 90_000,
|
|
169
|
+
});
|
|
170
|
+
shots.push(`${device}-full.jpg`);
|
|
171
|
+
}
|
|
172
|
+
const note = consent ? `, consent: ${consent}` : "";
|
|
173
|
+
console.log(`${name} ${device}: ${shots.join(", ")}${note}`);
|
|
174
|
+
index.push(`- ${device}: ${shots.map((s) => `[${s}](${name}/${s})`).join(", ")}${note}`);
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
const msg = e.message.split("\n")[0];
|
|
178
|
+
console.log(`${name} ${device}: error ${msg}`);
|
|
179
|
+
index.push(`- ${device}: error ${msg}`);
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
await done();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
index.push("");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
await browser.close();
|
|
190
|
+
}
|
|
191
|
+
await mkdir(root, { recursive: true });
|
|
192
|
+
await writeFile(join(root, "index.md"), index.join("\n"));
|
|
193
|
+
console.log(`-> ${root}${blocked ? ` (${blocked} blocked)` : ""}`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Finds characters our web fonts don't cover, the way the browser decides it: for every
|
|
2
|
+
// text shown on the pages, the first family of the element's font-family stack must have
|
|
3
|
+
// a loaded @font-face whose unicode-range includes the character. Otherwise the browser
|
|
4
|
+
// draws it from a system font, with other metrics and baseline (the "→" that sat low on
|
|
5
|
+
// some phones). Exit code 1 when something is missing, so it can gate CI.
|
|
6
|
+
//
|
|
7
|
+
// Usage: stack-tools glyphs <url...> (e.g. the home, catalog, a vehicle page, chi-siamo)
|
|
8
|
+
import { chromium } from "playwright-core";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
const urls = process.argv.slice(2);
|
|
12
|
+
if (!urls.length) {
|
|
13
|
+
console.error("Usage: stack-tools glyphs <url...>");
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
const executablePath = process.env.CHROME_PATH ??
|
|
17
|
+
join(homedir(), ".cache/ms-playwright/chromium-1194/chrome-linux/chrome");
|
|
18
|
+
const browser = await chromium.launch({ executablePath });
|
|
19
|
+
const all = new Map();
|
|
20
|
+
try {
|
|
21
|
+
for (const url of urls) {
|
|
22
|
+
for (const width of [390, 1440]) {
|
|
23
|
+
const page = await browser.newPage({ viewport: { width, height: 900 } });
|
|
24
|
+
await page.goto(url, { waitUntil: "networkidle" });
|
|
25
|
+
await page.evaluate(() => document.fonts.ready);
|
|
26
|
+
const missing = await page.evaluate(() => {
|
|
27
|
+
// unicode-range of every @font-face, by family name.
|
|
28
|
+
const ranges = new Map();
|
|
29
|
+
for (const face of document.fonts) {
|
|
30
|
+
const family = face.family.replace(/["']/g, "");
|
|
31
|
+
const list = ranges.get(family) ?? [];
|
|
32
|
+
for (const part of face.unicodeRange.split(",")) {
|
|
33
|
+
const m = part.trim().match(/^U\+([0-9A-F?]+)(?:-([0-9A-F]+))?$/i);
|
|
34
|
+
if (!m)
|
|
35
|
+
continue;
|
|
36
|
+
const lo = parseInt(m[1].replace(/\?/g, "0"), 16);
|
|
37
|
+
const hi = m[2] ? parseInt(m[2], 16) : parseInt(m[1].replace(/\?/g, "F"), 16);
|
|
38
|
+
list.push([lo, hi]);
|
|
39
|
+
}
|
|
40
|
+
ranges.set(family, list);
|
|
41
|
+
}
|
|
42
|
+
const covered = (family, cp) => (ranges.get(family) ?? []).some(([lo, hi]) => cp >= lo && cp <= hi);
|
|
43
|
+
const out = [];
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
|
46
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
47
|
+
const el = n.parentElement;
|
|
48
|
+
if (!el || !n.textContent?.trim())
|
|
49
|
+
continue;
|
|
50
|
+
const style = getComputedStyle(el);
|
|
51
|
+
if (style.display === "none" || style.visibility === "hidden")
|
|
52
|
+
continue;
|
|
53
|
+
if (el.closest("script, style, noscript, svg"))
|
|
54
|
+
continue;
|
|
55
|
+
const family = style.fontFamily.split(",")[0].trim().replace(/["']/g, "");
|
|
56
|
+
if (!ranges.has(family))
|
|
57
|
+
continue; // a system font on purpose (e.g. form controls)
|
|
58
|
+
for (const char of n.textContent) {
|
|
59
|
+
const cp = char.codePointAt(0);
|
|
60
|
+
// Emoji (and their joiners and variation selectors) come from the device's
|
|
61
|
+
// emoji font by design, in every font stack.
|
|
62
|
+
if (/\p{Extended_Pictographic}|\u200d|\ufe0f/u.test(char))
|
|
63
|
+
continue;
|
|
64
|
+
if (cp <= 0x20 || cp === 0xa0 || covered(family, cp))
|
|
65
|
+
continue;
|
|
66
|
+
const key = `${family} ${cp}`;
|
|
67
|
+
if (seen.has(key))
|
|
68
|
+
continue;
|
|
69
|
+
seen.add(key);
|
|
70
|
+
out.push({
|
|
71
|
+
char,
|
|
72
|
+
code: `U+${cp.toString(16).toUpperCase().padStart(4, "0")}`,
|
|
73
|
+
family,
|
|
74
|
+
sample: n.textContent.trim().slice(0, 40),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
});
|
|
80
|
+
for (const m of missing) {
|
|
81
|
+
const key = `${m.family} ${m.code}`;
|
|
82
|
+
const entry = all.get(key) ?? { ...m, pages: new Set() };
|
|
83
|
+
entry.pages.add(url);
|
|
84
|
+
all.set(key, entry);
|
|
85
|
+
}
|
|
86
|
+
await page.close();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
await browser.close();
|
|
92
|
+
}
|
|
93
|
+
if (!all.size) {
|
|
94
|
+
console.log(`All characters covered by our fonts on ${urls.length} page(s).`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
console.log(`${all.size} character(s) drawn from a system font:`);
|
|
98
|
+
for (const m of all.values())
|
|
99
|
+
console.log(` ${m.char} ${m.code} in ${m.family} e.g. "${m.sample}" (${[...m.pages].length} page(s))`);
|
|
100
|
+
process.exitCode = 1;
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|