fix(browser): distinguish SVG links from HTML XLink attributes (#2480)
* fix(browser): respect SVG desc and title HTML integration points * fix(browser): preserve moved SVG XLink destinations * fix(browser): bound concurrent SVG identity reads
This commit is contained in:
@@ -17,8 +17,10 @@ import {
|
||||
captureFrames,
|
||||
captureResources,
|
||||
type CapturedResource,
|
||||
type DomCapture,
|
||||
mainFrameUrl,
|
||||
} from "./CdpCaptureDocuments.js";
|
||||
import { capturedSvgNodeKind } from "./CdpCaptureDomSvg.js";
|
||||
import {
|
||||
allowedSanitizedUrl,
|
||||
delayWithCancellation,
|
||||
@@ -52,7 +54,7 @@ interface CaptureState {
|
||||
interface CapturedSections {
|
||||
readonly attachedUrl: string;
|
||||
readonly frames: WebPageInspection["frames"];
|
||||
readonly dom: ReturnType<typeof captureDom>;
|
||||
readonly dom: DomCapture;
|
||||
readonly accessibility: ReturnType<typeof captureAccessibility>;
|
||||
readonly scripts: WebPageInspection["scripts"];
|
||||
readonly resources: WebPageInspection["resources"];
|
||||
@@ -260,9 +262,7 @@ const authorizeObservationWindow = async (
|
||||
throw new BrowserObservationError("inspect_web_page", "target_not_allowed");
|
||||
};
|
||||
|
||||
const capturePageDom = async (
|
||||
state: CaptureState,
|
||||
): Promise<ReturnType<typeof captureDom>> => {
|
||||
const capturePageDom = async (state: CaptureState): Promise<DomCapture> => {
|
||||
const { context, allowedOrigins } = state;
|
||||
const result = await context.connection.send(
|
||||
"DOMSnapshot.captureSnapshot",
|
||||
@@ -274,12 +274,56 @@ const capturePageDom = async (
|
||||
context.sessionId,
|
||||
context.signal,
|
||||
);
|
||||
return captureDom(
|
||||
const capture = captureDom(
|
||||
result,
|
||||
allowedOrigins,
|
||||
context.input,
|
||||
state.events.completeness,
|
||||
);
|
||||
let step = capture.next();
|
||||
let descriptionUnavailable = false;
|
||||
const pendingController = new AbortController();
|
||||
const signal =
|
||||
context.signal === undefined
|
||||
? pendingController.signal
|
||||
: AbortSignal.any([context.signal, pendingController.signal]);
|
||||
while (!step.done) {
|
||||
const pending = step.value.map(async (query) => {
|
||||
if (descriptionUnavailable) return undefined;
|
||||
try {
|
||||
return capturedSvgNodeKind(
|
||||
query,
|
||||
await context.connection.send(
|
||||
"DOM.describeNode",
|
||||
{ backendNodeId: query.backendNodeId, depth: 0 },
|
||||
context.sessionId,
|
||||
signal,
|
||||
),
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
// A detached node can disappear between snapshot and description.
|
||||
// Preserve partial metadata, but propagate transport/cancellation errors.
|
||||
if (!(cause instanceof CdpCommandRejection)) throw cause;
|
||||
if (cause.code === -32_601) descriptionUnavailable = true;
|
||||
else if (cause.code !== -32_000) throw cause;
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
try {
|
||||
// Promise.all preserves snapshot order even when CDP replies out of order.
|
||||
step = capture.next(await Promise.all(pending));
|
||||
} catch (cause: unknown) {
|
||||
// Stop and settle this bounded batch before the session can be detached.
|
||||
pendingController.abort();
|
||||
await Promise.allSettled(pending);
|
||||
throw cause;
|
||||
}
|
||||
}
|
||||
if (step.value.unresolvedSvgNodes > 0)
|
||||
state.limitations.push(
|
||||
`SVG identity was unavailable for ${String(step.value.unresolvedSvgNodes)} snapshotted XLink candidate nodes; their URL destinations remain unknown.`,
|
||||
);
|
||||
return step.value;
|
||||
};
|
||||
|
||||
const normalizedInspection = (
|
||||
|
||||
Reference in New Issue
Block a user