refactor(browser): align inspector exclusions with canonical vocabulary (#834)

Report canonical BrowserExclusionReasons from runtime location
authorization (unsupported_url, not_approved) and collapse them
onto the fixed V8 wire bucket via inspectorExclusionKey, keeping
describeInspectorTargetLimitations text stable. Document the
provider authority split (attach-only CDP/V8 vs owned-runtime
Playwright) so the shared vocabulary is not re-split.
This commit is contained in:
morluto
2026-10-07 11:34:57 +08:00
committed by GitHub
parent ef535b81fe
commit de9593ad48
5 changed files with 76 additions and 10 deletions
+11
View File
@@ -22,6 +22,17 @@ REA can attach to a user-owned Chrome-family browser through the Chrome DevTools
Target discovery returns the complete in-scope target array in one result.
Electron `file://` pages use a separate provider and target boundary; see [electron-observation.md](electron-observation.md).
## Provider authorities
CDP page capture, V8 Inspector observation, and Playwright scenarios stay
separate providers because their authorities differ: CDP and V8 attach to an
already-running target and never launch, drive, evaluate, or mutate it, while
Playwright providers own and drive the runtime (launch browsers, run actions,
capture step snapshots). Merging them would mix attach-only and owned-process
lifecycles in one contract. What they share instead is one exclusion
vocabulary (`BrowserExclusionReason`): every denial reason in every stack maps
onto it, even where a wire schema keeps a narrower historical bucket.
Existing static application Evidence and passive web/Electron captures can be
combined later through
[JavaScript static/runtime reconciliation](javascript-runtime-reconciliation.md).
@@ -0,0 +1,34 @@
import { describe, expect, it } from "vitest";
import {
authorizeRuntimeLocation,
inspectorExclusionKey,
} from "./JavaScriptRuntimeScope.js";
describe("runtime location authorization", () => {
it("reports canonical exclusion reasons per denial case", async () => {
expect(await authorizeRuntimeLocation("not a url")).toEqual({
allowed: false,
reason: "unsupported_url",
});
expect(await authorizeRuntimeLocation("ftp://example.test/app.js")).toEqual(
{
allowed: false,
reason: "unsupported_url",
},
);
expect(
await authorizeRuntimeLocation("file:///outside-approved-scope.js"),
).toEqual({ allowed: false, reason: "not_approved" });
});
it("collapses every canonical denial onto the fixed wire bucket", () => {
expect(inspectorExclusionKey("unsupported_url")).toBe(
"unsupported_location",
);
expect(inspectorExclusionKey("not_approved")).toBe("unsupported_location");
expect(inspectorExclusionKey("disallowed_origin")).toBe(
"unsupported_location",
);
});
});
+21 -6
View File
@@ -4,6 +4,7 @@ import {
browserOriginSchema,
sanitizeBrowserUrl,
} from "../domain/browserObservation.js";
import type { BrowserExclusionReason } from "../domain/browserCompleteness.js";
import type {
JavaScriptRuntimeLocation,
JavaScriptRuntimeTargetLocation,
@@ -14,9 +15,23 @@ export type RuntimeLocationDecision =
| { readonly allowed: true; readonly location: JavaScriptRuntimeLocation }
| {
readonly allowed: false;
readonly reason: "unsupported_location";
readonly reason: BrowserExclusionReason;
};
/**
* Wire bucket for inspector script exclusions. The V8 observation schemas
* fix the `unsupported_location` key, so every canonical denial reason maps
* onto it; the reason itself stays available on the decision for logs and
* limitations text.
*/
export const inspectorExclusionKey = (
reason: BrowserExclusionReason,
): "unsupported_location" => {
// Every canonical denial collapses onto the fixed V8 wire bucket.
void reason;
return "unsupported_location";
};
/** Resolve a protocol location exposed by the explicitly selected Inspector endpoint. */
export const authorizeRuntimeLocation = async (
value: string,
@@ -29,7 +44,7 @@ export const authorizeRuntimeLocation = async (
if (value.startsWith("file:")) {
const filePath = await authorizedElectronFile(value);
return filePath === undefined
? { allowed: false, reason: "unsupported_location" }
? { allowed: false, reason: "not_approved" }
: { allowed: true, location: { kind: "file", file_path: filePath } };
}
let url: URL;
@@ -38,13 +53,13 @@ export const authorizeRuntimeLocation = async (
} catch (cause: unknown) {
// Non-URL input is outside the authorized runtime scope.
void cause;
return { allowed: false, reason: "unsupported_location" };
return { allowed: false, reason: "unsupported_url" };
}
if (!["http:", "https:"].includes(url.protocol))
return { allowed: false, reason: "unsupported_location" };
return { allowed: false, reason: "unsupported_url" };
const parsedOrigin = browserOriginSchema.safeParse(url.origin);
if (!parsedOrigin.success)
return { allowed: false, reason: "unsupported_location" };
return { allowed: false, reason: "unsupported_url" };
return {
allowed: true,
location: {
@@ -64,7 +79,7 @@ export const authorizeRuntimeTargetLocation = async (
readonly allowed: true;
readonly location: JavaScriptRuntimeTargetLocation;
}
| { readonly allowed: false; readonly reason: "unsupported_location" }
| { readonly allowed: false; readonly reason: BrowserExclusionReason }
> => {
if (
context.type !== "node" ||
+5 -2
View File
@@ -6,7 +6,10 @@ import type {
JavaScriptRuntimeTargetList,
ObserveJavaScriptRuntimeInput,
} from "../domain/javascriptRuntimeObservation.js";
import { authorizeRuntimeLocation } from "./JavaScriptRuntimeScope.js";
import {
authorizeRuntimeLocation,
inspectorExclusionKey,
} from "./JavaScriptRuntimeScope.js";
import type { CaptureState, ScriptDraft } from "./V8InspectorProvider.js";
import type { AuthorizedV8InspectorTarget } from "./V8InspectorEndpoint.js";
@@ -52,7 +55,7 @@ export const finalizeInspectorCapture = async ({
for (const draft of state.scripts) {
const decision = await authorizeRuntimeLocation(draft.rawUrl);
if (!decision.allowed) {
exclusions[decision.reason] += 1;
exclusions[inspectorExclusionKey(decision.reason)] += 1;
continue;
}
const script = scriptFromDraft(draft, decision.location);
+5 -2
View File
@@ -23,7 +23,10 @@ import {
delayWithCancellation,
} from "./CdpCaptureValues.js";
import { CdpConnection, type CdpEvent } from "./CdpConnection.js";
import { authorizeRuntimeTargetLocation } from "./JavaScriptRuntimeScope.js";
import {
authorizeRuntimeTargetLocation,
inspectorExclusionKey,
} from "./JavaScriptRuntimeScope.js";
import {
createInspectorExclusionCounts,
describeInspectorTargetLimitations,
@@ -93,7 +96,7 @@ export class V8InspectorProvider implements JavaScriptRuntimeObservationPort {
product: discovery.runtime.product,
});
if (!decision.allowed) {
excluded[decision.reason] += 1;
excluded[inspectorExclusionKey(decision.reason)] += 1;
continue;
}
if (decision.location.kind === "builtin") {