mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bb84d1c5b | ||
|
|
7f8b51a724 | ||
|
|
2fd1b9d8f1 | ||
|
|
ef27aa9832 | ||
|
|
e67e393434 | ||
|
|
7bccb84d5f | ||
|
|
f6d129b12e | ||
|
|
fc39bc4f8f | ||
|
|
05bee25b2f | ||
|
|
2778ab1eee |
+1
-18
@@ -5,24 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|||||||
|
|
||||||
Starting from 0.2.0, CLI / Extension / DSH Plugin share the same version number.
|
Starting from 0.2.0, CLI / Extension / DSH Plugin share the same version number.
|
||||||
|
|
||||||
## [0.2.1] - 2026-09-09
|
## [Unreleased]
|
||||||
|
|
||||||
### Changed
|
|
||||||
- DSH Plugin: clarified installation, configuration, profile restart, and upgrade instructions
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- CLI: reliable Windows self-updates, including executable replacement and daemon restart
|
|
||||||
- CLI: Windows named-pipe connection continuity and stale daemon process detection
|
|
||||||
- Windows installer: PowerShell 5.1 compatibility, path quoting, and staged executable replacement
|
|
||||||
- CLI / DSH Plugin: cancellation propagation and upload/download cleanup when the parent process exits
|
|
||||||
- Extension: tab ownership and session cleanup when agent tabs fail to open or borrowed tabs are returned or closed
|
|
||||||
- Extension: navigation recovery when other extensions restrict Chrome DevTools Protocol access
|
|
||||||
- Extension: background input filling, automatic append behavior, and verification of field values before reporting success
|
|
||||||
- Extension: match observed form state to the correct element after page changes
|
|
||||||
- Extension: UUID generation fallback for recording and overlays on insecure origins
|
|
||||||
- Browser locale matching for regional language variants
|
|
||||||
- DSH Plugin: observation state synchronization, thumbnail capture lifecycle, and stale preview cleanup
|
|
||||||
- DSH Plugin: removed the obsolete client runtime host dependency
|
|
||||||
|
|
||||||
## [0.2.0] - 2026-09-02
|
## [0.2.0] - 2026-09-02
|
||||||
|
|
||||||
|
|||||||
Generated
+2
-2
@@ -134,7 +134,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bsk"
|
name = "bsk"
|
||||||
version = "0.2.1"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
@@ -169,7 +169,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bsk-protocol"
|
name = "bsk-protocol"
|
||||||
version = "0.2.1"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"schemars",
|
"schemars",
|
||||||
"semver",
|
"semver",
|
||||||
|
|||||||
+2
-2
@@ -7,7 +7,7 @@ members = [
|
|||||||
default-members = ["crates/bsk-cli"]
|
default-members = ["crates/bsk-cli"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.2.1"
|
version = "0.2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.85"
|
rust-version = "1.85"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@@ -43,7 +43,7 @@ rand = "0.8"
|
|||||||
uuid = { version = "1", features = ["v4", "serde"] }
|
uuid = { version = "1", features = ["v4", "serde"] }
|
||||||
|
|
||||||
# Workspace crates (version required for `cargo publish` of dependents)
|
# Workspace crates (version required for `cargo publish` of dependents)
|
||||||
bsk-protocol = { version = "0.2.1", path = "crates/bsk-protocol" }
|
bsk-protocol = { version = "0.2.0", path = "crates/bsk-protocol" }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = "symbols"
|
strip = "symbols"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@browser-skill/extension",
|
"name": "@browser-skill/extension",
|
||||||
"version": "0.2.1",
|
"version": "0.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ import { rectPolygon } from "../geometry";
|
|||||||
import {
|
import {
|
||||||
projectSnapshotRect,
|
projectSnapshotRect,
|
||||||
screenshotPageRect,
|
screenshotPageRect,
|
||||||
snapshotCoordinates,
|
|
||||||
snapshotViewportRect,
|
snapshotViewportRect,
|
||||||
} from "../geometry/coordinate-types";
|
} from "../geometry/coordinate-types";
|
||||||
import { GeometryContext, snapshotLayoutScale } from "../geometry/frame-context";
|
import { GeometryContext } from "../geometry/frame-context";
|
||||||
import type { CdpRunner } from "../shared";
|
import type { CdpRunner } from "../shared";
|
||||||
|
|
||||||
const target = { tabId: 4 };
|
const target = { tabId: 4 };
|
||||||
@@ -23,11 +22,7 @@ const graph: CdpFrameGraph = {
|
|||||||
function driver() {
|
function driver() {
|
||||||
const send = vi.fn(async (_tab: number, method: string): Promise<object> => {
|
const send = vi.fn(async (_tab: number, method: string): Promise<object> => {
|
||||||
if (method === "Page.getLayoutMetrics")
|
if (method === "Page.getLayoutMetrics")
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1000, clientHeight: 1000 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 1000 },
|
|
||||||
};
|
|
||||||
if (method === "DOM.getBoxModel")
|
if (method === "DOM.getBoxModel")
|
||||||
return { model: { content: [52.5, 612.5, 427.5, 612.5, 427.5, 862.5, 52.5, 862.5] } };
|
return { model: { content: [52.5, 612.5, 427.5, 612.5, 427.5, 862.5, 52.5, 862.5] } };
|
||||||
if (method === "DOM.resolveNode") return { object: { objectId: "owner" } };
|
if (method === "DOM.resolveNode") return { object: { objectId: "owner" } };
|
||||||
@@ -40,63 +35,6 @@ function driver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("measurement geometry context", () => {
|
describe("measurement geometry context", () => {
|
||||||
it.each([0.8, 1, 1.25, 2])("normalizes snapshot layout units at scale %s", (scale) => {
|
|
||||||
const measured = snapshotLayoutScale({
|
|
||||||
visualViewport: { clientWidth: 997.25, zoom: 1.1 },
|
|
||||||
cssVisualViewport: { clientWidth: 997.25 / scale, zoom: 1.1 },
|
|
||||||
// Rounded layout dimensions must not supply the scale.
|
|
||||||
layoutViewport: { clientWidth: 997 },
|
|
||||||
cssLayoutViewport: { clientWidth: Math.floor(997.25 / scale) },
|
|
||||||
});
|
|
||||||
expect(measured).toBeCloseTo(scale, 12);
|
|
||||||
const coordinates = snapshotCoordinates(
|
|
||||||
{ scrollOffsetX: 80 * scale, scrollOffsetY: 200 * scale },
|
|
||||||
measured,
|
|
||||||
{ x: 999, y: 999 },
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
snapshotViewportRect(
|
|
||||||
[160 * scale, 320 * scale, 120 * scale, 40 * scale],
|
|
||||||
{ target },
|
|
||||||
coordinates,
|
|
||||||
)?.rect,
|
|
||||||
).toEqual({ x: 80, y: 120, width: 120, height: 40 });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("uses CSS root scroll only for missing snapshot offsets, without scaling it twice", () => {
|
|
||||||
const coordinates = snapshotCoordinates({ scrollOffsetX: 80 }, 2, { x: 999, y: 100 });
|
|
||||||
expect(snapshotViewportRect([200, 800, 240, 80], { target }, coordinates)?.rect).toEqual({
|
|
||||||
x: 60,
|
|
||||||
y: 300,
|
|
||||||
width: 120,
|
|
||||||
height: 40,
|
|
||||||
});
|
|
||||||
expect(snapshotCoordinates({ scrollOffsetX: 0 }, 2)).toBeNull();
|
|
||||||
expect(
|
|
||||||
snapshotCoordinates({ scrollOffsetX: NaN, scrollOffsetY: 0 }, 2, { x: 0, y: 0 }),
|
|
||||||
).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does not infer snapshot units from missing, invalid, or CSS-only metrics", () => {
|
|
||||||
expect(snapshotLayoutScale({ cssLayoutViewport: { clientWidth: 800 } })).toBeNull();
|
|
||||||
for (const raw of [0, -1, NaN, Infinity]) {
|
|
||||||
expect(
|
|
||||||
snapshotLayoutScale({
|
|
||||||
visualViewport: { clientWidth: raw },
|
|
||||||
cssVisualViewport: { clientWidth: 800 },
|
|
||||||
}),
|
|
||||||
).toBeNull();
|
|
||||||
}
|
|
||||||
expect(
|
|
||||||
snapshotLayoutScale({
|
|
||||||
visualViewport: { clientWidth: 0, clientHeight: 600 },
|
|
||||||
cssVisualViewport: { clientWidth: 0, clientHeight: 300 },
|
|
||||||
}),
|
|
||||||
).toBe(2);
|
|
||||||
expect(snapshotCoordinates({ scrollOffsetX: 0, scrollOffsetY: 0 }, null)).toBeNull();
|
|
||||||
expect(snapshotViewportRect([10, 20, 120, 40], { target }, null)).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("shares in-flight frame measurements, but never shares them with the next context", async () => {
|
it("shares in-flight frame measurements, but never shares them with the next context", async () => {
|
||||||
const cdp = driver();
|
const cdp = driver();
|
||||||
const context = new GeometryContext(cdp, 4);
|
const context = new GeometryContext(cdp, 4);
|
||||||
@@ -123,20 +61,14 @@ describe("measurement geometry context", () => {
|
|||||||
height: 1000,
|
height: 1000,
|
||||||
});
|
});
|
||||||
if (projection.status !== "available") throw new Error("expected available projection");
|
if (projection.status !== "available") throw new Error("expected available projection");
|
||||||
const input = snapshotViewportRect([17, 23, 120, 40], source, {
|
const input = snapshotViewportRect([17, 23, 120, 40], source, { x: 0, y: 0 });
|
||||||
layoutUnitsPerCssPixel: 1,
|
|
||||||
scrollCss: { x: 0, y: 0 },
|
|
||||||
});
|
|
||||||
expect(projectSnapshotRect(input!, projection.projection)).toEqual({
|
expect(projectSnapshotRect(input!, projection.projection)).toEqual({
|
||||||
x: 73.75,
|
x: 73.75,
|
||||||
y: 641.25,
|
y: 641.25,
|
||||||
width: 150,
|
width: 150,
|
||||||
height: 50,
|
height: 50,
|
||||||
});
|
});
|
||||||
const scrolled = snapshotViewportRect([17, 23, 120, 40], source, {
|
const scrolled = snapshotViewportRect([17, 23, 120, 40], source, { x: 0, y: 10 });
|
||||||
layoutUnitsPerCssPixel: 1,
|
|
||||||
scrollCss: { x: 0, y: 10 },
|
|
||||||
});
|
|
||||||
expect(projectSnapshotRect(scrolled!, projection.projection)?.y).toBe(628.75);
|
expect(projectSnapshotRect(scrolled!, projection.projection)?.y).toBe(628.75);
|
||||||
await context.snapshotProjection(source, 10, [], { width: 1000, height: 1000 });
|
await context.snapshotProjection(source, 10, [], { width: 1000, height: 1000 });
|
||||||
expect(cdp.calls.mock.calls.filter(([, method]) => method === "DOM.resolveNode")).toHaveLength(
|
expect(cdp.calls.mock.calls.filter(([, method]) => method === "DOM.resolveNode")).toHaveLength(
|
||||||
@@ -241,7 +173,7 @@ describe("measurement geometry context", () => {
|
|||||||
const input = snapshotViewportRect(
|
const input = snapshotViewportRect(
|
||||||
[30, 50, 120, 40],
|
[30, 50, 120, 40],
|
||||||
{ target, frameId: "main" },
|
{ target, frameId: "main" },
|
||||||
{ layoutUnitsPerCssPixel: 1, scrollCss: { x: 10, y: 20 } },
|
{ x: 10, y: 20 },
|
||||||
)!;
|
)!;
|
||||||
const projection = {
|
const projection = {
|
||||||
source: { target, frameId: "main" },
|
source: { target, frameId: "main" },
|
||||||
@@ -262,20 +194,8 @@ describe("measurement geometry context", () => {
|
|||||||
source: { target: { tabId: 5 }, frameId: "main" },
|
source: { target: { tabId: 5 }, frameId: "main" },
|
||||||
}),
|
}),
|
||||||
).toBeNull();
|
).toBeNull();
|
||||||
expect(
|
expect(snapshotViewportRect([0, 0, NaN, 40], { target }, { x: 0, y: 0 })).toBeNull();
|
||||||
snapshotViewportRect(
|
expect(snapshotViewportRect([0, 0, 10, 40], { target }, { x: Infinity, y: 0 })).toBeNull();
|
||||||
[0, 0, NaN, 40],
|
|
||||||
{ target },
|
|
||||||
{ layoutUnitsPerCssPixel: 1, scrollCss: { x: 0, y: 0 } },
|
|
||||||
),
|
|
||||||
).toBeNull();
|
|
||||||
expect(
|
|
||||||
snapshotViewportRect(
|
|
||||||
[0, 0, 10, 40],
|
|
||||||
{ target },
|
|
||||||
{ layoutUnitsPerCssPixel: 1, scrollCss: { x: Infinity, y: 0 } },
|
|
||||||
),
|
|
||||||
).toBeNull();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not turn a border quad or a failed owner read into a content projection", async () => {
|
it("does not turn a border quad or a failed owner read into a content projection", async () => {
|
||||||
@@ -308,7 +228,7 @@ describe("measurement geometry context", () => {
|
|||||||
const input = snapshotViewportRect(
|
const input = snapshotViewportRect(
|
||||||
[0, 0, 300, 200],
|
[0, 0, 300, 200],
|
||||||
{ target, frameId: "nested" },
|
{ target, frameId: "nested" },
|
||||||
{ layoutUnitsPerCssPixel: 1, scrollCss: { x: 0, y: 0 } },
|
{ x: 0, y: 0 },
|
||||||
);
|
);
|
||||||
expect(projectSnapshotRect(input!, projection.projection)).toEqual({
|
expect(projectSnapshotRect(input!, projection.projection)).toEqual({
|
||||||
x: 60,
|
x: 60,
|
||||||
@@ -358,11 +278,7 @@ describe("measurement geometry context", () => {
|
|||||||
peak = Math.max(peak, active);
|
peak = Math.max(peak, active);
|
||||||
await new Promise<void>((resolve) => release.push(resolve));
|
await new Promise<void>((resolve) => release.push(resolve));
|
||||||
active--;
|
active--;
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 100, clientHeight: 100 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 100, clientHeight: 100 },
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const context = new GeometryContext(
|
const context = new GeometryContext(
|
||||||
|
|||||||
@@ -65,11 +65,7 @@ function makeFakeCdp(handlers: Record<string, (params?: object) => unknown>) {
|
|||||||
sent.push({ method, params });
|
sent.push({ method, params });
|
||||||
const handler = handlers[method];
|
const handler = handlers[method];
|
||||||
if (!handler && method === "Page.getLayoutMetrics") {
|
if (!handler && method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1280, clientHeight: 720 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1280, clientHeight: 720 },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (!handler) throw new Error(`unexpected CDP call ${method}`);
|
if (!handler) throw new Error(`unexpected CDP call ${method}`);
|
||||||
return handler(params);
|
return handler(params);
|
||||||
@@ -2552,11 +2548,7 @@ describe("handleSnapshot", () => {
|
|||||||
if (method === "Accessibility.enable") return {};
|
if (method === "Accessibility.enable") return {};
|
||||||
if (method === "Accessibility.getFullAXTree") return { nodes };
|
if (method === "Accessibility.getFullAXTree") return { nodes };
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (method === "DOMSnapshot.enable") return {};
|
if (method === "DOMSnapshot.enable") return {};
|
||||||
if (method === "DOMSnapshot.captureSnapshot") throw new Error("snapshot unsupported");
|
if (method === "DOMSnapshot.captureSnapshot") throw new Error("snapshot unsupported");
|
||||||
@@ -2643,11 +2635,7 @@ describe("handleSnapshot", () => {
|
|||||||
if (method === "Accessibility.enable") return {};
|
if (method === "Accessibility.enable") return {};
|
||||||
if (method === "Accessibility.getFullAXTree") return { nodes: [root, button] };
|
if (method === "Accessibility.getFullAXTree") return { nodes: [root, button] };
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (method === "DOMSnapshot.enable") return {};
|
if (method === "DOMSnapshot.enable") return {};
|
||||||
if (method === "DOMSnapshot.captureSnapshot") {
|
if (method === "DOMSnapshot.captureSnapshot") {
|
||||||
@@ -2738,11 +2726,7 @@ describe("handleSnapshot", () => {
|
|||||||
if (method === "Accessibility.enable") return {};
|
if (method === "Accessibility.enable") return {};
|
||||||
if (method === "Accessibility.getFullAXTree") return { nodes: [root, button] };
|
if (method === "Accessibility.getFullAXTree") return { nodes: [root, button] };
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (method === "DOMSnapshot.enable") return {};
|
if (method === "DOMSnapshot.enable") return {};
|
||||||
if (method === "DOMSnapshot.captureSnapshot") {
|
if (method === "DOMSnapshot.captureSnapshot") {
|
||||||
@@ -2836,11 +2820,7 @@ describe("handleSnapshot", () => {
|
|||||||
if (method === "Accessibility.enable") return {};
|
if (method === "Accessibility.enable") return {};
|
||||||
if (method === "Accessibility.getFullAXTree") return { nodes: [root, button] };
|
if (method === "Accessibility.getFullAXTree") return { nodes: [root, button] };
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (method === "DOMSnapshot.enable") return {};
|
if (method === "DOMSnapshot.enable") return {};
|
||||||
if (method === "DOMSnapshot.captureSnapshot") {
|
if (method === "DOMSnapshot.captureSnapshot") {
|
||||||
@@ -3005,11 +2985,7 @@ describe("handleSnapshot", () => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1000, clientHeight: 800 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800 },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (method === "DOMSnapshot.enable") return {};
|
if (method === "DOMSnapshot.enable") return {};
|
||||||
if (method === "DOMSnapshot.captureSnapshot") {
|
if (method === "DOMSnapshot.captureSnapshot") {
|
||||||
@@ -3222,8 +3198,6 @@ describe("handleSnapshot", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const VP_METRICS = {
|
const VP_METRICS = {
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -3237,8 +3211,6 @@ describe("handleSnapshot", () => {
|
|||||||
strings,
|
strings,
|
||||||
documents: [
|
documents: [
|
||||||
{
|
{
|
||||||
scrollOffsetX: 0,
|
|
||||||
scrollOffsetY: 0,
|
|
||||||
frameId: "main",
|
frameId: "main",
|
||||||
nodes: {
|
nodes: {
|
||||||
parentIndex: [-1, 0, 1],
|
parentIndex: [-1, 0, 1],
|
||||||
@@ -3259,8 +3231,6 @@ describe("handleSnapshot", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
scrollOffsetX: 0,
|
|
||||||
scrollOffsetY: 0,
|
|
||||||
frameId: "child",
|
frameId: "child",
|
||||||
nodes: {
|
nodes: {
|
||||||
parentIndex: [-1, 0, 1],
|
parentIndex: [-1, 0, 1],
|
||||||
@@ -3572,7 +3542,7 @@ describe("handleSnapshot", () => {
|
|||||||
maxTokens,
|
maxTokens,
|
||||||
});
|
});
|
||||||
expect(result.text.match(/@warning/g)).toHaveLength(1);
|
expect(result.text.match(/@warning/g)).toHaveLength(1);
|
||||||
expect(result.text).toContain("geometry incomplete");
|
expect(result.text).toContain("iframe geometry incomplete");
|
||||||
expect(result.text.startsWith("@vom 1\n")).toBe(true);
|
expect(result.text.startsWith("@vom 1\n")).toBe(true);
|
||||||
if (maxTokens === undefined) {
|
if (maxTokens === undefined) {
|
||||||
expect(result.truncated).toBe(false);
|
expect(result.truncated).toBe(false);
|
||||||
|
|||||||
@@ -1,237 +0,0 @@
|
|||||||
// @vitest-environment node
|
|
||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import type { CdpFrame, CdpFrameGraph, CdpTarget } from "@/browser-driver/frame-graph";
|
|
||||||
import { GeometryContext } from "../geometry/frame-context";
|
|
||||||
import type { CdpRunner } from "../shared";
|
|
||||||
import { captureViewModel } from "../vom/capture";
|
|
||||||
import { captureFrameData } from "../vom/frame-capture";
|
|
||||||
|
|
||||||
type Send = <T = Record<string, unknown>>(
|
|
||||||
method: string,
|
|
||||||
params?: object,
|
|
||||||
sessionId?: string,
|
|
||||||
) => Promise<T>;
|
|
||||||
type Tree = { frame: { id: string; parentId?: string; name?: string }; childFrames?: Tree[] };
|
|
||||||
type Rect = { x: number; y: number; w: number; h: number };
|
|
||||||
type Oracle = { probe: Rect; owners: Record<string, { x: number; y: number; scale: number }> };
|
|
||||||
|
|
||||||
// The independent oracle uses DOM border boxes and this fixture's axis-aligned
|
|
||||||
// iframe transforms. No production snapshot conversion/projection builds expectations.
|
|
||||||
const oracleExpression = `(() => {
|
|
||||||
const box = document.querySelector('#probe').getBoundingClientRect();
|
|
||||||
const owners = {};
|
|
||||||
for (const frame of document.querySelectorAll('iframe')) {
|
|
||||||
const rect = frame.getBoundingClientRect();
|
|
||||||
const style = getComputedStyle(frame);
|
|
||||||
const scale = rect.width / frame.offsetWidth;
|
|
||||||
owners[frame.name] = {
|
|
||||||
x: rect.x + (frame.clientLeft + parseFloat(style.paddingLeft)) * scale,
|
|
||||||
y: rect.y + (frame.clientTop + parseFloat(style.paddingTop)) * scale,
|
|
||||||
scale,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return { probe: { x: box.x, y: box.y, w: box.width, h: box.height }, owners };
|
|
||||||
})()`;
|
|
||||||
|
|
||||||
describe.skipIf(!process.env.BSK_GEOMETRY_CHROME)("real DOMSnapshot coordinate contract", () => {
|
|
||||||
it.each([
|
|
||||||
{ deviceScale: 1, zoom: 1 },
|
|
||||||
{ deviceScale: 0.8, zoom: 1 },
|
|
||||||
{ deviceScale: 1, zoom: 1.25 },
|
|
||||||
{ deviceScale: 2, zoom: 1 },
|
|
||||||
{ deviceScale: 2, zoom: 0.8 },
|
|
||||||
])("matches DOM geometry at device scale $deviceScale and zoom $zoom", async (configuration) => {
|
|
||||||
const evalRoot = new URL("../../../../../evals/browser/", import.meta.url);
|
|
||||||
const { createEvalServer } = await import(new URL("lib/server.mjs", evalRoot).href);
|
|
||||||
const { withChrome } = await import(
|
|
||||||
new URL("cases/regression/snapshot-coordinates/chrome.mjs", evalRoot).href
|
|
||||||
);
|
|
||||||
const server = createEvalServer();
|
|
||||||
const { baseUrl } = await server.start();
|
|
||||||
try {
|
|
||||||
await withChrome(
|
|
||||||
{ executable: process.env.BSK_GEOMETRY_CHROME, ...configuration },
|
|
||||||
async (send: Send) => {
|
|
||||||
const { targetId } = await send<{ targetId: string }>("Target.createTarget", {
|
|
||||||
url: "about:blank",
|
|
||||||
});
|
|
||||||
const { sessionId: rootSession } = await send<{ sessionId: string }>(
|
|
||||||
"Target.attachToTarget",
|
|
||||||
{ targetId, flatten: true },
|
|
||||||
);
|
|
||||||
await send(
|
|
||||||
"Page.navigate",
|
|
||||||
{ url: `${baseUrl}/snapshot-coordinates?run=coordinates` },
|
|
||||||
rootSession,
|
|
||||||
);
|
|
||||||
await expect
|
|
||||||
.poll(
|
|
||||||
() =>
|
|
||||||
server
|
|
||||||
.snapshot("coordinates")
|
|
||||||
.events.some(
|
|
||||||
(event: { type: string; data: { root?: boolean } }) =>
|
|
||||||
event.type === "geometry.ready" && event.data.root,
|
|
||||||
),
|
|
||||||
{ timeout: 10_000 },
|
|
||||||
)
|
|
||||||
.toBe(true);
|
|
||||||
|
|
||||||
const targets = await send<{ targetInfos: { targetId: string; type: string }[] }>(
|
|
||||||
"Target.getTargets",
|
|
||||||
);
|
|
||||||
const sessions = [rootSession];
|
|
||||||
for (const target of targets.targetInfos.filter((target) => target.type === "iframe")) {
|
|
||||||
const { sessionId } = await send<{ sessionId: string }>("Target.attachToTarget", {
|
|
||||||
targetId: target.targetId,
|
|
||||||
flatten: true,
|
|
||||||
});
|
|
||||||
sessions.push(sessionId);
|
|
||||||
}
|
|
||||||
expect(sessions.length).toBe(2); // The cross-site fixture must actually be an OOPIF.
|
|
||||||
const frames: CdpFrame[] = [];
|
|
||||||
const names = new Map<string, string>();
|
|
||||||
const sessionFor = (target: CdpTarget) => target.sessionId ?? rootSession;
|
|
||||||
for (const sessionId of sessions) {
|
|
||||||
const { frameTree } = await send<{ frameTree: Tree }>(
|
|
||||||
"Page.getFrameTree",
|
|
||||||
{},
|
|
||||||
sessionId,
|
|
||||||
);
|
|
||||||
const target: CdpTarget = {
|
|
||||||
tabId: 1,
|
|
||||||
...(sessionId === rootSession ? {} : { sessionId }),
|
|
||||||
};
|
|
||||||
const visit = (tree: Tree, parentFrameId = tree.frame.parentId) => {
|
|
||||||
frames.push({ frameId: tree.frame.id, parentFrameId, target });
|
|
||||||
names.set(tree.frame.id, tree.frame.name ?? "");
|
|
||||||
for (const child of tree.childFrames ?? []) visit(child, tree.frame.id);
|
|
||||||
};
|
|
||||||
visit(frameTree);
|
|
||||||
}
|
|
||||||
expect(frames).toHaveLength(5);
|
|
||||||
for (const frame of frames) {
|
|
||||||
if (!frame.parentFrameId) continue;
|
|
||||||
const parent = frames.find((item) => item.frameId === frame.parentFrameId)!;
|
|
||||||
const owner = await send<{ backendNodeId: number }>(
|
|
||||||
"DOM.getFrameOwner",
|
|
||||||
{ frameId: frame.frameId },
|
|
||||||
sessionFor(parent.target),
|
|
||||||
);
|
|
||||||
frame.ownerBackendNodeId = owner.backendNodeId;
|
|
||||||
}
|
|
||||||
const graph: CdpFrameGraph = { rootFrameId: frames[0].frameId, frames };
|
|
||||||
const calls: string[] = [];
|
|
||||||
const cdp: CdpRunner = {
|
|
||||||
send: (tabId, method, params) => {
|
|
||||||
calls.push(`${tabId}:${method}`);
|
|
||||||
return send(method, params, rootSession);
|
|
||||||
},
|
|
||||||
sendToTarget: (target, method, params) => {
|
|
||||||
calls.push(`${target.sessionId ?? target.tabId}:${method}`);
|
|
||||||
return send(method, params, sessionFor(target));
|
|
||||||
},
|
|
||||||
getFrameGraph: async () => graph,
|
|
||||||
};
|
|
||||||
const oracles = new Map<string, Oracle>();
|
|
||||||
for (const frame of frames) {
|
|
||||||
const session = sessionFor(frame.target);
|
|
||||||
const { executionContextId } = await send<{ executionContextId: number }>(
|
|
||||||
"Page.createIsolatedWorld",
|
|
||||||
{ frameId: frame.frameId, worldName: "coordinate-oracle" },
|
|
||||||
session,
|
|
||||||
);
|
|
||||||
await expect
|
|
||||||
.poll(
|
|
||||||
async () => {
|
|
||||||
const ready = await send<{ result: { value: boolean } }>(
|
|
||||||
"Runtime.evaluate",
|
|
||||||
{
|
|
||||||
expression: 'document.documentElement.dataset.geometryReady === "true"',
|
|
||||||
contextId: executionContextId,
|
|
||||||
returnByValue: true,
|
|
||||||
},
|
|
||||||
session,
|
|
||||||
);
|
|
||||||
return ready.result.value;
|
|
||||||
},
|
|
||||||
{ timeout: 5_000 },
|
|
||||||
)
|
|
||||||
.toBe(true);
|
|
||||||
// Establish scroll after cross-process target creation/layout settles.
|
|
||||||
const scroll = frame.parentFrameId
|
|
||||||
? names.get(frame.frameId) === "nested"
|
|
||||||
? [10, 20]
|
|
||||||
: [40, 100]
|
|
||||||
: [80, 240];
|
|
||||||
await send(
|
|
||||||
"Runtime.evaluate",
|
|
||||||
{
|
|
||||||
expression: `(async () => { scrollTo(${scroll.join(",")}); await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); })()`,
|
|
||||||
contextId: executionContextId,
|
|
||||||
awaitPromise: true,
|
|
||||||
},
|
|
||||||
session,
|
|
||||||
);
|
|
||||||
const reply = await send<{ result: { value: Oracle } }>(
|
|
||||||
"Runtime.evaluate",
|
|
||||||
{ expression: oracleExpression, contextId: executionContextId, returnByValue: true },
|
|
||||||
session,
|
|
||||||
);
|
|
||||||
oracles.set(frame.frameId, reply.result.value);
|
|
||||||
}
|
|
||||||
const geometry = new GeometryContext(cdp, 1, graph);
|
|
||||||
const captured = await captureViewModel(cdp, 1, { geometry });
|
|
||||||
await captureFrameData(cdp, 1, captured, undefined, geometry);
|
|
||||||
expect(captured.frameGeometryIssues).toEqual([]);
|
|
||||||
for (const frame of frames) {
|
|
||||||
const node = captured.frameNodes
|
|
||||||
?.get(frame.frameId)
|
|
||||||
?.find((node) => node.attrs.id === "probe");
|
|
||||||
expect(node, `missing probe in ${names.get(frame.frameId) || "root"}`).toBeDefined();
|
|
||||||
const local = oracles.get(frame.frameId)!.probe;
|
|
||||||
const top = { ...local };
|
|
||||||
let current = frame;
|
|
||||||
while (current.parentFrameId) {
|
|
||||||
const owner = oracles.get(current.parentFrameId)!.owners[names.get(current.frameId)!];
|
|
||||||
top.x = owner.x + top.x * owner.scale;
|
|
||||||
top.y = owner.y + top.y * owner.scale;
|
|
||||||
top.w *= owner.scale;
|
|
||||||
top.h *= owner.scale;
|
|
||||||
current = frames.find((item) => item.frameId === current.parentFrameId)!;
|
|
||||||
}
|
|
||||||
expect(
|
|
||||||
node!.rect,
|
|
||||||
JSON.stringify({
|
|
||||||
frame: names.get(frame.frameId),
|
|
||||||
local,
|
|
||||||
top,
|
|
||||||
viewport: captured.viewport,
|
|
||||||
}),
|
|
||||||
).not.toBeNull();
|
|
||||||
for (const key of ["x", "y", "w", "h"] as const) {
|
|
||||||
expect(
|
|
||||||
Math.abs(node!.localRect![key] - local[key]),
|
|
||||||
`${names.get(frame.frameId)} local ${key}`,
|
|
||||||
).toBeLessThan(2);
|
|
||||||
expect(
|
|
||||||
Math.abs(node!.rect![key] - top[key]),
|
|
||||||
`${names.get(frame.frameId)} top ${key}`,
|
|
||||||
).toBeLessThan(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(calls.filter((call) => call.endsWith(":Page.getLayoutMetrics"))).toHaveLength(
|
|
||||||
sessions.length,
|
|
||||||
);
|
|
||||||
const metrics = await send<{
|
|
||||||
cssVisualViewport: { zoom: number };
|
|
||||||
visualViewport: { clientWidth: number };
|
|
||||||
}>("Page.getLayoutMetrics", {}, rootSession);
|
|
||||||
expect(metrics.cssVisualViewport.zoom).toBeCloseTo(configuration.zoom, 4);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
await server.stop();
|
|
||||||
}
|
|
||||||
}, 30_000);
|
|
||||||
});
|
|
||||||
@@ -25,12 +25,6 @@ export interface UnavailableFrameProjection {
|
|||||||
ownerBackendNodeId: number;
|
ownerBackendNodeId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UnavailableSnapshotCoordinates {
|
|
||||||
status: "unavailable";
|
|
||||||
source: CoordinateOwner;
|
|
||||||
reason: "snapshot-coordinates-unavailable";
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SnapshotProjectionResult =
|
export type SnapshotProjectionResult =
|
||||||
| { status: "available"; projection: SnapshotProjection }
|
| { status: "available"; projection: SnapshotProjection }
|
||||||
| UnavailableFrameProjection;
|
| UnavailableFrameProjection;
|
||||||
@@ -38,74 +32,25 @@ export type SnapshotProjectionResult =
|
|||||||
/** Descendants inherit the failed boundary without attempting another owner read. */
|
/** Descendants inherit the failed boundary without attempting another owner read. */
|
||||||
export type FrameProjectionIssue =
|
export type FrameProjectionIssue =
|
||||||
| UnavailableFrameProjection
|
| UnavailableFrameProjection
|
||||||
| UnavailableSnapshotCoordinates
|
| { status: "blocked"; source: CoordinateOwner; cause: UnavailableFrameProjection };
|
||||||
| {
|
|
||||||
status: "blocked";
|
|
||||||
source: CoordinateOwner;
|
|
||||||
cause: UnavailableFrameProjection | UnavailableSnapshotCoordinates;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type FrameProjectionState = SnapshotProjectionResult | FrameProjectionIssue;
|
export type FrameProjectionState = SnapshotProjectionResult | FrameProjectionIssue;
|
||||||
|
|
||||||
export interface SnapshotCoordinates {
|
/** DOMSnapshot bounds are document-relative CSS pixels, independent of raster DPR. */
|
||||||
layoutUnitsPerCssPixel: number;
|
|
||||||
scrollCss: { x: number; y: number };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Snapshot scroll offsets share the raw layout units of its bounds. Only a
|
|
||||||
* target's root document may fall back to that target's CSS layout viewport. */
|
|
||||||
export function snapshotCoordinates(
|
|
||||||
document: { scrollOffsetX?: number; scrollOffsetY?: number },
|
|
||||||
layoutUnitsPerCssPixel: number | null,
|
|
||||||
rootScrollCss?: { x?: number; y?: number },
|
|
||||||
): SnapshotCoordinates | null {
|
|
||||||
if (
|
|
||||||
layoutUnitsPerCssPixel === null ||
|
|
||||||
!Number.isFinite(layoutUnitsPerCssPixel) ||
|
|
||||||
layoutUnitsPerCssPixel <= 0
|
|
||||||
)
|
|
||||||
return null;
|
|
||||||
const x =
|
|
||||||
document.scrollOffsetX === undefined
|
|
||||||
? rootScrollCss?.x
|
|
||||||
: document.scrollOffsetX / layoutUnitsPerCssPixel;
|
|
||||||
const y =
|
|
||||||
document.scrollOffsetY === undefined
|
|
||||||
? rootScrollCss?.y
|
|
||||||
: document.scrollOffsetY / layoutUnitsPerCssPixel;
|
|
||||||
if (x === undefined || y === undefined || !Number.isFinite(x) || !Number.isFinite(y)) return null;
|
|
||||||
return { layoutUnitsPerCssPixel, scrollCss: { x, y } };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Convert raw document-relative Blink layout units exactly once, before any
|
|
||||||
* CSS viewport clipping or frame projection. This scale is not screenshot zoom. */
|
|
||||||
export function snapshotViewportRect(
|
export function snapshotViewportRect(
|
||||||
bounds: number[],
|
bounds: number[],
|
||||||
owner: CoordinateOwner,
|
owner: CoordinateOwner,
|
||||||
coordinates: SnapshotCoordinates | null,
|
scroll: { x: number; y: number },
|
||||||
): FrameViewportRect | null {
|
): FrameViewportRect | null {
|
||||||
if (!coordinates || bounds.length < 4 || !bounds.slice(0, 4).every(Number.isFinite)) return null;
|
if (bounds.length < 4 || !bounds.slice(0, 4).every(Number.isFinite)) return null;
|
||||||
const { layoutUnitsPerCssPixel: scale, scrollCss: scroll } = coordinates;
|
|
||||||
const [x, y, width, height] = bounds;
|
const [x, y, width, height] = bounds;
|
||||||
if (
|
if (width <= 0 || height <= 0 || !Number.isFinite(scroll.x) || !Number.isFinite(scroll.y)) {
|
||||||
!Number.isFinite(scale) ||
|
|
||||||
scale <= 0 ||
|
|
||||||
width <= 0 ||
|
|
||||||
height <= 0 ||
|
|
||||||
!Number.isFinite(scroll.x) ||
|
|
||||||
!Number.isFinite(scroll.y)
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
space: "frame-viewport-css",
|
space: "frame-viewport-css",
|
||||||
owner,
|
owner,
|
||||||
rect: {
|
rect: { x: x - scroll.x, y: y - scroll.y, width, height },
|
||||||
x: x / scale - scroll.x,
|
|
||||||
y: y / scale - scroll.y,
|
|
||||||
width: width / scale,
|
|
||||||
height: height / scale,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ import type { CoordinateOwner, CssViewport, SnapshotProjectionResult } from "./c
|
|||||||
import { readSnapshotOwnerSizes } from "./snapshot-owner-sizes";
|
import { readSnapshotOwnerSizes } from "./snapshot-owner-sizes";
|
||||||
|
|
||||||
export interface LayoutMetrics {
|
export interface LayoutMetrics {
|
||||||
cssVisualViewport?: { zoom?: number; clientWidth?: number; clientHeight?: number };
|
cssVisualViewport?: { zoom?: number };
|
||||||
visualViewport?: { zoom?: number; clientWidth?: number; clientHeight?: number };
|
visualViewport?: { zoom?: number };
|
||||||
cssLayoutViewport?: {
|
cssLayoutViewport?: {
|
||||||
clientWidth?: number;
|
clientWidth?: number;
|
||||||
clientHeight?: number;
|
clientHeight?: number;
|
||||||
@@ -29,29 +29,6 @@ export interface LayoutMetrics {
|
|||||||
layoutViewport?: { clientWidth?: number; clientHeight?: number; pageX?: number; pageY?: number };
|
layoutViewport?: { clientWidth?: number; clientHeight?: number; pageX?: number; pageY?: number };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Chromium emits these paired floating-point dimensions before/after dividing
|
|
||||||
* by LayoutZoomFactor. Integer layout viewport dimensions lose precision at
|
|
||||||
* fractional zoom. Neither visualViewport.scale nor .zoom is this conversion.
|
|
||||||
* See InspectorPageAgent::getLayoutMetrics in Chromium. */
|
|
||||||
export function snapshotLayoutScale(metrics: LayoutMetrics): number | null {
|
|
||||||
for (const dimension of ["clientWidth", "clientHeight"] as const) {
|
|
||||||
const raw = metrics.visualViewport?.[dimension];
|
|
||||||
const css = metrics.cssVisualViewport?.[dimension];
|
|
||||||
if (
|
|
||||||
raw !== undefined &&
|
|
||||||
css !== undefined &&
|
|
||||||
Number.isFinite(raw) &&
|
|
||||||
Number.isFinite(css) &&
|
|
||||||
raw > 0 &&
|
|
||||||
css > 0
|
|
||||||
) {
|
|
||||||
const scale = raw / css;
|
|
||||||
if (Number.isFinite(scale) && scale > 0) return scale;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The legacy field is a compatibility fallback, never a source of raster DPR. */
|
/** The legacy field is a compatibility fallback, never a source of raster DPR. */
|
||||||
export function cssViewport(metrics: LayoutMetrics): CssViewport {
|
export function cssViewport(metrics: LayoutMetrics): CssViewport {
|
||||||
const value = metrics.cssLayoutViewport ?? metrics.layoutViewport;
|
const value = metrics.cssLayoutViewport ?? metrics.layoutViewport;
|
||||||
|
|||||||
@@ -1138,7 +1138,7 @@ export async function captureVomObservation(
|
|||||||
// Reserve space using the renderer's character-based token estimate. Like VOM
|
// Reserve space using the renderer's character-based token estimate. Like VOM
|
||||||
// headers, this integrity notice remains visible even under a tiny token budget.
|
// headers, this integrity notice remains visible even under a tiny token budget.
|
||||||
const geometryNotice = captured.frameGeometryIssues?.length
|
const geometryNotice = captured.frameGeometryIssues?.length
|
||||||
? "@warning geometry incomplete: some page or frame content has no top-level coordinates.\n"
|
? "@warning iframe geometry incomplete: some frame content has no top-level coordinates.\n"
|
||||||
: "";
|
: "";
|
||||||
const rendered = renderVom(decoratedScene, {
|
const rendered = renderVom(decoratedScene, {
|
||||||
maxDepth: options.maxDepth,
|
maxDepth: options.maxDepth,
|
||||||
|
|||||||
@@ -211,11 +211,7 @@ function makeCdp(snapshot: unknown) {
|
|||||||
if (method === "DOMSnapshot.enable") return {};
|
if (method === "DOMSnapshot.enable") return {};
|
||||||
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (method === "Runtime.evaluate") {
|
if (method === "Runtime.evaluate") {
|
||||||
return {
|
return {
|
||||||
@@ -303,8 +299,6 @@ describe("captureViewModel", () => {
|
|||||||
if (method === "DOMSnapshot.captureSnapshot") return hoverTriggerSnapshotReply();
|
if (method === "DOMSnapshot.captureSnapshot") return hoverTriggerSnapshotReply();
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return {
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -368,8 +362,6 @@ describe("captureViewModel", () => {
|
|||||||
if (method === "DOMSnapshot.captureSnapshot") return twoHoverTriggerSnapshotReply();
|
if (method === "DOMSnapshot.captureSnapshot") return twoHoverTriggerSnapshotReply();
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return {
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -418,8 +410,6 @@ describe("captureViewModel", () => {
|
|||||||
if (method === "DOMSnapshot.captureSnapshot") return nestedHoverTriggerSnapshotReply();
|
if (method === "DOMSnapshot.captureSnapshot") return nestedHoverTriggerSnapshotReply();
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return {
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -538,8 +528,6 @@ describe("captureViewModel", () => {
|
|||||||
strings: S,
|
strings: S,
|
||||||
documents: [
|
documents: [
|
||||||
{
|
{
|
||||||
scrollOffsetX: 0,
|
|
||||||
scrollOffsetY: 0,
|
|
||||||
frameId: "main",
|
frameId: "main",
|
||||||
nodes: {
|
nodes: {
|
||||||
parentIndex: [-1, 0, 1, 0, 3, 4],
|
parentIndex: [-1, 0, 1, 0, 3, 4],
|
||||||
@@ -760,8 +748,6 @@ describe("captureViewModel", () => {
|
|||||||
if (method === "DOMSnapshot.captureSnapshot") return fakeSnapshotReply();
|
if (method === "DOMSnapshot.captureSnapshot") return fakeSnapshotReply();
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return {
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 200 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 200 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -774,46 +760,7 @@ describe("captureViewModel", () => {
|
|||||||
expect(div?.rect).toMatchObject({ y: 0, h: 600 });
|
expect(div?.rect).toMatchObject({ y: 0, h: 600 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("normalizes snapshot-owned scroll before using a stale CSS metrics fallback", async () => {
|
it("keeps CSS snapshot bounds independent of legacy metrics ratio", async () => {
|
||||||
const snapshot = {
|
|
||||||
strings: ["html", "button"],
|
|
||||||
documents: [
|
|
||||||
{
|
|
||||||
frameId: "root",
|
|
||||||
scrollOffsetX: 40,
|
|
||||||
scrollOffsetY: 200,
|
|
||||||
nodes: {
|
|
||||||
parentIndex: [-1, 0],
|
|
||||||
nodeName: [0, 1],
|
|
||||||
backendNodeId: [10, 11],
|
|
||||||
attributes: [[], []],
|
|
||||||
},
|
|
||||||
layout: { nodeIndex: [1], bounds: [[200, 800, 240, 80]] },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
const cdp: CdpRunner = {
|
|
||||||
send: vi.fn(async (_tab: number, method: string) => {
|
|
||||||
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
|
||||||
if (method === "Page.getLayoutMetrics")
|
|
||||||
return {
|
|
||||||
visualViewport: { clientWidth: 2000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 999, pageY: 999 },
|
|
||||||
};
|
|
||||||
return {};
|
|
||||||
}) as CdpRunner["send"],
|
|
||||||
};
|
|
||||||
const captured = await captureViewModel(cdp, 4);
|
|
||||||
expect(captured.nodes.find((node) => node.backendNodeId === 11)).toMatchObject({
|
|
||||||
localRect: { x: 80, y: 300, w: 120, h: 40 },
|
|
||||||
rect: { x: 80, y: 300, w: 120, h: 40 },
|
|
||||||
rendered: true,
|
|
||||||
});
|
|
||||||
expect(captured.frameGeometryIssues).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("normalizes raw snapshot bounds before viewport clipping", async () => {
|
|
||||||
const S = ["html", "body", "div", "position", "fixed", "static", "pointer-events", "auto"];
|
const S = ["html", "body", "div", "position", "fixed", "static", "pointer-events", "auto"];
|
||||||
const i = (s: string) => S.indexOf(s);
|
const i = (s: string) => S.indexOf(s);
|
||||||
const snapshot = {
|
const snapshot = {
|
||||||
@@ -847,8 +794,6 @@ describe("captureViewModel", () => {
|
|||||||
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return {
|
||||||
visualViewport: { clientWidth: 2000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
||||||
layoutViewport: { clientWidth: 2000, clientHeight: 1600 },
|
layoutViewport: { clientWidth: 2000, clientHeight: 1600 },
|
||||||
};
|
};
|
||||||
@@ -866,8 +811,8 @@ describe("captureViewModel", () => {
|
|||||||
expect(nodes.find((n) => n.backendNodeId === 12)?.localRect).toEqual({
|
expect(nodes.find((n) => n.backendNodeId === 12)?.localRect).toEqual({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
w: 1000,
|
w: 2000,
|
||||||
h: 800,
|
h: 1600,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -924,8 +869,6 @@ describe("captureViewModel", () => {
|
|||||||
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return {
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1016,8 +959,6 @@ describe("captureViewModel", () => {
|
|||||||
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return {
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1114,8 +1055,6 @@ describe("captureViewModel", () => {
|
|||||||
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return {
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1175,8 +1114,6 @@ describe("captureViewModel", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
scrollOffsetX: 0,
|
|
||||||
scrollOffsetY: 0,
|
|
||||||
nodes: {
|
nodes: {
|
||||||
parentIndex: [-1, 0, 1],
|
parentIndex: [-1, 0, 1],
|
||||||
nodeName: [i("html"), i("body"), i("iframe")],
|
nodeName: [i("html"), i("body"), i("iframe")],
|
||||||
@@ -1198,8 +1135,6 @@ describe("captureViewModel", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
scrollOffsetX: 0,
|
|
||||||
scrollOffsetY: 0,
|
|
||||||
nodes: {
|
nodes: {
|
||||||
parentIndex: [-1, 0],
|
parentIndex: [-1, 0],
|
||||||
nodeName: [i("body"), i("input")],
|
nodeName: [i("body"), i("input")],
|
||||||
@@ -1226,8 +1161,6 @@ describe("captureViewModel", () => {
|
|||||||
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return {
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 0 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1302,8 +1235,6 @@ describe("captureViewModel", () => {
|
|||||||
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return {
|
||||||
visualViewport: { clientWidth: 2000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 100 },
|
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800, pageX: 0, pageY: 100 },
|
||||||
layoutViewport: { clientWidth: 2000, clientHeight: 1600 },
|
layoutViewport: { clientWidth: 2000, clientHeight: 1600 },
|
||||||
};
|
};
|
||||||
@@ -1312,7 +1243,7 @@ describe("captureViewModel", () => {
|
|||||||
}) as unknown as <T>(tabId: number, method: string, params?: object) => Promise<T>,
|
}) as unknown as <T>(tabId: number, method: string, params?: object) => Promise<T>,
|
||||||
};
|
};
|
||||||
const { nodes } = await captureViewModel(cdp, 4);
|
const { nodes } = await captureViewModel(cdp, 4);
|
||||||
expect(nodes.find((n) => n.backendNodeId === 12)?.rect?.y).toBe(400 / 2 - 100);
|
expect(nodes.find((n) => n.backendNodeId === 12)?.rect?.y).toBe(400 - 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("collectOverlayExcludedBackendIds walks the pierced overlay host subtree", async () => {
|
it("collectOverlayExcludedBackendIds walks the pierced overlay host subtree", async () => {
|
||||||
@@ -1343,8 +1274,6 @@ function siblingCaptureFixture(
|
|||||||
beforeReply: (method: string, params: Record<string, unknown>) => Promise<void> = async () => {},
|
beforeReply: (method: string, params: Record<string, unknown>) => Promise<void> = async () => {},
|
||||||
) {
|
) {
|
||||||
const document = (id: number, owners: number[], childIndexes: number[]) => ({
|
const document = (id: number, owners: number[], childIndexes: number[]) => ({
|
||||||
scrollOffsetX: 0,
|
|
||||||
scrollOffsetY: 0,
|
|
||||||
frameId: `frame-${id}`,
|
frameId: `frame-${id}`,
|
||||||
nodes: {
|
nodes: {
|
||||||
parentIndex: [-1, ...owners.map(() => 0)],
|
parentIndex: [-1, ...owners.map(() => 0)],
|
||||||
@@ -1376,11 +1305,7 @@ function siblingCaptureFixture(
|
|||||||
await beforeReply(method, args);
|
await beforeReply(method, args);
|
||||||
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
||||||
if (method === "Page.getLayoutMetrics")
|
if (method === "Page.getLayoutMetrics")
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1000, clientHeight: 800 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800 },
|
|
||||||
};
|
|
||||||
if (method === "DOM.getBoxModel")
|
if (method === "DOM.getBoxModel")
|
||||||
return { model: { content: [0, 0, 200, 0, 200, 100, 0, 100] } };
|
return { model: { content: [0, 0, 200, 0, 200, 100, 0, 100] } };
|
||||||
if (method === "DOM.resolveNode") return { object: { objectId: String(args.backendNodeId) } };
|
if (method === "DOM.resolveNode") return { object: { objectId: String(args.backendNodeId) } };
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ describe("document facts", () => {
|
|||||||
);
|
);
|
||||||
expect(nodes[0].attrs).toEqual({ "aria-hidden": "true", inert: "" });
|
expect(nodes[0].attrs).toEqual({ "aria-hidden": "true", inert: "" });
|
||||||
expect(nodes[0].layout).toEqual({
|
expect(nodes[0].layout).toEqual({
|
||||||
boundsSpace: "snapshot-document-layout",
|
boundsSpace: "snapshot-document-css",
|
||||||
bounds: [10, 20, 120, 40],
|
bounds: [10, 20, 120, 40],
|
||||||
styles: {
|
styles: {
|
||||||
position: "static",
|
position: "static",
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ function childSnapshot(frameId: string, backendNodeId: number) {
|
|||||||
strings,
|
strings,
|
||||||
documents: [
|
documents: [
|
||||||
{
|
{
|
||||||
scrollOffsetX: 0,
|
|
||||||
scrollOffsetY: 0,
|
|
||||||
frameId,
|
frameId,
|
||||||
nodes: {
|
nodes: {
|
||||||
parentIndex: [-1, 0],
|
parentIndex: [-1, 0],
|
||||||
@@ -78,11 +76,7 @@ describe("captureFrameData", () => {
|
|||||||
};
|
};
|
||||||
const reply = async (_target: unknown, method: string) => {
|
const reply = async (_target: unknown, method: string) => {
|
||||||
if (method === "Page.getLayoutMetrics")
|
if (method === "Page.getLayoutMetrics")
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 300, clientHeight: 200 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 300, clientHeight: 200 },
|
|
||||||
};
|
|
||||||
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
if (method === "DOMSnapshot.captureSnapshot") return snapshot;
|
||||||
if (method === "DOM.getBoxModel")
|
if (method === "DOM.getBoxModel")
|
||||||
return { model: { content: [50, 100, 350, 100, 350, 300, 50, 300] } };
|
return { model: { content: [50, 100, 350, 100, 350, 300, 50, 300] } };
|
||||||
@@ -133,11 +127,7 @@ describe("captureFrameData", () => {
|
|||||||
};
|
};
|
||||||
const sendToTarget = vi.fn(async (target, method) => {
|
const sendToTarget = vi.fn(async (target, method) => {
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 300, clientHeight: 200, pageX: 0, pageY: 0 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 300, clientHeight: 200, pageX: 0, pageY: 0 },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (method === "DOMSnapshot.enable" || method === "Accessibility.enable") return {};
|
if (method === "DOMSnapshot.enable" || method === "Accessibility.enable") return {};
|
||||||
if (method === "DOMSnapshot.captureSnapshot") {
|
if (method === "DOMSnapshot.captureSnapshot") {
|
||||||
@@ -164,11 +154,7 @@ describe("captureFrameData", () => {
|
|||||||
return { model: { content: [x, 100, x + 300, 100, x + 300, 300, x, 300] } };
|
return { model: { content: [x, 100, x + 300, 100, x + 300, 300, x, 300] } };
|
||||||
}
|
}
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1000, clientHeight: 800 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800 },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
throw new Error(`unexpected root ${method}`);
|
throw new Error(`unexpected root ${method}`);
|
||||||
}) as CdpRunner["send"],
|
}) as CdpRunner["send"],
|
||||||
@@ -236,11 +222,7 @@ describe("captureFrameData", () => {
|
|||||||
if (method === "Accessibility.getFullAXTree") return { nodes: [] };
|
if (method === "Accessibility.getFullAXTree") return { nodes: [] };
|
||||||
if (method === "DOM.getBoxModel") throw new Error("owner geometry unavailable");
|
if (method === "DOM.getBoxModel") throw new Error("owner geometry unavailable");
|
||||||
if (method === "Page.getLayoutMetrics") {
|
if (method === "Page.getLayoutMetrics") {
|
||||||
return {
|
return { cssLayoutViewport: { clientWidth: 1000, clientHeight: 800 } };
|
||||||
visualViewport: { clientWidth: 1000 },
|
|
||||||
cssVisualViewport: { clientWidth: 1000 },
|
|
||||||
cssLayoutViewport: { clientWidth: 1000, clientHeight: 800 },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
throw new Error(`unexpected root ${method}`);
|
throw new Error(`unexpected root ${method}`);
|
||||||
}) as CdpRunner["send"],
|
}) as CdpRunner["send"],
|
||||||
@@ -283,7 +265,7 @@ describe("captureFrameData", () => {
|
|||||||
expect.objectContaining({ backendDOMNodeId: 101, frameId: "child" }),
|
expect.objectContaining({ backendDOMNodeId: 101, frameId: "child" }),
|
||||||
]);
|
]);
|
||||||
expect(childDocument?.domNodes.find((node) => node.backendNodeId === 101)).toEqual(
|
expect(childDocument?.domNodes.find((node) => node.backendNodeId === 101)).toEqual(
|
||||||
expect.objectContaining({ rect: null, localRect: null, rendered: true }),
|
expect.objectContaining({ rect: null, localRect: { x: 10, y: 20, w: 100, h: 40 } }),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,16 +5,8 @@ import type { Viewport } from "@browser-skill/vom";
|
|||||||
import type { CdpTarget } from "@/browser-driver/frame-graph";
|
import type { CdpTarget } from "@/browser-driver/frame-graph";
|
||||||
import { evaluateHoverTrigger } from "@/lib/hover-trigger-policy";
|
import { evaluateHoverTrigger } from "@/lib/hover-trigger-policy";
|
||||||
import { OVERLAY_HOST_SELECTOR } from "../../lib/overlay-bridge";
|
import { OVERLAY_HOST_SELECTOR } from "../../lib/overlay-bridge";
|
||||||
import {
|
import { type FrameProjectionIssue, type FrameProjectionState } from "../geometry/coordinate-types";
|
||||||
type FrameProjectionIssue,
|
import { cssViewport, GeometryContext, type LayoutMetrics } from "../geometry/frame-context";
|
||||||
type FrameProjectionState,
|
|
||||||
snapshotCoordinates,
|
|
||||||
} from "../geometry/coordinate-types";
|
|
||||||
import {
|
|
||||||
GeometryContext,
|
|
||||||
type LayoutMetrics,
|
|
||||||
snapshotLayoutScale,
|
|
||||||
} from "../geometry/frame-context";
|
|
||||||
import type { CdpRunner } from "../shared";
|
import type { CdpRunner } from "../shared";
|
||||||
import { isAbortError, throwIfAborted } from "./capture-abort";
|
import { isAbortError, throwIfAborted } from "./capture-abort";
|
||||||
import type { CapturedNode } from "./capture-types";
|
import type { CapturedNode } from "./capture-types";
|
||||||
@@ -537,13 +529,10 @@ async function parseChildFrameDocuments(
|
|||||||
const iframeBackendId = parentBackendIds[nodeArrayIdx];
|
const iframeBackendId = parentBackendIds[nodeArrayIdx];
|
||||||
if (visited.has(childDocIndex) || !childDoc || iframeBackendId === undefined) return [];
|
if (visited.has(childDocIndex) || !childDoc || iframeBackendId === undefined) return [];
|
||||||
const source = { target: parentContext.target, frameId: snapshotFrameId(childDoc, strings) };
|
const source = { target: parentContext.target, frameId: snapshotFrameId(childDoc, strings) };
|
||||||
const coordinates = snapshotCoordinates(childDoc, parentContext.layoutUnitsPerCssPixel);
|
|
||||||
const parent = parentContext.projection;
|
const parent = parentContext.projection;
|
||||||
const projection: FrameProjectionState =
|
const projection: FrameProjectionState =
|
||||||
parent.status === "available"
|
parent.status === "available"
|
||||||
? coordinates
|
? { status: "unavailable", source, ownerBackendNodeId: iframeBackendId }
|
||||||
? { status: "unavailable", source, ownerBackendNodeId: iframeBackendId }
|
|
||||||
: { status: "unavailable", source, reason: "snapshot-coordinates-unavailable" }
|
|
||||||
: { status: "blocked", source, cause: parent.status === "blocked" ? parent.cause : parent };
|
: { status: "blocked", source, cause: parent.status === "blocked" ? parent.cause : parent };
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -551,7 +540,6 @@ async function parseChildFrameDocuments(
|
|||||||
childDoc,
|
childDoc,
|
||||||
iframeBackendId,
|
iframeBackendId,
|
||||||
source,
|
source,
|
||||||
coordinates,
|
|
||||||
projection: projection as FrameProjectionState,
|
projection: projection as FrameProjectionState,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -573,7 +561,6 @@ async function parseChildFrameDocuments(
|
|||||||
Array.from({ length: Math.min(4, children.length) }, async () => {
|
Array.from({ length: Math.min(4, children.length) }, async () => {
|
||||||
while (cursor < children.length && !signal?.aborted && !failure) {
|
while (cursor < children.length && !signal?.aborted && !failure) {
|
||||||
const child = children[cursor++];
|
const child = children[cursor++];
|
||||||
if (!child.coordinates) continue;
|
|
||||||
try {
|
try {
|
||||||
// Owner quads are target-relative; do not apply the parent transform twice.
|
// Owner quads are target-relative; do not apply the parent transform twice.
|
||||||
child.projection = await geometry.snapshotProjection(
|
child.projection = await geometry.snapshotProjection(
|
||||||
@@ -594,14 +581,7 @@ async function parseChildFrameDocuments(
|
|||||||
throwIfAborted(signal);
|
throwIfAborted(signal);
|
||||||
|
|
||||||
// Completion order must not change document traversal or result insertion order.
|
// Completion order must not change document traversal or result insertion order.
|
||||||
for (const {
|
for (const { childDocIndex, childDoc, iframeBackendId, source, projection } of children) {
|
||||||
childDocIndex,
|
|
||||||
childDoc,
|
|
||||||
iframeBackendId,
|
|
||||||
source,
|
|
||||||
projection,
|
|
||||||
coordinates,
|
|
||||||
} of children) {
|
|
||||||
throwIfAborted(signal);
|
throwIfAborted(signal);
|
||||||
if (projection.status !== "available") frameGeometryIssues.push(projection);
|
if (projection.status !== "available") frameGeometryIssues.push(projection);
|
||||||
const childContext: FrameContext = {
|
const childContext: FrameContext = {
|
||||||
@@ -609,8 +589,8 @@ async function parseChildFrameDocuments(
|
|||||||
target: source.target,
|
target: source.target,
|
||||||
ownerFrameBackendNodeId: iframeBackendId,
|
ownerFrameBackendNodeId: iframeBackendId,
|
||||||
projection,
|
projection,
|
||||||
coordinates,
|
scrollX: childDoc.scrollOffsetX ?? 0,
|
||||||
layoutUnitsPerCssPixel: parentContext.layoutUnitsPerCssPixel,
|
scrollY: childDoc.scrollOffsetY ?? 0,
|
||||||
};
|
};
|
||||||
const nextVisited = new Set(visited);
|
const nextVisited = new Set(visited);
|
||||||
nextVisited.add(childDocIndex);
|
nextVisited.add(childDocIndex);
|
||||||
@@ -673,11 +653,10 @@ export async function captureViewModel(
|
|||||||
console.debug("[bsk capture] layout metrics unavailable", error);
|
console.debug("[bsk capture] layout metrics unavailable", error);
|
||||||
}
|
}
|
||||||
throwIfAborted(options.signal);
|
throwIfAborted(options.signal);
|
||||||
const viewport: Viewport = {
|
const measured = cssViewport(metrics);
|
||||||
width: metrics.cssLayoutViewport?.clientWidth ?? 0,
|
const viewport: Viewport = { width: measured.width, height: measured.height };
|
||||||
height: metrics.cssLayoutViewport?.clientHeight ?? 0,
|
const scrollX = measured.scrollX;
|
||||||
};
|
const scrollY = measured.scrollY;
|
||||||
const layoutUnitsPerCssPixel = snapshotLayoutScale(metrics);
|
|
||||||
|
|
||||||
await cdp.send(tabId, "DOMSnapshot.enable", {});
|
await cdp.send(tabId, "DOMSnapshot.enable", {});
|
||||||
throwIfAborted(options.signal);
|
throwIfAborted(options.signal);
|
||||||
@@ -700,28 +679,19 @@ export async function captureViewModel(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const source = { target, frameId: snapshotFrameId(doc0, strings) };
|
|
||||||
const coordinates = snapshotCoordinates(doc0, layoutUnitsPerCssPixel, {
|
|
||||||
x: metrics.cssLayoutViewport?.pageX,
|
|
||||||
y: metrics.cssLayoutViewport?.pageY,
|
|
||||||
});
|
|
||||||
const topContext: FrameContext = {
|
const topContext: FrameContext = {
|
||||||
frameId: snapshotFrameId(doc0, strings),
|
frameId: snapshotFrameId(doc0, strings),
|
||||||
ownerFrameBackendNodeId: null,
|
ownerFrameBackendNodeId: null,
|
||||||
target,
|
target,
|
||||||
projection:
|
projection: {
|
||||||
coordinates &&
|
status: "available",
|
||||||
[viewport.width, viewport.height].every((size) => Number.isFinite(size) && size > 0)
|
projection: {
|
||||||
? {
|
source: { target, frameId: snapshotFrameId(doc0, strings) },
|
||||||
status: "available",
|
geometry: { sourceClips: [], edges: [], topViewport: viewport },
|
||||||
projection: {
|
},
|
||||||
source,
|
},
|
||||||
geometry: { sourceClips: [], edges: [], topViewport: viewport },
|
scrollX,
|
||||||
},
|
scrollY,
|
||||||
}
|
|
||||||
: { status: "unavailable", source, reason: "snapshot-coordinates-unavailable" },
|
|
||||||
coordinates,
|
|
||||||
layoutUnitsPerCssPixel,
|
|
||||||
};
|
};
|
||||||
const mainParsed = await normalizeDocument(doc0, strings, topContext, options.signal);
|
const mainParsed = await normalizeDocument(doc0, strings, topContext, options.signal);
|
||||||
const nodes = mainParsed.nodes;
|
const nodes = mainParsed.nodes;
|
||||||
@@ -773,10 +743,7 @@ export async function captureViewModel(
|
|||||||
viewport,
|
viewport,
|
||||||
iframeNodes,
|
iframeNodes,
|
||||||
frameNodes,
|
frameNodes,
|
||||||
frameGeometryIssues: [
|
frameGeometryIssues: frameParsed.frameGeometryIssues,
|
||||||
...(topContext.projection.status === "available" ? [] : [topContext.projection]),
|
|
||||||
...frameParsed.frameGeometryIssues,
|
|
||||||
],
|
|
||||||
frameOwnerBackendNodeIds: frameParsed.frameOwnerBackendNodeIds,
|
frameOwnerBackendNodeIds: frameParsed.frameOwnerBackendNodeIds,
|
||||||
frameExcludedBackendNodeIds: frameParsed.frameExcludedBackendNodeIds,
|
frameExcludedBackendNodeIds: frameParsed.frameExcludedBackendNodeIds,
|
||||||
frameParentIds: frameParsed.frameParentIds,
|
frameParentIds: frameParsed.frameParentIds,
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import { isOverlayHostNode } from "@/lib/overlay-bridge";
|
|||||||
import { createCaptureCheckpoint } from "./capture-abort";
|
import { createCaptureCheckpoint } from "./capture-abort";
|
||||||
import type { CapturedNode } from "./capture-types";
|
import type { CapturedNode } from "./capture-types";
|
||||||
|
|
||||||
/** Bounds retain their raw snapshot document layout units until normalization. */
|
/** Bounds retain their snapshot document CSS units until normalization. */
|
||||||
export interface SnapshotLayout {
|
export interface SnapshotLayout {
|
||||||
readonly boundsSpace: "snapshot-document-layout";
|
readonly boundsSpace: "snapshot-document-css";
|
||||||
bounds?: number[];
|
bounds?: number[];
|
||||||
styles: Readonly<Record<string, string>>;
|
styles: Readonly<Record<string, string>>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import type { CdpTarget } from "@/browser-driver/frame-graph";
|
|||||||
import {
|
import {
|
||||||
type FrameProjectionState,
|
type FrameProjectionState,
|
||||||
projectSnapshotRect,
|
projectSnapshotRect,
|
||||||
type SnapshotCoordinates,
|
|
||||||
snapshotViewportRect,
|
snapshotViewportRect,
|
||||||
} from "../geometry/coordinate-types";
|
} from "../geometry/coordinate-types";
|
||||||
import { createCaptureCheckpoint } from "./capture-abort";
|
import { createCaptureCheckpoint } from "./capture-abort";
|
||||||
@@ -14,8 +13,8 @@ export interface FrameContext {
|
|||||||
ownerFrameBackendNodeId: number | null;
|
ownerFrameBackendNodeId: number | null;
|
||||||
projection: FrameProjectionState;
|
projection: FrameProjectionState;
|
||||||
target: CdpTarget;
|
target: CdpTarget;
|
||||||
coordinates: SnapshotCoordinates | null;
|
scrollX: number;
|
||||||
layoutUnitsPerCssPixel: number | null;
|
scrollY: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NormalizedDocument {
|
export interface NormalizedDocument {
|
||||||
@@ -39,11 +38,10 @@ export async function normalizeDocument(
|
|||||||
if (pending) await pending;
|
if (pending) await pending;
|
||||||
}
|
}
|
||||||
const node = decoded.nodes[i];
|
const node = decoded.nodes[i];
|
||||||
const bounds = node.layout?.bounds ?? [];
|
|
||||||
const input = snapshotViewportRect(
|
const input = snapshotViewportRect(
|
||||||
bounds,
|
node.layout?.bounds ?? [],
|
||||||
{ target: context.target, frameId: context.frameId },
|
{ target: context.target, frameId: context.frameId },
|
||||||
context.coordinates,
|
{ x: context.scrollX, y: context.scrollY },
|
||||||
);
|
);
|
||||||
const local = input?.rect;
|
const local = input?.rect;
|
||||||
const rect =
|
const rect =
|
||||||
@@ -59,10 +57,7 @@ export async function normalizeDocument(
|
|||||||
localRect: local ? { x: local.x, y: local.y, w: local.width, h: local.height } : null,
|
localRect: local ? { x: local.x, y: local.y, w: local.width, h: local.height } : null,
|
||||||
rect: rect ? { x: rect.x, y: rect.y, w: rect.width, h: rect.height } : null,
|
rect: rect ? { x: rect.x, y: rect.y, w: rect.width, h: rect.height } : null,
|
||||||
rendered:
|
rendered:
|
||||||
bounds.length >= 4 &&
|
!!local &&
|
||||||
bounds.slice(0, 4).every(Number.isFinite) &&
|
|
||||||
bounds[2] > 0 &&
|
|
||||||
bounds[3] > 0 &&
|
|
||||||
visibility !== "hidden" &&
|
visibility !== "hidden" &&
|
||||||
visibility !== "collapse" &&
|
visibility !== "collapse" &&
|
||||||
(Number.parseFloat(opacity) || 0) > 0,
|
(Number.parseFloat(opacity) || 0) > 0,
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ export async function decodeDocument(
|
|||||||
li === undefined
|
li === undefined
|
||||||
? undefined
|
? undefined
|
||||||
: {
|
: {
|
||||||
boundsSpace: "snapshot-document-layout" as const,
|
boundsSpace: "snapshot-document-css" as const,
|
||||||
bounds: dl?.bounds?.[li],
|
bounds: dl?.bounds?.[li],
|
||||||
styles,
|
styles,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
# DOMSnapshot layout-unit regression (#195)
|
|
||||||
|
|
||||||
Source: https://github.com/Tencent/BrowserSkill/pull/195
|
|
||||||
|
|
||||||
DOMSnapshot bounds and document scroll offsets retain Blink layout units. Treating them as CSS
|
|
||||||
pixels changes both positions and sizes under device scaling/browser zoom, before iframe
|
|
||||||
projection or viewport clipping even starts.
|
|
||||||
|
|
||||||
The fixture contains a scrolled root, a scrolled same-process iframe, an OOPIF served from the
|
|
||||||
other loopback hostname, and a nested iframe in each. Owners have borders, padding and CSS
|
|
||||||
transforms. The geometry test compares the production capture's local and top-level rectangles
|
|
||||||
against independent DOM border boxes, with at most 2 CSS pixels of layout rounding. It also
|
|
||||||
checks that each target reads layout metrics only once. No credentials or personal tabs are used.
|
|
||||||
|
|
||||||
Run the geometric assertions with Node 22+ and a local Chrome executable:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
BSK_GEOMETRY_CHROME=/path/to/chrome pnpm --filter @browser-skill/extension exec vitest run \
|
|
||||||
src/tools/__tests__/snapshot-coordinates.browser.test.ts
|
|
||||||
```
|
|
||||||
|
|
||||||
The test launches and cleans up its own headless Chrome profiles. It explicitly verifies the
|
|
||||||
requested browser zoom and OOPIF topology, so unsupported setups fail rather than silently
|
|
||||||
testing a different configuration. It is skipped in ordinary unit runs unless the executable
|
|
||||||
is specified. No browser download or new package dependency is required.
|
|
||||||
|
|
||||||
The corpus smoke case checks fixture readiness and observable semantics through the real CLI:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
BSK_AUTO_UPDATE=off pnpm eval:browser smoke --case snapshot-coordinates --bsk ./target/debug/bsk
|
|
||||||
```
|
|
||||||
|
|
||||||
Smoke alone does **not** certify coordinate accuracy; CLI observations do not expose raw boxes.
|
|
||||||
Use the geometric test above for the regression's numeric assertions.
|
|
||||||
|
|
||||||
## Separate existing boundary
|
|
||||||
|
|
||||||
The OOPIF root uses non-occupying scrollbars in the unit-conversion regression. Root and
|
|
||||||
same-process frames retain normal scrollbars. Append `&classic-scrollbars` to the fixture URL
|
|
||||||
to reproduce the separate existing OOPIF projection issue: `targetProjection()` maps the CSS
|
|
||||||
layout viewport (which excludes occupying scrollbars) onto the entire owner content quad.
|
|
||||||
This inflates the projected coordinates when scrollbars occupy space. Main already has that
|
|
||||||
mapping; fixing it also changes shared live geometry and is outside this snapshot-unit fix.
|
|
||||||
The test does not relax its numeric tolerance to absorb that error.
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
import { spawn } from "node:child_process";
|
|
||||||
import { once } from "node:events";
|
|
||||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
|
||||||
|
|
||||||
// This regression owns its browser/profile. It never attaches to a user's Chrome.
|
|
||||||
export async function withChrome({ executable, deviceScale, zoom }, run) {
|
|
||||||
const profile = await mkdtemp(join(tmpdir(), "bsk-snapshot-coordinates-"));
|
|
||||||
let chrome;
|
|
||||||
let socket;
|
|
||||||
const pending = new Map();
|
|
||||||
try {
|
|
||||||
await mkdir(join(profile, "Default"));
|
|
||||||
await writeFile(
|
|
||||||
join(profile, "Default", "Preferences"),
|
|
||||||
JSON.stringify({
|
|
||||||
partition: { default_zoom_level: { x: Math.log(zoom) / Math.log(1.2) } },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
chrome = spawn(
|
|
||||||
executable,
|
|
||||||
[
|
|
||||||
"--headless=new",
|
|
||||||
"--no-first-run",
|
|
||||||
"--no-default-browser-check",
|
|
||||||
"--disable-extensions",
|
|
||||||
"--site-per-process",
|
|
||||||
"--remote-debugging-port=0",
|
|
||||||
"--window-size=1600,1200",
|
|
||||||
`--force-device-scale-factor=${deviceScale}`,
|
|
||||||
`--user-data-dir=${profile}`,
|
|
||||||
"about:blank",
|
|
||||||
],
|
|
||||||
{ stdio: ["ignore", "ignore", "pipe"] },
|
|
||||||
);
|
|
||||||
const endpoint = await new Promise((resolve, reject) => {
|
|
||||||
let output = "";
|
|
||||||
const timeout = setTimeout(
|
|
||||||
() => reject(new Error(`Chrome startup timed out: ${output}`)),
|
|
||||||
15_000,
|
|
||||||
);
|
|
||||||
const fail = (error) => {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
reject(error);
|
|
||||||
};
|
|
||||||
chrome.once("error", fail);
|
|
||||||
chrome.once("exit", (code) => fail(new Error(`Chrome exited (${code}): ${output}`)));
|
|
||||||
chrome.stderr.on("data", (chunk) => {
|
|
||||||
output += chunk;
|
|
||||||
const match = output.match(/DevTools listening on (ws:\/\/\S+)/);
|
|
||||||
if (match) {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
resolve(match[1]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
socket = new WebSocket(endpoint);
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
socket.addEventListener("open", resolve, { once: true });
|
|
||||||
socket.addEventListener("error", reject, { once: true });
|
|
||||||
});
|
|
||||||
socket.addEventListener("message", ({ data }) => {
|
|
||||||
const reply = JSON.parse(data);
|
|
||||||
const request = pending.get(reply.id);
|
|
||||||
if (!request) return;
|
|
||||||
clearTimeout(request.timeout);
|
|
||||||
pending.delete(reply.id);
|
|
||||||
if (reply.error) request.reject(new Error(JSON.stringify(reply.error)));
|
|
||||||
else request.resolve(reply.result);
|
|
||||||
});
|
|
||||||
let sequence = 0;
|
|
||||||
const send = (method, params = {}, sessionId) =>
|
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
const id = ++sequence;
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
pending.delete(id);
|
|
||||||
reject(new Error(`CDP timed out: ${method}`));
|
|
||||||
}, 10_000);
|
|
||||||
pending.set(id, { resolve, reject, timeout });
|
|
||||||
socket.send(JSON.stringify({ id, method, params, sessionId }));
|
|
||||||
});
|
|
||||||
await run(send);
|
|
||||||
} finally {
|
|
||||||
for (const request of pending.values()) {
|
|
||||||
clearTimeout(request.timeout);
|
|
||||||
request.reject(new Error("regression browser closed"));
|
|
||||||
}
|
|
||||||
socket?.close();
|
|
||||||
if (chrome && chrome.exitCode === null && chrome.signalCode === null) {
|
|
||||||
const exited = once(chrome, "exit");
|
|
||||||
const timeout = setTimeout(() => chrome.kill("SIGKILL"), 5_000);
|
|
||||||
chrome.kill();
|
|
||||||
await exited;
|
|
||||||
clearTimeout(timeout);
|
|
||||||
}
|
|
||||||
await rm(profile, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "../../../schemas/case.schema.json",
|
|
||||||
"schemaVersion": 1,
|
|
||||||
"id": "snapshot-coordinates",
|
|
||||||
"title": "Scrolled and nested frame coordinate fixture",
|
|
||||||
"suite": "regression",
|
|
||||||
"tags": ["geometry", "iframe", "scroll"],
|
|
||||||
"fixture": { "startPath": "/snapshot-coordinates" },
|
|
||||||
"prompts": {
|
|
||||||
"en": "Open {url}, observe the page and its frames, report the GEOMETRY marker, then close the session.",
|
|
||||||
"zh-CN": "打开 {url},观察页面及其 iframe,报告 GEOMETRY 标记,然后关闭会话。"
|
|
||||||
},
|
|
||||||
"coverage": ["session.start", "session.stop", "page.navigate", "inspect.observe"],
|
|
||||||
"assertions": {
|
|
||||||
"site": [
|
|
||||||
{
|
|
||||||
"label": "root fixture scrolled and settled",
|
|
||||||
"type": "geometry.ready",
|
|
||||||
"where": { "data.root": true },
|
|
||||||
"minCount": 1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"response": [{ "label": "observed the fixture marker", "includes": "GEOMETRY-195" }],
|
|
||||||
"adapter": [{ "label": "browser session was closed", "key": "sessionStopped" }]
|
|
||||||
},
|
|
||||||
"smoke": {
|
|
||||||
"steps": [
|
|
||||||
{ "action": "navigate" },
|
|
||||||
{ "action": "wait-site-event", "type": "geometry.ready", "where": { "root": true } },
|
|
||||||
{ "action": "observe" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import { page, withRun } from "../../../lib/fixtures.mjs";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
id: "snapshot-coordinates",
|
|
||||||
routes: ["/snapshot-coordinates", "/snapshot-coordinates/frame", "/snapshot-coordinates/nested"],
|
|
||||||
render({ pathname, runId, query }) {
|
|
||||||
const root = pathname === "/snapshot-coordinates";
|
|
||||||
const nested = pathname.endsWith("/nested");
|
|
||||||
return page({
|
|
||||||
title: "Snapshot coordinate regression",
|
|
||||||
body: `
|
|
||||||
<style>
|
|
||||||
main { margin: 0; width: auto; }
|
|
||||||
body { width: 2000px; height: 2400px; }
|
|
||||||
html { overflow-anchor: none; }
|
|
||||||
${query.get("scrollbars") === "none" ? "html { scrollbar-width: none; }" : ""}
|
|
||||||
button { position: absolute; box-sizing: border-box; padding: 0; border: 2px solid black; border-radius: 0; }
|
|
||||||
#probe { left: ${root ? 180 : 100}px; top: ${root ? 360 : 160}px; width: 120px; height: 40px; }
|
|
||||||
iframe { position: absolute; box-sizing: content-box; width: 320px; height: 220px;
|
|
||||||
border: 6px solid black; padding: 8px; transform: scale(1.25); transform-origin: 0 0; }
|
|
||||||
#same { left: 340px; top: 400px; }
|
|
||||||
#cross { left: 820px; top: 400px; }
|
|
||||||
#nested { left: 150px; top: 210px; width: 130px; height: 70px; border-width: 2px; padding: 4px; transform: scale(0.8); }
|
|
||||||
${nested ? "#probe { left: 30px; top: 40px; width: 60px; height: 20px; }" : ""}
|
|
||||||
</style>
|
|
||||||
<button id="probe" data-geometry-probe>GEOMETRY-195</button>
|
|
||||||
${root ? `<iframe id="same" name="same" title="same-process frame" src="${withRun("/snapshot-coordinates/frame", runId)}"></iframe><iframe id="cross" name="cross" title="cross-site frame"></iframe>` : ""}
|
|
||||||
${!root && !nested ? `<iframe id="nested" name="nested" title="nested frame" src="${withRun("/snapshot-coordinates/nested", runId)}"></iframe>` : ""}
|
|
||||||
`,
|
|
||||||
script: `
|
|
||||||
history.scrollRestoration = "manual";
|
|
||||||
const cross = document.querySelector("#cross");
|
|
||||||
if (cross) {
|
|
||||||
const url = new URL(${JSON.stringify(withRun("/snapshot-coordinates/frame", runId))}, location.href);
|
|
||||||
url.hostname = location.hostname === "127.0.0.1" ? "localhost" : "127.0.0.1";
|
|
||||||
// Isolate unit conversion from the pre-existing OOPIF scrollbar-width
|
|
||||||
// projection issue. ?classic-scrollbars retains that separate reproduction.
|
|
||||||
if (!new URLSearchParams(location.search).has("classic-scrollbars")) url.searchParams.set("scrollbars", "none");
|
|
||||||
cross.src = url.href;
|
|
||||||
}
|
|
||||||
window.addEventListener("load", () => {
|
|
||||||
scrollTo(${root ? "80, 240" : nested ? "10, 20" : "40, 100"});
|
|
||||||
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
||||||
window.geometryReady = true;
|
|
||||||
document.documentElement.dataset.geometryReady = "true";
|
|
||||||
browserEval.send("geometry.ready", { root: ${root} });
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
`,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -41,22 +41,17 @@ test("case manifests are discovered, ordered, and grouped into suites", () => {
|
|||||||
"diagnostics",
|
"diagnostics",
|
||||||
"mobile-emulation",
|
"mobile-emulation",
|
||||||
"generated-form",
|
"generated-form",
|
||||||
"snapshot-coordinates",
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
assert.deepEqual(repositorySummary(cases, fixtureRegistry).suites, {
|
assert.deepEqual(repositorySummary(cases, fixtureRegistry).suites, { core: 6, matrix: 1 });
|
||||||
core: 6,
|
|
||||||
matrix: 1,
|
|
||||||
regression: 1,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("repository validation links every case to a fixture and valid workflow evidence", () => {
|
test("repository validation links every case to a fixture and valid workflow evidence", () => {
|
||||||
assert.deepEqual(validateRepositoryCases(cases, fixtureRegistry), []);
|
assert.deepEqual(validateRepositoryCases(cases, fixtureRegistry), []);
|
||||||
const summary = repositorySummary(cases, fixtureRegistry);
|
const summary = repositorySummary(cases, fixtureRegistry);
|
||||||
assert.equal(summary.cases, 8);
|
assert.equal(summary.cases, 7);
|
||||||
assert.equal(summary.fixtureModules, 9);
|
assert.equal(summary.fixtureModules, 8);
|
||||||
assert.equal(summary.fixtureRoutes, 15);
|
assert.equal(summary.fixtureRoutes, 12);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("manifest validation rejects unknown operations and incomplete workflow steps", () => {
|
test("manifest validation rejects unknown operations and incomplete workflow steps", () => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@wxg-prc-cpg/browser-skill-dsh-plugin",
|
"name": "@wxg-prc-cpg/browser-skill-dsh-plugin",
|
||||||
"description": "DeepSeek Harness tool plugin that exposes BrowserSkill browser automation (browser_* tools) to the model",
|
"description": "DeepSeek Harness tool plugin that exposes BrowserSkill browser automation (browser_* tools) to the model",
|
||||||
"version": "0.2.1",
|
"version": "0.2.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public",
|
"access": "public",
|
||||||
|
|||||||
+3
-9
@@ -174,22 +174,16 @@ function updateChangelog(version) {
|
|||||||
|
|
||||||
const today = new Date().toISOString().slice(0, 10);
|
const today = new Date().toISOString().slice(0, 10);
|
||||||
const escapedVer = version.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
const escapedVer = version.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||||
const versionHeading = new RegExp(`^## \\[${escapedVer}\\](?:\\s|$)`, "m");
|
|
||||||
|
|
||||||
// First: fill in any date-placeholder line for this version (e.g. "## [0.2.0] - 2026-09-XX")
|
// First: fill in any date-placeholder line for this version (e.g. "## [0.2.0] - 2026-09-XX")
|
||||||
const versionPlaceholder = new RegExp(`^## \\[${escapedVer}\\]\\s*-\\s*\\d{4}-\\d{2}-XX`, "m");
|
const versionPlaceholder = new RegExp(`^## \\[${escapedVer}\\]\\s*-\\s*\\d{4}-\\d{2}-XX`, "m");
|
||||||
if (versionPlaceholder.test(content)) {
|
if (versionPlaceholder.test(content)) {
|
||||||
content = content.replace(versionPlaceholder, `## [${version}] - ${today}`);
|
content = content.replace(versionPlaceholder, `## [${version}] - ${today}`);
|
||||||
} else if (!versionHeading.test(content)) {
|
} else {
|
||||||
// Preserve prepared release entries; new versions go before the release history.
|
// Otherwise: insert a new section after [Unreleased]
|
||||||
const heading = `## [${version}] - ${today}`;
|
|
||||||
const unreleased = /^## \[Unreleased\]/m;
|
const unreleased = /^## \[Unreleased\]/m;
|
||||||
if (unreleased.test(content)) {
|
if (unreleased.test(content)) {
|
||||||
content = content.replace(unreleased, `## [Unreleased]\n\n${heading}`);
|
content = content.replace(unreleased, `## [Unreleased]\n\n## [${version}] - ${today}`);
|
||||||
} else if (/^## /m.test(content)) {
|
|
||||||
content = content.replace(/^## /m, `${heading}\n\n## `);
|
|
||||||
} else {
|
|
||||||
content = `${content.trimEnd()}\n\n${heading}\n`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user