@jini-ai/diagnostics 0.5.2 → 0.5.4
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 +8 -0
- package/dist/agent-logs.js +31 -44
- package/dist/core/secrets-only.d.ts +8 -2
- package/dist/core/secrets-only.js +181 -9
- package/dist/discovery-filesystem.d.ts +14 -0
- package/dist/discovery-filesystem.js +19 -0
- package/dist/domain-dns/index.js +7 -3
- package/dist/node-ports.js +14 -10
- package/dist/observability/instrumentation.js +11 -7
- package/dist/redaction.js +16 -12
- package/dist/sources.js +21 -24
- package/dist/web-evidence/browser-port.d.ts +3 -0
- package/dist/web-evidence/browser-port.js +0 -1
- package/dist/web-evidence/collect-page-evidence.d.ts +2 -0
- package/dist/web-evidence/collect-page-evidence.js +58 -56
- package/dist/web-evidence/index.d.ts +1 -0
- package/dist/web-evidence/index.js +1 -0
- package/dist/web-evidence/lazy-browser.js +5 -4
- package/dist/web-evidence/page-performance-script.d.ts +38 -0
- package/dist/web-evidence/page-performance-script.js +80 -0
- package/dist/web-evidence/playwright-browser.d.ts +0 -3
- package/dist/web-evidence/playwright-browser.js +23 -14
- package/dist/web-evidence/playwright-runtime.d.ts +3 -0
- package/dist/web-evidence/playwright-runtime.js +7 -4
- package/dist/web-evidence/public-page.d.ts +3 -3
- package/dist/web-evidence/public-page.js +97 -81
- package/dist/web-evidence/render-page.js +167 -125
- package/dist/web-evidence/request-guard.d.ts +1 -1
- package/dist/web-evidence/request-guard.js +87 -78
- package/package.json +4 -3
|
@@ -3,25 +3,31 @@ export const MAX_REDIRECT_HOPS = 5;
|
|
|
3
3
|
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
4
4
|
/** Streaming and media types that add nothing to a still picture and could hold a fetch open. */
|
|
5
5
|
const SKIPPED_RESOURCE_TYPES = new Set(["media", "eventsource", "websocket", "texttrack"]);
|
|
6
|
+
/** The only requests a public reader may opt into writing: script-issued XHR/fetch data calls. */
|
|
7
|
+
function isDataWrite({ method, resourceType }) {
|
|
8
|
+
return ["xhr", "fetch"].includes(resourceType) && ["POST", "PUT", "PATCH"].includes(method.toUpperCase());
|
|
9
|
+
}
|
|
10
|
+
/** An anonymous http(s) URL, or `undefined` for anything unparsable, credentialed or another scheme. */
|
|
11
|
+
function parseFetchableUrl(url) {
|
|
12
|
+
try {
|
|
13
|
+
const parsed = new URL(url);
|
|
14
|
+
return ["http:", "https:"].includes(parsed.protocol) && !parsed.username && !parsed.password ? parsed : undefined;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
6
20
|
/**
|
|
7
21
|
* Pure routing decision for one request. Budget is not considered here (see the router).
|
|
8
22
|
* @complexity O(url length + allowedOrigins).
|
|
9
23
|
*/
|
|
10
24
|
export function decideRequest({ url, method, resourceType, allowedOrigins }, { allowDataRequests = false } = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
parsed = new URL(url);
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
return { action: "abort", reason: "scheme" };
|
|
17
|
-
}
|
|
18
|
-
if (parsed.username || parsed.password)
|
|
19
|
-
return { action: "abort", reason: "scheme" };
|
|
20
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
25
|
+
const parsed = parseFetchableUrl(url);
|
|
26
|
+
if (!parsed)
|
|
21
27
|
return { action: "abort", reason: "scheme" };
|
|
22
28
|
const upper = method.toUpperCase();
|
|
23
|
-
const dataWrite = allowDataRequests &&
|
|
24
|
-
if (
|
|
29
|
+
const dataWrite = allowDataRequests && isDataWrite({ method: upper, resourceType });
|
|
30
|
+
if (!["GET", "HEAD"].includes(upper) && !dataWrite)
|
|
25
31
|
return { action: "abort", reason: "method" };
|
|
26
32
|
if (SKIPPED_RESOURCE_TYPES.has(resourceType))
|
|
27
33
|
return { action: "abort", reason: "resource-type" };
|
|
@@ -68,6 +74,13 @@ function redirectTarget(resource, base) {
|
|
|
68
74
|
return location;
|
|
69
75
|
}
|
|
70
76
|
}
|
|
77
|
+
/** Match fetch redirect semantics without letting Chromium follow an unvetted hop. */
|
|
78
|
+
function redirectedRequest({ status, method, body, headers }) {
|
|
79
|
+
if (status !== 303 && !([301, 302].includes(status) && method.toUpperCase() === "POST"))
|
|
80
|
+
return { method, body, headers };
|
|
81
|
+
const { "content-type": _dropped, ...kept } = headers;
|
|
82
|
+
return { method: "GET", body: undefined, headers: kept };
|
|
83
|
+
}
|
|
71
84
|
/** A counting semaphore: at most `limit` holders, FIFO waiters. */
|
|
72
85
|
function createSemaphore(limit) {
|
|
73
86
|
let active = 0;
|
|
@@ -85,28 +98,11 @@ function createSemaphore(limit) {
|
|
|
85
98
|
},
|
|
86
99
|
};
|
|
87
100
|
}
|
|
88
|
-
/**
|
|
89
|
-
*
|
|
90
|
-
* @param required.httpClient - Guarded client built from `platform/http`'s `WEB_SCREENSHOT_EGRESS_POLICY`; never a raw transport.
|
|
91
|
-
* @param required.ownSiteFetch - Loopback fetch for `allowedOrigins` only.
|
|
92
|
-
* @param required.allowedOrigins - Exact origins (scheme://host:port) that bypass the public guard; empty for public pages.
|
|
93
|
-
* @param required.signal - Aborts every in-flight fetch when the capture ends or times out.
|
|
94
|
-
* @complexity O(1) bookkeeping per hop, at most {@link MAX_REDIRECT_HOPS} + 1 hops per request; fetches are bounded by `maxConcurrent` and the budgets.
|
|
95
|
-
*/
|
|
96
|
-
export function createRequestRouter({ httpClient, ownSiteFetch, allowedOrigins, signal }, { maxRequests = 300, maxTotalBytes = 60 * 1024 * 1024, maxResourceBytes = 15 * 1024 * 1024, maxConcurrent = 6, perRequestTimeoutMs = 15_000, preserveOwnSiteCookies = false, allowDataRequests = false, maxRequestBodyBytes = 64 * 1024, isEgressRefused = error => error instanceof Error && error.name === "EgressRefusedError", onResponse, onBlocked } = {}) {
|
|
97
|
-
const report = { fulfilled: 0, blocked: 0, navigationRefused: false, bytes: 0 };
|
|
101
|
+
/** One capture's transport side: request/byte budgets, the concurrency slots and both fetch paths. */
|
|
102
|
+
function createHopFetcher({ httpClient, ownSiteFetch, signal, report }, { maxRequests = 300, maxTotalBytes = 60 * 1024 * 1024, maxResourceBytes = 15 * 1024 * 1024, maxConcurrent = 6, perRequestTimeoutMs = 15_000, isEgressRefused = error => error instanceof Error && error.name === "EgressRefusedError" }) {
|
|
98
103
|
const slots = createSemaphore(maxConcurrent);
|
|
99
104
|
let started = 0;
|
|
100
|
-
|
|
101
|
-
async function abort(route, reason, isNavigation) {
|
|
102
|
-
report.blocked += 1;
|
|
103
|
-
onBlocked?.({ url: route.request().url(), resourceType: route.request().resourceType(), reason });
|
|
104
|
-
if (reason === "refused" && isNavigation)
|
|
105
|
-
report.navigationRefused = true;
|
|
106
|
-
// The context may already be closing; a route that is gone has nothing left to abort.
|
|
107
|
-
await route.abort(reason === "failed" ? "failed" : "blockedbyclient").catch(() => { });
|
|
108
|
-
}
|
|
109
|
-
async function fetchResource(decision, url, headers, requestBody) {
|
|
105
|
+
async function fetchResource({ decision, url, headers, body: requestBody }) {
|
|
110
106
|
if (decision.via === "own-site") {
|
|
111
107
|
return ownSiteFetch({ url, method: decision.method, headers }, { signal, maxBytes: maxResourceBytes });
|
|
112
108
|
}
|
|
@@ -115,7 +111,7 @@ export function createRequestRouter({ httpClient, ownSiteFetch, allowedOrigins,
|
|
|
115
111
|
return { status: response.status, headers: { ...response.headers, ...(response.setCookies?.length ? { "set-cookie": response.setCookies.join("\n") } : {}) }, body, truncated: response.bodyBytes ? response.bodyBytesTruncated === true : response.bodyTruncated === true };
|
|
116
112
|
}
|
|
117
113
|
/** One hop: budget, a concurrency slot, the fetch, and the byte accounting — or why it was refused. */
|
|
118
|
-
async
|
|
114
|
+
return async (hop) => {
|
|
119
115
|
if (started >= maxRequests || report.bytes >= maxTotalBytes || signal.aborted)
|
|
120
116
|
return "budget";
|
|
121
117
|
started += 1;
|
|
@@ -126,7 +122,7 @@ export function createRequestRouter({ httpClient, ownSiteFetch, allowedOrigins,
|
|
|
126
122
|
}
|
|
127
123
|
let resource;
|
|
128
124
|
try {
|
|
129
|
-
resource = await fetchResource(
|
|
125
|
+
resource = await fetchResource(hop);
|
|
130
126
|
}
|
|
131
127
|
catch (error) {
|
|
132
128
|
return isEgressRefused(error) ? "refused" : "failed";
|
|
@@ -138,56 +134,69 @@ export function createRequestRouter({ httpClient, ownSiteFetch, allowedOrigins,
|
|
|
138
134
|
return "budget";
|
|
139
135
|
report.bytes += resource.body.length;
|
|
140
136
|
return report.bytes > maxTotalBytes ? "budget" : resource;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Builds the router for ONE capture (budgets and counters are per capture).
|
|
141
|
+
* @param required.httpClient - Guarded client built from `platform/http`'s `WEB_SCREENSHOT_EGRESS_POLICY`; never a raw transport.
|
|
142
|
+
* @param required.ownSiteFetch - Loopback fetch for `allowedOrigins` only.
|
|
143
|
+
* @param required.allowedOrigins - Exact origins (scheme://host:port) that bypass the public guard; empty for public pages.
|
|
144
|
+
* @param required.signal - Aborts every in-flight fetch when the capture ends or times out.
|
|
145
|
+
* @complexity O(1) bookkeeping per hop, at most {@link MAX_REDIRECT_HOPS} + 1 hops per request; fetches are bounded by `maxConcurrent` and the budgets.
|
|
146
|
+
*/
|
|
147
|
+
export function createRequestRouter({ httpClient, ownSiteFetch, allowedOrigins, signal }, options = {}) {
|
|
148
|
+
const { preserveOwnSiteCookies = false, allowDataRequests = false, maxRequestBodyBytes = 64 * 1024, onResponse, onBlocked } = options;
|
|
149
|
+
const report = { fulfilled: 0, blocked: 0, navigationRefused: false, bytes: 0 };
|
|
150
|
+
const fetchHop = createHopFetcher({ httpClient, ownSiteFetch, signal, report }, options);
|
|
151
|
+
let navigationRedirect;
|
|
152
|
+
async function abort(route, reason, isNavigation) {
|
|
153
|
+
report.blocked += 1;
|
|
154
|
+
onBlocked?.({ url: route.request().url(), resourceType: route.request().resourceType(), reason });
|
|
155
|
+
if (reason === "refused" && isNavigation)
|
|
156
|
+
report.navigationRefused = true;
|
|
157
|
+
// The context may already be closing; a route that is gone has nothing left to abort.
|
|
158
|
+
await route.abort(reason === "failed" ? "failed" : "blockedbyclient").catch(() => { });
|
|
159
|
+
}
|
|
160
|
+
async function fulfill(route, { url, resource }) {
|
|
161
|
+
report.fulfilled += 1;
|
|
162
|
+
onResponse?.({ url, resourceType: route.request().resourceType(), resource });
|
|
163
|
+
await route.fulfill({ status: resource.status, headers: filterHeaders(resource.headers, preserveOwnSiteCookies
|
|
164
|
+
? OWN_SITE_RESPONSE_HEADERS
|
|
165
|
+
: DROPPED_RESPONSE_HEADERS), body: resource.body }).catch(() => { });
|
|
166
|
+
}
|
|
167
|
+
/** One hop of one request: decide, fetch, then fulfil, hand a page redirect back, or route the next hop. */
|
|
168
|
+
async function routeHop({ route, isNavigation }, { hop, url, method, body, headers }) {
|
|
169
|
+
const request = route.request();
|
|
170
|
+
const decision = decideRequest({ url, method, resourceType: request.resourceType(), allowedOrigins }, { allowDataRequests });
|
|
171
|
+
if (decision.action === "abort")
|
|
172
|
+
return abort(route, decision.reason, isNavigation);
|
|
173
|
+
const ownCookie = preserveOwnSiteCookies && decision.via === "own-site" ? request.headers().cookie : undefined;
|
|
174
|
+
const resource = await fetchHop({ decision, url, headers: ownCookie ? { ...headers, cookie: ownCookie } : headers, body });
|
|
175
|
+
if (typeof resource === "string")
|
|
176
|
+
return abort(route, resource, isNavigation);
|
|
177
|
+
const next = redirectTarget(resource, url);
|
|
178
|
+
if (next === undefined)
|
|
179
|
+
return fulfill(route, { url, resource });
|
|
180
|
+
if (isNavigation) {
|
|
181
|
+
// Not a block: the capture navigates to `next` itself, so that hop is routed like this one.
|
|
182
|
+
// `aborted` (net::ERR_ABORTED) commits no error page; `blockedbyclient` would commit
|
|
183
|
+
// chrome-error://, which interrupts that next navigation (real Chromium, 2026-10-08).
|
|
184
|
+
navigationRedirect = next;
|
|
185
|
+
return route.abort("aborted").catch(() => { });
|
|
186
|
+
}
|
|
187
|
+
if (hop >= MAX_REDIRECT_HOPS)
|
|
188
|
+
return abort(route, "failed", isNavigation);
|
|
189
|
+
return routeHop({ route, isNavigation }, { hop: hop + 1, url: next, ...redirectedRequest({ status: resource.status, method, body, headers }) });
|
|
141
190
|
}
|
|
142
191
|
return {
|
|
143
192
|
async handle(route) {
|
|
144
193
|
const request = route.request();
|
|
145
194
|
const isNavigation = isMainFrameNavigation({ request });
|
|
146
|
-
const
|
|
147
|
-
let url = request.url();
|
|
148
|
-
let method = request.method();
|
|
149
|
-
let body;
|
|
195
|
+
const body = allowDataRequests && isDataWrite({ method: request.method(), resourceType: request.resourceType() }) ? request.postData?.() ?? undefined : undefined;
|
|
150
196
|
// Reject oversized writes whole; a clipped GraphQL payload would be a different request.
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return abort(route, "budget", isNavigation);
|
|
155
|
-
}
|
|
156
|
-
for (let hop = 0;; hop += 1) {
|
|
157
|
-
const decision = decideRequest({ url, method, resourceType: request.resourceType(), allowedOrigins }, { allowDataRequests });
|
|
158
|
-
if (decision.action === "abort")
|
|
159
|
-
return abort(route, decision.reason, isNavigation);
|
|
160
|
-
const ownCookie = preserveOwnSiteCookies && decision.via === "own-site" ? request.headers().cookie : undefined;
|
|
161
|
-
const resource = await fetchHop(decision, url, ownCookie ? { ...headers, cookie: ownCookie } : headers, body);
|
|
162
|
-
if (typeof resource === "string")
|
|
163
|
-
return abort(route, resource, isNavigation);
|
|
164
|
-
const next = redirectTarget(resource, url);
|
|
165
|
-
if (next === undefined) {
|
|
166
|
-
report.fulfilled += 1;
|
|
167
|
-
onResponse?.({ url, resourceType: request.resourceType(), resource });
|
|
168
|
-
await route.fulfill({ status: resource.status, headers: filterHeaders(resource.headers, preserveOwnSiteCookies
|
|
169
|
-
? OWN_SITE_RESPONSE_HEADERS
|
|
170
|
-
: DROPPED_RESPONSE_HEADERS), body: resource.body }).catch(() => { });
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
if (isNavigation) {
|
|
174
|
-
// Not a block: the capture navigates to `next` itself, so that hop is routed like this one.
|
|
175
|
-
// `aborted` (net::ERR_ABORTED) commits no error page; `blockedbyclient` would commit
|
|
176
|
-
// chrome-error://, which interrupts that next navigation (real Chromium, 2026-10-08).
|
|
177
|
-
navigationRedirect = next;
|
|
178
|
-
await route.abort("aborted").catch(() => { });
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (hop >= MAX_REDIRECT_HOPS)
|
|
182
|
-
return abort(route, "failed", isNavigation);
|
|
183
|
-
// Match fetch redirect semantics without letting Chromium follow an unvetted hop.
|
|
184
|
-
if (resource.status === 303 || ([301, 302].includes(resource.status) && method.toUpperCase() === "POST")) {
|
|
185
|
-
method = "GET";
|
|
186
|
-
body = undefined;
|
|
187
|
-
delete headers["content-type"];
|
|
188
|
-
}
|
|
189
|
-
url = next;
|
|
190
|
-
}
|
|
197
|
+
if (body !== undefined && Buffer.byteLength(body, "utf8") > maxRequestBodyBytes)
|
|
198
|
+
return abort(route, "budget", isNavigation);
|
|
199
|
+
return routeHop({ route, isNavigation }, { hop: 0, url: request.url(), method: request.method(), body, headers: filterHeaders(request.headers(), DROPPED_REQUEST_HEADERS) });
|
|
191
200
|
},
|
|
192
201
|
report: () => ({ ...report }),
|
|
193
202
|
takeNavigationRedirect() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/diagnostics",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Diagnostics-bundle tooling: JSON/text secret redaction, log-source collection, manifest building, and zip packaging for support exports.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -82,10 +82,11 @@
|
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@vitest/coverage-v8": "^2.1.9",
|
|
84
84
|
"jszip": "^3.10.1",
|
|
85
|
-
"@jini-ai/core": "^0.4.
|
|
85
|
+
"@jini-ai/core": "^0.4.9"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"
|
|
88
|
+
"js-tokens": "^9.0.1",
|
|
89
|
+
"@jini-ai/core": "^0.4.9"
|
|
89
90
|
},
|
|
90
91
|
"peerDependencies": {
|
|
91
92
|
"jszip": "^3.10.1"
|