refactor(browser): reuse worker URL exclusion classification

This commit is contained in:
morluto committed 2026-10-26 13:59:22 +08:00
1 parent 5e581fd3b1
commit f6d9f1b05c
2 files changed
+30 -9

No files matched your search

+28
View File
@@ -44,6 +44,34 @@ const capture = async (inventory: unknown) => {
};
describe("web worker target inventory", () => {
it.each([
["", "unattributed_origin"],
["https://outside.example/worker.js", "disallowed_origin"],
["file:///fixture/worker.js", "unsupported_url"],
])(
"retains selected-worker URL exclusion evidence for %s",
async (url, reason) => {
const result = await capture({
targetInfos: [
{
targetId: "worker",
type: "worker",
url,
attached: false,
openerId: "page",
},
],
});
expect(result.workers).toEqual([]);
expect(result.completeness.excluded).toContainEqual({
section: "workers",
reason,
count: 1,
});
},
);
it("preserves an explicit empty inventory", async () => {
const result = await capture({ targetInfos: [] });
+2 -9
View File
@@ -3,13 +3,13 @@ import type { CdpCaptureEvents } from "./CdpCaptureEvents.js";
import {
admitRecords,
allowedSanitizedUrl,
isHttpUrl,
recordValue,
cdpStringValue,
} from "./CdpCaptureValues.js";
import type { CaptureContext } from "./CdpPageCapture.js";
import { optionalCdpCommand } from "./CdpOptionalCommand.js";
import { workerTargetOwnership } from "./CdpWorkerTargetOwnership.js";
import { exclusionReasonForUrl } from "./CdpCaptureEventHelpers.js";
interface CaptureWorkersInput {
readonly context: CaptureContext;
@@ -84,14 +84,7 @@ export const captureWorkers = async (
const url = allowedSanitizedUrl(target.url, allowedOrigins);
if (url === undefined) {
const rawUrl = cdpStringValue(target.url);
completeness.exclude(
"workers",
rawUrl === undefined || rawUrl === ""
? "unattributed_origin"
: isHttpUrl(rawUrl)
? "disallowed_origin"
: "unsupported_url",
);
completeness.exclude("workers", exclusionReasonForUrl(rawUrl));
continue;
}
items.push({