@jini-ai/diagnostics 0.1.1 → 0.4.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/CHANGELOG.md +79 -0
- package/README.md +114 -0
- package/dist/agent-logs.d.ts +9 -4
- package/dist/agent-logs.js +14 -15
- package/dist/domain-dns/index.d.ts +136 -0
- package/dist/domain-dns/index.js +117 -0
- package/dist/index.d.ts +41 -3
- package/dist/index.js +38 -1
- package/dist/manifest.d.ts +22 -16
- package/dist/manifest.js +9 -19
- package/dist/node-ports.d.ts +6 -0
- package/dist/node-ports.js +57 -0
- package/dist/observability/config.d.ts +24 -0
- package/dist/observability/config.js +21 -0
- package/dist/observability/hooks.d.ts +18 -0
- package/dist/observability/hooks.js +24 -0
- package/dist/observability/index.d.ts +14 -0
- package/dist/observability/index.js +14 -0
- package/dist/observability/noop.d.ts +4 -0
- package/dist/observability/noop.js +6 -0
- package/dist/observability/otel.d.ts +14 -0
- package/dist/observability/otel.js +28 -0
- package/dist/observability/ports.d.ts +79 -0
- package/dist/observability/ports.js +2 -0
- package/dist/ports.d.ts +45 -0
- package/dist/ports.js +2 -0
- package/dist/redaction/secret-patterns.d.ts +8 -0
- package/dist/redaction/secret-patterns.js +18 -0
- package/dist/redaction/secrets-only.d.ts +44 -0
- package/dist/redaction/secrets-only.js +179 -0
- package/dist/redaction.d.ts +12 -3
- package/dist/redaction.js +18 -8
- package/dist/sources.d.ts +22 -12
- package/dist/sources.js +22 -42
- package/dist/types.d.ts +24 -0
- package/dist/types.js +2 -0
- package/dist/web-evidence/browser-port.d.ts +166 -0
- package/dist/web-evidence/browser-port.js +6 -0
- package/dist/web-evidence/collect-page-evidence.d.ts +160 -0
- package/dist/web-evidence/collect-page-evidence.js +215 -0
- package/dist/web-evidence/index.d.ts +5 -0
- package/dist/web-evidence/index.js +5 -0
- package/dist/web-evidence/page-structure-script.d.ts +53 -0
- package/dist/web-evidence/page-structure-script.js +338 -0
- package/dist/web-evidence/page-work-budget.d.ts +27 -0
- package/dist/web-evidence/page-work-budget.js +53 -0
- package/dist/web-evidence/playwright-browser.d.ts +131 -0
- package/dist/web-evidence/playwright-browser.js +349 -0
- package/dist/web-evidence/same-origin.d.ts +126 -0
- package/dist/web-evidence/same-origin.js +141 -0
- package/dist/zip.d.ts +8 -3
- package/dist/zip.js +23 -16
- package/package.json +46 -5
- package/dist/agent-logs.d.ts.map +0 -1
- package/dist/agent-logs.js.map +0 -1
- package/dist/contract.d.ts.map +0 -1
- package/dist/contract.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/manifest.d.ts.map +0 -1
- package/dist/manifest.js.map +0 -1
- package/dist/redaction.d.ts.map +0 -1
- package/dist/redaction.js.map +0 -1
- package/dist/sources.d.ts.map +0 -1
- package/dist/sources.js.map +0 -1
- package/dist/zip.d.ts.map +0 -1
- package/dist/zip.js.map +0 -1
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walks the rendered document and returns the structural evidence the compliance skill cites.
|
|
3
|
+
*
|
|
4
|
+
* Runs in the browser. See this file's header for the constraints that implies.
|
|
5
|
+
*
|
|
6
|
+
* @param limits - Per-category caps, passed in rather than hardcoded so the collector's single
|
|
7
|
+
* `SITE_EVIDENCE_LIMITS` constant is the only place any bound is defined.
|
|
8
|
+
* @complexity O(n) in rendered element count, with every output list capped by `limits`.
|
|
9
|
+
*/
|
|
10
|
+
export function collectPageStructure(limits) {
|
|
11
|
+
const truncated = [];
|
|
12
|
+
/** Whether `current` should end the selector walk, and if so, the segment to use: `html`/`body`
|
|
13
|
+
* by tag, or any ancestor's own `id`. Nested (not module-scope) alongside every other helper here
|
|
14
|
+
* — see this file's header for why that is not optional. */
|
|
15
|
+
function terminalSegment(current) {
|
|
16
|
+
const tag = current.tagName.toLowerCase();
|
|
17
|
+
if (tag === "html" || tag === "body")
|
|
18
|
+
return tag;
|
|
19
|
+
if (current.id)
|
|
20
|
+
return `#${CSS.escape(current.id)}`;
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/** The `tag` or `tag:nth-of-type(n)` segment for `current` among its siblings under `parent`. */
|
|
24
|
+
function siblingSegment(current, parent) {
|
|
25
|
+
const tag = current.tagName.toLowerCase();
|
|
26
|
+
const siblings = Array.from(parent.children).filter((child) => child.tagName === current.tagName);
|
|
27
|
+
return siblings.length > 1 ? `${tag}:nth-of-type(${siblings.indexOf(current) + 1})` : tag;
|
|
28
|
+
}
|
|
29
|
+
/** A short, re-checkable CSS path for one element. Prefers an `id` (stable and readable), then a
|
|
30
|
+
* bounded `nth-of-type` chain. The path is a CITATION — a human must be able to paste it into
|
|
31
|
+
* devtools and land on the same element — so readability beats theoretical uniqueness. */
|
|
32
|
+
function selectorFor(element) {
|
|
33
|
+
if (element.id)
|
|
34
|
+
return `#${CSS.escape(element.id)}`;
|
|
35
|
+
const parts = [];
|
|
36
|
+
let current = element;
|
|
37
|
+
let depth = 0;
|
|
38
|
+
while (current && current.nodeType === 1 && depth < 5) {
|
|
39
|
+
const terminal = terminalSegment(current);
|
|
40
|
+
if (terminal !== null) {
|
|
41
|
+
parts.unshift(terminal);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
const parent = current.parentElement;
|
|
45
|
+
if (!parent) {
|
|
46
|
+
parts.unshift(current.tagName.toLowerCase());
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
parts.unshift(siblingSegment(current, parent));
|
|
50
|
+
current = parent;
|
|
51
|
+
depth += 1;
|
|
52
|
+
}
|
|
53
|
+
return parts.join(" > ");
|
|
54
|
+
}
|
|
55
|
+
function textOf(element, max) {
|
|
56
|
+
const raw = (element.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
57
|
+
return raw.length > max ? `${raw.slice(0, max)}…` : raw;
|
|
58
|
+
}
|
|
59
|
+
// Each of the following is one accessible-name STRATEGY, tried in the order the accessible-name
|
|
60
|
+
// computation spec prefers: `aria-label`, then `aria-labelledby`, then an explicit `<label for>`,
|
|
61
|
+
// then a wrapping `<label>`, then `title`. Each returns `null` to fall through to the next; the
|
|
62
|
+
// order and every reject/accept condition are unchanged from the pre-split function.
|
|
63
|
+
function accessibleNameFromAriaLabel(element) {
|
|
64
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
65
|
+
return ariaLabel?.trim() ? { name: ariaLabel.trim(), source: "aria-label" } : null;
|
|
66
|
+
}
|
|
67
|
+
function accessibleNameFromAriaLabelledBy(element) {
|
|
68
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
69
|
+
if (!labelledBy)
|
|
70
|
+
return null;
|
|
71
|
+
const names = labelledBy
|
|
72
|
+
.split(/\s+/)
|
|
73
|
+
.map((id) => document.getElementById(id))
|
|
74
|
+
.filter((node) => node !== null)
|
|
75
|
+
.map((node) => textOf(node, 120))
|
|
76
|
+
.filter((value) => value.length > 0);
|
|
77
|
+
return names.length > 0 ? { name: names.join(" "), source: "aria-labelledby" } : null;
|
|
78
|
+
}
|
|
79
|
+
function accessibleNameFromLabelFor(element) {
|
|
80
|
+
if (!element.id)
|
|
81
|
+
return null;
|
|
82
|
+
const forLabel = document.querySelector(`label[for="${CSS.escape(element.id)}"]`);
|
|
83
|
+
if (!forLabel)
|
|
84
|
+
return null;
|
|
85
|
+
const value = textOf(forLabel, 120);
|
|
86
|
+
return value ? { name: value, source: "label-for" } : null;
|
|
87
|
+
}
|
|
88
|
+
function accessibleNameFromLabelWrap(element) {
|
|
89
|
+
const wrapping = element.closest("label");
|
|
90
|
+
if (!wrapping)
|
|
91
|
+
return null;
|
|
92
|
+
const value = textOf(wrapping, 120);
|
|
93
|
+
return value ? { name: value, source: "label-wrap" } : null;
|
|
94
|
+
}
|
|
95
|
+
function accessibleNameFromTitle(element) {
|
|
96
|
+
const title = element.getAttribute("title");
|
|
97
|
+
return title?.trim() ? { name: title.trim(), source: "title" } : null;
|
|
98
|
+
}
|
|
99
|
+
function accessibleNameOf(element) {
|
|
100
|
+
const strategies = [
|
|
101
|
+
accessibleNameFromAriaLabel,
|
|
102
|
+
accessibleNameFromAriaLabelledBy,
|
|
103
|
+
accessibleNameFromLabelFor,
|
|
104
|
+
accessibleNameFromLabelWrap,
|
|
105
|
+
accessibleNameFromTitle,
|
|
106
|
+
];
|
|
107
|
+
for (const strategy of strategies) {
|
|
108
|
+
const found = strategy(element);
|
|
109
|
+
if (found)
|
|
110
|
+
return found;
|
|
111
|
+
}
|
|
112
|
+
return { name: null, source: "none" };
|
|
113
|
+
}
|
|
114
|
+
function capped(items, category) {
|
|
115
|
+
if (items.length > limits.maxNodesPerCategory) {
|
|
116
|
+
truncated.push(category);
|
|
117
|
+
return items.slice(0, limits.maxNodesPerCategory);
|
|
118
|
+
}
|
|
119
|
+
return items;
|
|
120
|
+
}
|
|
121
|
+
// --- landmarks -----------------------------------------------------------
|
|
122
|
+
const LANDMARK_SELECTOR = "header,nav,main,aside,footer,form,section,[role]";
|
|
123
|
+
const IMPLICIT_ROLES = {
|
|
124
|
+
HEADER: "banner",
|
|
125
|
+
NAV: "navigation",
|
|
126
|
+
MAIN: "main",
|
|
127
|
+
ASIDE: "complementary",
|
|
128
|
+
FOOTER: "contentinfo",
|
|
129
|
+
FORM: "form",
|
|
130
|
+
SECTION: "region",
|
|
131
|
+
};
|
|
132
|
+
function collectLandmarks() {
|
|
133
|
+
const out = [];
|
|
134
|
+
for (const element of Array.from(document.querySelectorAll(LANDMARK_SELECTOR))) {
|
|
135
|
+
const explicit = element.getAttribute("role");
|
|
136
|
+
const role = explicit?.trim() ? explicit.trim() : (IMPLICIT_ROLES[element.tagName] ?? "");
|
|
137
|
+
if (!role)
|
|
138
|
+
continue;
|
|
139
|
+
out.push({ role, selector: selectorFor(element), accessibleName: accessibleNameOf(element).name });
|
|
140
|
+
}
|
|
141
|
+
return capped(out, "landmarks");
|
|
142
|
+
}
|
|
143
|
+
// --- headings ------------------------------------------------------------
|
|
144
|
+
function collectHeadings() {
|
|
145
|
+
const out = [];
|
|
146
|
+
for (const element of Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6,[role='heading']"))) {
|
|
147
|
+
const tagLevel = /^H([1-6])$/.exec(element.tagName);
|
|
148
|
+
const ariaLevel = element.getAttribute("aria-level");
|
|
149
|
+
const level = tagLevel ? Number(tagLevel[1]) : ariaLevel ? Number(ariaLevel) : 0;
|
|
150
|
+
if (!Number.isFinite(level) || level === 0)
|
|
151
|
+
continue;
|
|
152
|
+
out.push({ level, selector: selectorFor(element), text: textOf(element, 160) });
|
|
153
|
+
}
|
|
154
|
+
return capped(out, "headings");
|
|
155
|
+
}
|
|
156
|
+
// --- images --------------------------------------------------------------
|
|
157
|
+
function collectImages() {
|
|
158
|
+
const out = [];
|
|
159
|
+
for (const element of Array.from(document.querySelectorAll("img"))) {
|
|
160
|
+
const image = element;
|
|
161
|
+
out.push({
|
|
162
|
+
selector: selectorFor(image),
|
|
163
|
+
// `getAttribute` rather than `.src`: the authored value is what a reviewer will look for in
|
|
164
|
+
// the template, and `.src` would resolve it against the document, changing the citation.
|
|
165
|
+
src: image.getAttribute("src") ?? "",
|
|
166
|
+
alt: image.hasAttribute("alt") ? image.getAttribute("alt") : null,
|
|
167
|
+
ariaHidden: image.getAttribute("aria-hidden") === "true",
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return capped(out, "images");
|
|
171
|
+
}
|
|
172
|
+
// --- form controls -------------------------------------------------------
|
|
173
|
+
function collectFormControls() {
|
|
174
|
+
const out = [];
|
|
175
|
+
for (const element of Array.from(document.querySelectorAll("input,select,textarea"))) {
|
|
176
|
+
const type = element.getAttribute("type");
|
|
177
|
+
// A hidden input has no rendered presence and no labelling obligation; including it would pad
|
|
178
|
+
// every finding list with noise a reviewer then has to filter out by hand.
|
|
179
|
+
if (element.tagName === "INPUT" && type === "hidden")
|
|
180
|
+
continue;
|
|
181
|
+
const { name, source } = accessibleNameOf(element);
|
|
182
|
+
out.push({
|
|
183
|
+
selector: selectorFor(element),
|
|
184
|
+
tag: element.tagName.toLowerCase(),
|
|
185
|
+
type,
|
|
186
|
+
name: element.getAttribute("name"),
|
|
187
|
+
accessibleName: name,
|
|
188
|
+
labelSource: source,
|
|
189
|
+
required: element.hasAttribute("required") || element.getAttribute("aria-required") === "true",
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return capped(out, "formControls");
|
|
193
|
+
}
|
|
194
|
+
// --- contrast ------------------------------------------------------------
|
|
195
|
+
function parseColor(value) {
|
|
196
|
+
const match = /^rgba?\(([^)]+)\)$/.exec(value.trim());
|
|
197
|
+
if (!match)
|
|
198
|
+
return null;
|
|
199
|
+
const parts = match[1].split(/[,\s/]+/).filter((part) => part.length > 0).map(Number);
|
|
200
|
+
const [r, g, b] = parts;
|
|
201
|
+
if (r === undefined || g === undefined || b === undefined)
|
|
202
|
+
return null;
|
|
203
|
+
const alpha = parts.length > 3 ? parts[3] : 1;
|
|
204
|
+
return [r, g, b, alpha];
|
|
205
|
+
}
|
|
206
|
+
function relativeLuminance([r, g, b]) {
|
|
207
|
+
const channel = (raw) => {
|
|
208
|
+
const c = raw / 255;
|
|
209
|
+
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
210
|
+
};
|
|
211
|
+
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
|
|
212
|
+
}
|
|
213
|
+
function composite(fg, bg) {
|
|
214
|
+
const alpha = fg[3];
|
|
215
|
+
return [fg[0] * alpha + bg[0] * (1 - alpha), fg[1] * alpha + bg[1] * (1 - alpha), fg[2] * alpha + bg[2] * (1 - alpha), 1];
|
|
216
|
+
}
|
|
217
|
+
/** Composite translucent backgrounds from the outermost ancestor onto a white fallback.
|
|
218
|
+
* Images and gradients remain outside this bounded colour-pair sample. */
|
|
219
|
+
function effectiveBackground(element) {
|
|
220
|
+
const layers = [];
|
|
221
|
+
let current = element;
|
|
222
|
+
while (current) {
|
|
223
|
+
const parsed = parseColor(getComputedStyle(current).backgroundColor);
|
|
224
|
+
if (parsed && parsed[3] > 0) {
|
|
225
|
+
layers.push(parsed);
|
|
226
|
+
if (parsed[3] === 1)
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
current = current.parentElement;
|
|
230
|
+
}
|
|
231
|
+
let background = [255, 255, 255, 1];
|
|
232
|
+
for (const layer of layers.reverse())
|
|
233
|
+
background = composite(layer, background);
|
|
234
|
+
return `rgb(${background[0]}, ${background[1]}, ${background[2]})`;
|
|
235
|
+
}
|
|
236
|
+
const CONTRAST_CANDIDATE_SELECTOR = "p,li,a,button,h1,h2,h3,h4,h5,h6,label,span,td,th";
|
|
237
|
+
/** Only leaf-ish text with real content: a wrapper repeats its children's colours and would crowd
|
|
238
|
+
* the sample set with duplicates of the same real pair. */
|
|
239
|
+
function hasOwnSampleableText(element) {
|
|
240
|
+
const text = (element.textContent ?? "").trim();
|
|
241
|
+
if (text.length === 0)
|
|
242
|
+
return false;
|
|
243
|
+
return !element.querySelector(CONTRAST_CANDIDATE_SELECTOR);
|
|
244
|
+
}
|
|
245
|
+
function isRenderedVisible(element, style) {
|
|
246
|
+
if (style.visibility === "hidden" || style.display === "none")
|
|
247
|
+
return false;
|
|
248
|
+
// display is not inherited: a hidden subtree's child can still compute display:block.
|
|
249
|
+
let ancestor = element.parentElement;
|
|
250
|
+
while (ancestor) {
|
|
251
|
+
if (getComputedStyle(ancestor).display === "none")
|
|
252
|
+
return false;
|
|
253
|
+
ancestor = ancestor.parentElement;
|
|
254
|
+
}
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
/** Computes one contrast sample for an element already known to be sampleable and visible, or
|
|
258
|
+
* `null` when its colours cannot be parsed.
|
|
259
|
+
*
|
|
260
|
+
* INVARIANT: `bg` can never actually be null, only `fg` can. `background` comes from
|
|
261
|
+
* `effectiveBackground`, which has exactly two return paths: an ancestor's `backgroundColor`
|
|
262
|
+
* that `parseColor` has ALREADY parsed successfully (that is what `parsed[3] > 0` requires), or
|
|
263
|
+
* the hardcoded fallback literal `"rgb(255, 255, 255)"`, which trivially matches `parseColor`'s
|
|
264
|
+
* own regex. So `parseColor(effectiveBackground(element))` is guaranteed non-null. `fg`, by
|
|
265
|
+
* contrast, comes straight from the browser's own `style.color` serialization, which is not
|
|
266
|
+
* guaranteed to be `rgb()`/`rgba()` syntax (e.g. newer CSS Color 4 syntaxes some engines may
|
|
267
|
+
* report) — that is the one this guard exists to catch.
|
|
268
|
+
*
|
|
269
|
+
* Kept as `!fg || !bg` (not narrowed to `!fg`) deliberately: this file's header forbids hoisting
|
|
270
|
+
* helpers out of `collectPageStructure`'s closure for serialization across the Playwright
|
|
271
|
+
* `page.evaluate` boundary (see file header), so there is no seam here that would let a test
|
|
272
|
+
* inject an unparseable `effectiveBackground` result without changing `effectiveBackground`'s own
|
|
273
|
+
* behavior. Removing the `!bg` half would encode "we are certain this never happens" as an
|
|
274
|
+
* assumption baked into the return type instead of a runtime check — if `effectiveBackground`'s
|
|
275
|
+
* fallback literal is ever changed to something not always parseable, this guard is what keeps a
|
|
276
|
+
* malformed sample from reaching `relativeLuminance` instead of failing loudly. */
|
|
277
|
+
function contrastSampleFor(element, style) {
|
|
278
|
+
const foreground = style.color;
|
|
279
|
+
const background = effectiveBackground(element);
|
|
280
|
+
const fg = parseColor(foreground);
|
|
281
|
+
const bg = parseColor(background);
|
|
282
|
+
if (!fg || !bg) {
|
|
283
|
+
truncated.push("contrastSamples:unparsed-colour");
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
const l1 = relativeLuminance(composite(fg, bg));
|
|
287
|
+
const l2 = relativeLuminance(bg);
|
|
288
|
+
const ratio = (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
|
|
289
|
+
return {
|
|
290
|
+
selector: selectorFor(element),
|
|
291
|
+
foreground,
|
|
292
|
+
background,
|
|
293
|
+
ratio: Math.round(ratio * 100) / 100,
|
|
294
|
+
fontSizePx: Math.round(parseFloat(style.fontSize) * 10) / 10,
|
|
295
|
+
fontWeight: Number(style.fontWeight) || 400,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function collectContrastSamples() {
|
|
299
|
+
const out = [];
|
|
300
|
+
const candidates = Array.from(document.querySelectorAll(CONTRAST_CANDIDATE_SELECTOR));
|
|
301
|
+
for (const element of candidates) {
|
|
302
|
+
if (out.length >= limits.maxContrastSamples) {
|
|
303
|
+
truncated.push("contrastSamples");
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
if (!hasOwnSampleableText(element))
|
|
307
|
+
continue;
|
|
308
|
+
const style = getComputedStyle(element);
|
|
309
|
+
if (!isRenderedVisible(element, style))
|
|
310
|
+
continue;
|
|
311
|
+
const sample = contrastSampleFor(element, style);
|
|
312
|
+
if (sample)
|
|
313
|
+
out.push(sample);
|
|
314
|
+
}
|
|
315
|
+
return out;
|
|
316
|
+
}
|
|
317
|
+
// --- document ------------------------------------------------------------
|
|
318
|
+
const bodyText = (document.body?.innerText ?? "").replace(/[ \t]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
|
|
319
|
+
const textTruncated = bodyText.length > limits.maxTextExcerptChars;
|
|
320
|
+
const accessibility = limits.collectAccessibility
|
|
321
|
+
? {
|
|
322
|
+
landmarks: collectLandmarks(),
|
|
323
|
+
headings: collectHeadings(),
|
|
324
|
+
images: collectImages(),
|
|
325
|
+
formControls: collectFormControls(),
|
|
326
|
+
contrastSamples: collectContrastSamples(),
|
|
327
|
+
truncated: Array.from(new Set(truncated)),
|
|
328
|
+
}
|
|
329
|
+
: { landmarks: [], headings: [], images: [], formControls: [], contrastSamples: [], truncated: ["not-collected"] };
|
|
330
|
+
return {
|
|
331
|
+
title: document.title,
|
|
332
|
+
lang: document.documentElement.getAttribute("lang"),
|
|
333
|
+
textExcerpt: textTruncated ? bodyText.slice(0, limits.maxTextExcerptChars) : bodyText,
|
|
334
|
+
textTruncated,
|
|
335
|
+
accessibility,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
//# sourceMappingURL=page-structure-script.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Internal deadline shared by every asynchronous step of one page observation. */
|
|
2
|
+
export declare class PageWorkTimeout extends Error {
|
|
3
|
+
constructor({ timeoutMs }: {
|
|
4
|
+
timeoutMs: number;
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
/** A timeout is a budget for the whole page, not a fresh allowance for each browser operation. */
|
|
8
|
+
export declare class PageWorkBudget {
|
|
9
|
+
private readonly expiresAt;
|
|
10
|
+
private readonly timeoutMs;
|
|
11
|
+
constructor({ timeoutMs }: {
|
|
12
|
+
timeoutMs: number;
|
|
13
|
+
});
|
|
14
|
+
remainingMs(): number;
|
|
15
|
+
/** Races even APIs without native timeouts (evaluation/cookies) and never starts expired work.
|
|
16
|
+
* @complexity O(1) time and space apart from the injected operation. */
|
|
17
|
+
run<T>({ work }: {
|
|
18
|
+
work: () => Promise<T>;
|
|
19
|
+
}): Promise<T>;
|
|
20
|
+
/** Always initiate resource release, but a stalled close must not extend an exhausted budget.
|
|
21
|
+
* Pending Playwright operations are interrupted by context/browser close; late rejections are handled.
|
|
22
|
+
* @complexity O(1) aside from resource release. */
|
|
23
|
+
release({ close }: {
|
|
24
|
+
close: () => Promise<void>;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=page-work-budget.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Internal deadline shared by every asynchronous step of one page observation. */
|
|
2
|
+
export class PageWorkTimeout extends Error {
|
|
3
|
+
constructor({ timeoutMs }) {
|
|
4
|
+
super(`page work timed out after ${timeoutMs}ms`);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/** A timeout is a budget for the whole page, not a fresh allowance for each browser operation. */
|
|
8
|
+
export class PageWorkBudget {
|
|
9
|
+
expiresAt;
|
|
10
|
+
timeoutMs;
|
|
11
|
+
constructor({ timeoutMs }) {
|
|
12
|
+
this.timeoutMs = timeoutMs;
|
|
13
|
+
this.expiresAt = Date.now() + timeoutMs;
|
|
14
|
+
}
|
|
15
|
+
remainingMs() { return Math.max(0, this.expiresAt - Date.now()); }
|
|
16
|
+
/** Races even APIs without native timeouts (evaluation/cookies) and never starts expired work.
|
|
17
|
+
* @complexity O(1) time and space apart from the injected operation. */
|
|
18
|
+
async run({ work }) {
|
|
19
|
+
const remaining = this.remainingMs();
|
|
20
|
+
if (remaining <= 0)
|
|
21
|
+
throw new PageWorkTimeout({ timeoutMs: this.timeoutMs });
|
|
22
|
+
let timer;
|
|
23
|
+
try {
|
|
24
|
+
return await Promise.race([
|
|
25
|
+
work(),
|
|
26
|
+
new Promise((_resolve, reject) => {
|
|
27
|
+
timer = setTimeout(() => reject(new PageWorkTimeout({ timeoutMs: this.timeoutMs })), remaining);
|
|
28
|
+
}),
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Always initiate resource release, but a stalled close must not extend an exhausted budget.
|
|
36
|
+
* Pending Playwright operations are interrupted by context/browser close; late rejections are handled.
|
|
37
|
+
* @complexity O(1) aside from resource release. */
|
|
38
|
+
async release({ close }) {
|
|
39
|
+
const closing = close();
|
|
40
|
+
if (this.remainingMs() <= 0) {
|
|
41
|
+
void closing.catch(() => { });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
await this.run({ work: () => closing });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (!(error instanceof PageWorkTimeout))
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=page-work-budget.js.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The one and only module in this repository that touches a real headless browser.
|
|
3
|
+
* Implements `SiteEvidenceBrowserPort` (`browser-port.ts`) on Playwright's Chromium.
|
|
4
|
+
*
|
|
5
|
+
* ---------------------------------------------------------------------------
|
|
6
|
+
* Why the import is dynamic, and why the module's types are declared here
|
|
7
|
+
* ---------------------------------------------------------------------------
|
|
8
|
+
* The host may optionally install `playwright`; this package adds no browser dependency. The BROWSER
|
|
9
|
+
* BINARY it drives needs a separate `playwright install chromium` step in the host deployment.
|
|
10
|
+
* Installing the module alone does not supply that binary. So both halves can
|
|
11
|
+
* legitimately be missing at runtime, independently:
|
|
12
|
+
*
|
|
13
|
+
* - the module itself, on a deployment that pruned it;
|
|
14
|
+
* - the Chromium binary, on a deployment that installed the module but not the browser.
|
|
15
|
+
*
|
|
16
|
+
* Both are caught here and converted into `{ available: false, reason }`, never a thrown error and
|
|
17
|
+
* never a boot failure. The tool then reports "no browser in this deployment" and the compliance
|
|
18
|
+
* skill is required by its own output contract to downgrade every rendered-truth finding to
|
|
19
|
+
* `cannot-determine`. That is the entire reason this adapter must not be a static import: a static
|
|
20
|
+
* one would make an optional capability a hard boot dependency for every host install.
|
|
21
|
+
*
|
|
22
|
+
* {@link PlaywrightLike} declares, structurally, exactly the eight or so members this adapter uses.
|
|
23
|
+
* That is deliberate rather than importing Playwright's own (very large) `.d.ts`: typechecking this
|
|
24
|
+
* repository must not depend on a browser automation library's type surface being resolvable, and
|
|
25
|
+
* naming the members used makes the actual coupling one short, reviewable block instead of an
|
|
26
|
+
* open-ended import.
|
|
27
|
+
*
|
|
28
|
+
* ---------------------------------------------------------------------------
|
|
29
|
+
* Privacy properties, enforced here rather than promised
|
|
30
|
+
* ---------------------------------------------------------------------------
|
|
31
|
+
* - **Ephemeral context.** `browser.newContext()` with no `storageState` and no user-data
|
|
32
|
+
* directory. Cookies, storage, and cache exist only in memory and die with `close()`. Nothing is
|
|
33
|
+
* written to disk by this module.
|
|
34
|
+
* - **One context per page.** Each `observe()` call gets a fresh context, so a cookie set by page A
|
|
35
|
+
* can never be reported as though page B set it — which would be an outright false citation in a
|
|
36
|
+
* pre-consent cookie finding.
|
|
37
|
+
* - **No non-GET request ever leaves the process.** Every request is intercepted; anything that is
|
|
38
|
+
* not GET or HEAD is aborted and recorded as blocked. This is what makes "never submits forms" a
|
|
39
|
+
* structural property instead of a policy: even if a page auto-submits, or a consent widget POSTs
|
|
40
|
+
* preferences, the attempt is observed and the bytes do not go out.
|
|
41
|
+
* - **Values are never read.** Cookie values, request bodies, and form-field values are not
|
|
42
|
+
* extracted anywhere below, because `browser-port.ts`'s shapes have nowhere to put them.
|
|
43
|
+
*/
|
|
44
|
+
import type { SiteEvidenceBrowserAvailability } from "./browser-port.js";
|
|
45
|
+
interface PwRoute {
|
|
46
|
+
request(): PwRequest;
|
|
47
|
+
abort(errorCode?: string): Promise<void>;
|
|
48
|
+
continue(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
interface PwRequest {
|
|
51
|
+
url(): string;
|
|
52
|
+
method(): string;
|
|
53
|
+
resourceType(): string;
|
|
54
|
+
}
|
|
55
|
+
interface PwResponse {
|
|
56
|
+
status(): number;
|
|
57
|
+
url(): string;
|
|
58
|
+
headers(): Record<string, string>;
|
|
59
|
+
}
|
|
60
|
+
interface PwCookie {
|
|
61
|
+
name: string;
|
|
62
|
+
value: string;
|
|
63
|
+
domain: string;
|
|
64
|
+
path: string;
|
|
65
|
+
expires: number;
|
|
66
|
+
httpOnly: boolean;
|
|
67
|
+
secure: boolean;
|
|
68
|
+
sameSite: string;
|
|
69
|
+
}
|
|
70
|
+
interface PwLocator {
|
|
71
|
+
first(): PwLocator;
|
|
72
|
+
count(): Promise<number>;
|
|
73
|
+
click(options?: {
|
|
74
|
+
timeout?: number;
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
interface PwPage {
|
|
78
|
+
goto(url: string, options?: {
|
|
79
|
+
waitUntil?: string;
|
|
80
|
+
timeout?: number;
|
|
81
|
+
}): Promise<PwResponse | null>;
|
|
82
|
+
/** Only the STRING form is used — see {@link buildPageStructureExpression} for why passing the
|
|
83
|
+
* function reference directly is not safe here. */
|
|
84
|
+
evaluate<T>(expression: string): Promise<T>;
|
|
85
|
+
locator(selector: string): PwLocator;
|
|
86
|
+
waitForTimeout(ms: number): Promise<void>;
|
|
87
|
+
title(): Promise<string>;
|
|
88
|
+
}
|
|
89
|
+
interface PwContext {
|
|
90
|
+
newPage(): Promise<PwPage>;
|
|
91
|
+
route(pattern: string, handler: (route: PwRoute) => void | Promise<void>): Promise<void>;
|
|
92
|
+
cookies(): Promise<PwCookie[]>;
|
|
93
|
+
close(): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
interface PwBrowser {
|
|
96
|
+
newContext(options?: Record<string, unknown>): Promise<PwContext>;
|
|
97
|
+
close(): Promise<void>;
|
|
98
|
+
}
|
|
99
|
+
export interface PlaywrightLike {
|
|
100
|
+
chromium: {
|
|
101
|
+
launch(options?: {
|
|
102
|
+
headless?: boolean;
|
|
103
|
+
args?: readonly string[];
|
|
104
|
+
}): Promise<PwBrowser>;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Opens a real Chromium and returns a `SiteEvidenceBrowserPort` over it, or explains why this
|
|
109
|
+
* deployment cannot.
|
|
110
|
+
*
|
|
111
|
+
* @returns `{ available: true, browser }` on success; `{ available: false, reason }` when the
|
|
112
|
+
* `playwright` module or its Chromium binary is not present. Never throws for either case — see
|
|
113
|
+
* this file's header for why an absent browser must be a reportable state rather than an error.
|
|
114
|
+
* @complexity One process launch. The caller is responsible for calling `close()`, which
|
|
115
|
+
* `collectPageEvidence` does in a `finally`.
|
|
116
|
+
*/
|
|
117
|
+
export interface PlaywrightAdapterOptions {
|
|
118
|
+
readonly moduleLoader?: {
|
|
119
|
+
load(required: {
|
|
120
|
+
moduleName: string;
|
|
121
|
+
}): Promise<PlaywrightLike>;
|
|
122
|
+
};
|
|
123
|
+
readonly launchOptions?: {
|
|
124
|
+
headless?: boolean;
|
|
125
|
+
args?: string[];
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** Opens the optional browser capability; import and launch failures become availability results. */
|
|
129
|
+
export declare function openPlaywrightSiteEvidenceBrowser(_required: Record<string, never>, options?: PlaywrightAdapterOptions): Promise<SiteEvidenceBrowserAvailability>;
|
|
130
|
+
export {};
|
|
131
|
+
//# sourceMappingURL=playwright-browser.d.ts.map
|