@empiricalrun/playwright-utils 0.70.3 → 0.71.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/api-worker-client.d.ts +5 -1
- package/dist/api-worker-client.d.ts.map +1 -1
- package/dist/api-worker-client.js +15 -0
- package/dist/generated/api-worker-openapi.d.ts +609 -383
- package/dist/generated/api-worker-openapi.d.ts.map +1 -1
- package/dist/overlay-test-expectations.d.ts +10 -0
- package/dist/overlay-test-expectations.d.ts.map +1 -0
- package/dist/overlay-test-expectations.js +51 -0
- package/dist/overlay-tests/click.spec.js +26 -94
- package/dist/overlay-tests/dropdown.spec.js +10 -9
- package/dist/overlay-tests/fixtures.d.ts +1 -0
- package/dist/overlay-tests/fixtures.d.ts.map +1 -1
- package/dist/overlay-tests/fixtures.js +24 -0
- package/dist/overlay-tests/visual.spec.js +1 -11
- package/dist/test/cross-shard-locks.d.ts +1 -1
- package/dist/test/cross-shard-locks.d.ts.map +1 -1
- package/dist/test/cross-shard-locks.js +71 -25
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +10 -0
- package/dist/test/locator-handler-log.spec.d.ts +2 -0
- package/dist/test/locator-handler-log.spec.d.ts.map +1 -0
- package/dist/test/locator-handler-log.spec.js +44 -0
- package/dist/test/scripts/locator-handler-log.d.ts +23 -0
- package/dist/test/scripts/locator-handler-log.d.ts.map +1 -0
- package/dist/test/scripts/locator-handler-log.js +105 -0
- package/dist/test/scripts/pw-locator-patch/actions/click.d.ts.map +1 -1
- package/dist/test/scripts/pw-locator-patch/actions/click.js +17 -34
- package/dist/test/scripts/pw-locator-patch/actions/hover.d.ts.map +1 -1
- package/dist/test/scripts/pw-locator-patch/actions/hover.js +11 -25
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.d.ts +21 -4
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.d.ts.map +1 -1
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/index.js +113 -18
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/prompt.d.ts +2 -3
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/prompt.d.ts.map +1 -1
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/prompt.js +6 -52
- package/dist/webhook.d.ts +1 -6
- package/dist/webhook.d.ts.map +1 -1
- package/dist/webhook.js +12 -124
- package/package.json +3 -3
- package/playwright.config.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/overlay-tests/typesafe-hit-check.spec.d.ts +0 -2
- package/dist/overlay-tests/typesafe-hit-check.spec.d.ts.map +0 -1
- package/dist/overlay-tests/typesafe-hit-check.spec.js +0 -57
- package/dist/overlay-tests/typesafe.spec.d.ts +0 -2
- package/dist/overlay-tests/typesafe.spec.d.ts.map +0 -1
- package/dist/overlay-tests/typesafe.spec.js +0 -88
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/typesafe.d.ts +0 -38
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/typesafe.d.ts.map +0 -1
- package/dist/test/scripts/pw-locator-patch/dismiss-overlays/typesafe.js +0 -159
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typesafe-hit-check.spec.d.ts","sourceRoot":"","sources":["../../src/overlay-tests/typesafe-hit-check.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const typesafe_1 = require("../test/scripts/pw-locator-patch/dismiss-overlays/typesafe");
|
|
4
|
-
const fixtures_1 = require("./fixtures");
|
|
5
|
-
async function centerOf(locator) {
|
|
6
|
-
const box = await locator.boundingBox();
|
|
7
|
-
if (!box) {
|
|
8
|
-
throw new Error("Element has no bounding box");
|
|
9
|
-
}
|
|
10
|
-
return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
|
|
11
|
-
}
|
|
12
|
-
(0, fixtures_1.test)("allows the toast close button", async ({ page, server }) => {
|
|
13
|
-
await page.goto(`${server.baseURL}/choose-an-overlay.html`);
|
|
14
|
-
const target = await page
|
|
15
|
-
.getByRole("button", { name: "Target" })
|
|
16
|
-
.elementHandle();
|
|
17
|
-
const point = await centerOf(page.locator("#toastCloseBtn"));
|
|
18
|
-
(0, fixtures_1.expect)(await (0, typesafe_1.checkHit)(target, point)).toBe("ok");
|
|
19
|
-
});
|
|
20
|
-
(0, fixtures_1.test)("refuses the dialog behind a toast that blocks the target", async ({ page, server, }) => {
|
|
21
|
-
await page.goto(`${server.baseURL}/choose-an-overlay.html`);
|
|
22
|
-
const target = await page
|
|
23
|
-
.getByRole("button", { name: "Target" })
|
|
24
|
-
.elementHandle();
|
|
25
|
-
const point = await centerOf(page.getByRole("button", { name: "Noted" }));
|
|
26
|
-
(0, fixtures_1.expect)(await (0, typesafe_1.checkHit)(target, point)).toBe("outside_overlay");
|
|
27
|
-
});
|
|
28
|
-
(0, fixtures_1.test)("refuses a page control outside the blocking toast", async ({ page, server, }) => {
|
|
29
|
-
await page.goto(`${server.baseURL}/toast-without-close.html`);
|
|
30
|
-
const target = await page
|
|
31
|
-
.getByRole("button", { name: "Target" })
|
|
32
|
-
.elementHandle();
|
|
33
|
-
const point = await centerOf(page.getByRole("button", { name: "Close project" }));
|
|
34
|
-
(0, fixtures_1.expect)(await (0, typesafe_1.checkHit)(target, point)).toBe("outside_overlay");
|
|
35
|
-
});
|
|
36
|
-
(0, fixtures_1.test)("refuses text inside the blocking toast", async ({ page, server }) => {
|
|
37
|
-
await page.goto(`${server.baseURL}/toast-without-close.html`);
|
|
38
|
-
const target = await page
|
|
39
|
-
.getByRole("button", { name: "Target" })
|
|
40
|
-
.elementHandle();
|
|
41
|
-
const point = await centerOf(page.locator("#toast"));
|
|
42
|
-
(0, fixtures_1.expect)(await (0, typesafe_1.checkHit)(target, point)).toBe("not_clickable");
|
|
43
|
-
});
|
|
44
|
-
(0, fixtures_1.test)("refuses the target under a glass pane", async ({ page, server }) => {
|
|
45
|
-
await page.goto(`${server.baseURL}/glass-pane.html`);
|
|
46
|
-
const target = await page
|
|
47
|
-
.getByRole("button", { name: "Target" })
|
|
48
|
-
.elementHandle();
|
|
49
|
-
(0, fixtures_1.expect)(await (0, typesafe_1.checkHit)(target, await centerOf(page.getByRole("button", { name: "Target" })))).toBe("not_clickable");
|
|
50
|
-
});
|
|
51
|
-
(0, fixtures_1.test)("reports no blocker when the target is uncovered", async ({ page, server, }) => {
|
|
52
|
-
await page.goto(`${server.baseURL}/toast-without-close.html`);
|
|
53
|
-
const target = await page
|
|
54
|
-
.getByRole("button", { name: "Close project" })
|
|
55
|
-
.elementHandle();
|
|
56
|
-
(0, fixtures_1.expect)(await (0, typesafe_1.checkHit)(target, await centerOf(page.getByRole("button", { name: "Close project" })))).toBe("no_blocker");
|
|
57
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typesafe.spec.d.ts","sourceRoot":"","sources":["../../src/overlay-tests/typesafe.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const dismiss_overlays_1 = require("../test/scripts/pw-locator-patch/dismiss-overlays");
|
|
9
|
-
const typesafe_1 = require("../test/scripts/pw-locator-patch/dismiss-overlays/typesafe");
|
|
10
|
-
const utils_1 = require("../test/scripts/pw-locator-patch/dismiss-overlays/utils");
|
|
11
|
-
const fixtures_1 = require("./fixtures");
|
|
12
|
-
fixtures_1.test.skip(!process.env.TYPESAFE_API_KEY, "TYPESAFE_API_KEY is not set");
|
|
13
|
-
function resultsFile() {
|
|
14
|
-
return node_path_1.default.join(fixtures_1.test.info().project.outputDir, "typesafe-overlay-results.jsonl");
|
|
15
|
-
}
|
|
16
|
-
const DISMISS_ATTEMPTS = 3;
|
|
17
|
-
async function actWithTypeSafeDismissal(page, target, action) {
|
|
18
|
-
const results = [];
|
|
19
|
-
for (let attempt = 0;; attempt++) {
|
|
20
|
-
try {
|
|
21
|
-
await target[action]({ timeout: 3_000 });
|
|
22
|
-
return results;
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
if (attempt === DISMISS_ATTEMPTS || !(0, dismiss_overlays_1.isErrorSupported)(error.message)) {
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
const element = (0, dismiss_overlays_1.extractInterceptingElement)(error.message);
|
|
29
|
-
const text = await (0, utils_1.textContent)(page, element);
|
|
30
|
-
const result = await (0, typesafe_1.dismissWithTypeSafe)(page, {
|
|
31
|
-
text,
|
|
32
|
-
target: await target.elementHandle(),
|
|
33
|
-
});
|
|
34
|
-
results.push(result);
|
|
35
|
-
node_fs_1.default.mkdirSync(node_path_1.default.dirname(resultsFile()), { recursive: true });
|
|
36
|
-
node_fs_1.default.appendFileSync(resultsFile(), JSON.stringify({
|
|
37
|
-
test: fixtures_1.test.info().title,
|
|
38
|
-
attempt,
|
|
39
|
-
overlayText: text,
|
|
40
|
-
...result,
|
|
41
|
-
}) + "\n");
|
|
42
|
-
if (!result.dismissed) {
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
(0, fixtures_1.test)("dismisses the toast but not the dialog", async ({ page, server }) => {
|
|
49
|
-
await page.goto(`${server.baseURL}/choose-an-overlay.html`);
|
|
50
|
-
await actWithTypeSafeDismissal(page, page.getByRole("button", { name: "Target" }), "click");
|
|
51
|
-
await (0, fixtures_1.expect)(page.getByText("This is a toast message")).not.toBeVisible();
|
|
52
|
-
await (0, fixtures_1.expect)(page.getByRole("heading", { name: "Center Overlay" })).toBeVisible();
|
|
53
|
-
});
|
|
54
|
-
(0, fixtures_1.test)("ticks the checkbox and accepts terms", async ({ page, server }) => {
|
|
55
|
-
await page.goto(`${server.baseURL}/tos.html`);
|
|
56
|
-
page.on("dialog", (dialog) => dialog.dismiss());
|
|
57
|
-
await actWithTypeSafeDismissal(page, page.getByRole("button", { name: "Target" }), "click");
|
|
58
|
-
await (0, fixtures_1.expect)(page.getByRole("heading", { name: "Terms of Service" })).not.toBeVisible();
|
|
59
|
-
});
|
|
60
|
-
(0, fixtures_1.test)("dismisses a product tour and terms in sequence", async ({ page, server, }) => {
|
|
61
|
-
await page.goto(`${server.baseURL}/loop-to-dismiss.html`);
|
|
62
|
-
await actWithTypeSafeDismissal(page, page.getByRole("button", { name: "Target" }), "click");
|
|
63
|
-
await (0, fixtures_1.expect)(page.getByText("Clicked!")).toBeVisible();
|
|
64
|
-
});
|
|
65
|
-
(0, fixtures_1.test)("dismisses a Survicate survey for hover", async ({ page, server }) => {
|
|
66
|
-
await page.goto(`${server.baseURL}/survey.html`);
|
|
67
|
-
await (0, fixtures_1.expect)(page.getByText("Start survey")).toBeVisible({ timeout: 15_000 });
|
|
68
|
-
await actWithTypeSafeDismissal(page, page.getByRole("button", { name: "Click target" }), "hover");
|
|
69
|
-
});
|
|
70
|
-
(0, fixtures_1.test)("cannot fill a form overlay", async ({ page, server }) => {
|
|
71
|
-
await page.goto(`${server.baseURL}/overlay-form.html`);
|
|
72
|
-
await (0, fixtures_1.expect)(actWithTypeSafeDismissal(page, page.getByRole("button", { name: "Target" }), "click")).rejects.toThrow();
|
|
73
|
-
});
|
|
74
|
-
(0, fixtures_1.test)("does not click a page control when the toast has no close button", async ({ page, server, }) => {
|
|
75
|
-
await page.goto(`${server.baseURL}/toast-without-close.html`);
|
|
76
|
-
await (0, fixtures_1.expect)(actWithTypeSafeDismissal(page, page.getByRole("button", { name: "Target" }), "click")).rejects.toThrow();
|
|
77
|
-
await (0, fixtures_1.expect)(page.getByText("Project closed")).not.toBeVisible();
|
|
78
|
-
});
|
|
79
|
-
(0, fixtures_1.test)("does not click anything for an invisible glass pane", async ({ page, server, }) => {
|
|
80
|
-
await page.goto(`${server.baseURL}/glass-pane.html`);
|
|
81
|
-
let dialogOpened = false;
|
|
82
|
-
page.on("dialog", (dialog) => {
|
|
83
|
-
dialogOpened = true;
|
|
84
|
-
return dialog.dismiss();
|
|
85
|
-
});
|
|
86
|
-
await (0, fixtures_1.expect)(actWithTypeSafeDismissal(page, page.getByRole("button", { name: "Target" }), "click")).rejects.toThrow();
|
|
87
|
-
(0, fixtures_1.expect)(dialogOpened).toBe(false);
|
|
88
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ElementHandle, Page } from "playwright-core";
|
|
2
|
-
type Box = {
|
|
3
|
-
top: number;
|
|
4
|
-
bottom: number;
|
|
5
|
-
left: number;
|
|
6
|
-
right: number;
|
|
7
|
-
};
|
|
8
|
-
export type TypeSafeDismissStep = {
|
|
9
|
-
popupProbability: number;
|
|
10
|
-
box: Box;
|
|
11
|
-
boxConfidence: number;
|
|
12
|
-
clicked: {
|
|
13
|
-
x: number;
|
|
14
|
-
y: number;
|
|
15
|
-
} | undefined;
|
|
16
|
-
hitCheck: HitCheck | undefined;
|
|
17
|
-
latencyMs: number;
|
|
18
|
-
inputTokens: number;
|
|
19
|
-
outputTokens: number;
|
|
20
|
-
};
|
|
21
|
-
type Point = {
|
|
22
|
-
x: number;
|
|
23
|
-
y: number;
|
|
24
|
-
};
|
|
25
|
-
type HitCheck = "ok" | "no_blocker" | "outside_overlay" | "not_clickable";
|
|
26
|
-
export type TypeSafeStopReason = "popup_gone" | "low_box_confidence" | Exclude<HitCheck, "ok"> | "no_visual_change" | "max_steps";
|
|
27
|
-
export type TypeSafeDismissResult = {
|
|
28
|
-
dismissed: boolean;
|
|
29
|
-
stopReason: TypeSafeStopReason;
|
|
30
|
-
steps: TypeSafeDismissStep[];
|
|
31
|
-
};
|
|
32
|
-
export declare function dismissWithTypeSafe(page: Page, overlay: {
|
|
33
|
-
text: string | undefined;
|
|
34
|
-
target: ElementHandle<Element>;
|
|
35
|
-
}): Promise<TypeSafeDismissResult>;
|
|
36
|
-
export declare function checkHit(target: ElementHandle<Element>, point: Point): Promise<"no_blocker" | "not_clickable" | "ok" | "outside_overlay">;
|
|
37
|
-
export {};
|
|
38
|
-
//# sourceMappingURL=typesafe.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typesafe.d.ts","sourceRoot":"","sources":["../../../../../src/test/scripts/pw-locator-patch/dismiss-overlays/typesafe.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAQ3D,KAAK,GAAG,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAWxE,MAAM,MAAM,mBAAmB,GAAG;IAChC,gBAAgB,EAAE,MAAM,CAAC;IACzB,GAAG,EAAE,GAAG,CAAC;IACT,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAC9C,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,KAAK,KAAK,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,KAAK,QAAQ,GAAG,IAAI,GAAG,YAAY,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAE1E,MAAM,MAAM,kBAAkB,GAC1B,YAAY,GACZ,oBAAoB,GACpB,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,GACvB,kBAAkB,GAClB,WAAW,CAAC;AAEhB,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,KAAK,EAAE,mBAAmB,EAAE,CAAC;CAC9B,CAAC;AAEF,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;CAAE,GACpE,OAAO,CAAC,qBAAqB,CAAC,CAoDhC;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,sEAyDpE"}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dismissWithTypeSafe = dismissWithTypeSafe;
|
|
4
|
-
exports.checkHit = checkHit;
|
|
5
|
-
const node_crypto_1 = require("node:crypto");
|
|
6
|
-
const SYSTEM_ONE_URL = "https://api.typesafe.ai/v1/systemone";
|
|
7
|
-
const MODEL = "jev-preview";
|
|
8
|
-
const MAX_STEPS = 4;
|
|
9
|
-
const MIN_POPUP_PROBABILITY = 0.5;
|
|
10
|
-
const MIN_BOX_CONFIDENCE = 0.3;
|
|
11
|
-
async function dismissWithTypeSafe(page, overlay) {
|
|
12
|
-
const steps = [];
|
|
13
|
-
const stop = (stopReason) => ({
|
|
14
|
-
dismissed: stopReason === "popup_gone" && steps.length > 1,
|
|
15
|
-
stopReason,
|
|
16
|
-
steps,
|
|
17
|
-
});
|
|
18
|
-
let previousScreenshot;
|
|
19
|
-
for (let i = 0; i < MAX_STEPS; i++) {
|
|
20
|
-
const viewport = page.viewportSize();
|
|
21
|
-
if (!viewport) {
|
|
22
|
-
throw new Error("Viewport size is required for TypeSafe dismissal");
|
|
23
|
-
}
|
|
24
|
-
const screenshot = await page.screenshot({ type: "png" });
|
|
25
|
-
if (previousScreenshot?.equals(screenshot)) {
|
|
26
|
-
return stop("no_visual_change");
|
|
27
|
-
}
|
|
28
|
-
previousScreenshot = screenshot;
|
|
29
|
-
const startedAt = Date.now();
|
|
30
|
-
const response = await askSystemOne(screenshot, overlay.text);
|
|
31
|
-
const { popup_visible, dismiss_control } = response.answers;
|
|
32
|
-
const step = {
|
|
33
|
-
popupProbability: popup_visible.noul,
|
|
34
|
-
box: dismiss_control.box,
|
|
35
|
-
boxConfidence: dismiss_control.confidence,
|
|
36
|
-
clicked: undefined,
|
|
37
|
-
hitCheck: undefined,
|
|
38
|
-
latencyMs: Date.now() - startedAt,
|
|
39
|
-
inputTokens: response.usage.input_tokens,
|
|
40
|
-
outputTokens: response.usage.output_tokens,
|
|
41
|
-
};
|
|
42
|
-
steps.push(step);
|
|
43
|
-
if (popup_visible.noul < MIN_POPUP_PROBABILITY) {
|
|
44
|
-
return stop("popup_gone");
|
|
45
|
-
}
|
|
46
|
-
if (dismiss_control.confidence < MIN_BOX_CONFIDENCE) {
|
|
47
|
-
return stop("low_box_confidence");
|
|
48
|
-
}
|
|
49
|
-
const { box } = dismiss_control;
|
|
50
|
-
const point = {
|
|
51
|
-
x: Math.round(((box.left + box.right) / 2) * viewport.width),
|
|
52
|
-
y: Math.round(((box.top + box.bottom) / 2) * viewport.height),
|
|
53
|
-
};
|
|
54
|
-
step.hitCheck = await checkHit(overlay.target, point);
|
|
55
|
-
if (step.hitCheck !== "ok") {
|
|
56
|
-
return stop(step.hitCheck);
|
|
57
|
-
}
|
|
58
|
-
step.clicked = point;
|
|
59
|
-
await page.mouse.click(point.x, point.y);
|
|
60
|
-
await page.waitForTimeout(300);
|
|
61
|
-
}
|
|
62
|
-
return stop("max_steps");
|
|
63
|
-
}
|
|
64
|
-
function checkHit(target, point) {
|
|
65
|
-
return target.evaluate((targetEl, { x, y }) => {
|
|
66
|
-
const deepHit = (px, py) => {
|
|
67
|
-
let el = document.elementFromPoint(px, py);
|
|
68
|
-
while (el?.shadowRoot) {
|
|
69
|
-
const inner = el.shadowRoot.elementFromPoint(px, py);
|
|
70
|
-
if (!inner || inner === el) {
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
el = inner;
|
|
74
|
-
}
|
|
75
|
-
return el;
|
|
76
|
-
};
|
|
77
|
-
const parentOf = (el) => el.parentNode instanceof ShadowRoot
|
|
78
|
-
? el.parentNode.host
|
|
79
|
-
: el.parentElement;
|
|
80
|
-
const isAncestorOrSelf = (ancestor, el) => {
|
|
81
|
-
for (let n = el; n; n = parentOf(n)) {
|
|
82
|
-
if (n === ancestor) {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return false;
|
|
87
|
-
};
|
|
88
|
-
const rect = targetEl.getBoundingClientRect();
|
|
89
|
-
const blocker = deepHit(rect.left + rect.width / 2, rect.top + rect.height / 2);
|
|
90
|
-
if (!blocker || isAncestorOrSelf(targetEl, blocker)) {
|
|
91
|
-
return "no_blocker";
|
|
92
|
-
}
|
|
93
|
-
let overlayRoot = blocker;
|
|
94
|
-
for (let p = parentOf(overlayRoot); p && !isAncestorOrSelf(p, targetEl); p = parentOf(p)) {
|
|
95
|
-
overlayRoot = p;
|
|
96
|
-
}
|
|
97
|
-
const hit = deepHit(x, y);
|
|
98
|
-
if (!hit || !isAncestorOrSelf(overlayRoot, hit)) {
|
|
99
|
-
return "outside_overlay";
|
|
100
|
-
}
|
|
101
|
-
const interactive = 'button, a[href], input, select, label, summary, iframe, [role=button], [role=link], [role=checkbox], [role=menuitem], [role=tab], [onclick], [tabindex]:not([tabindex="-1"])';
|
|
102
|
-
for (let n = hit; n; n = parentOf(n)) {
|
|
103
|
-
if (n.matches(interactive) || getComputedStyle(n).cursor === "pointer") {
|
|
104
|
-
return "ok";
|
|
105
|
-
}
|
|
106
|
-
if (n === overlayRoot) {
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return "not_clickable";
|
|
111
|
-
}, point);
|
|
112
|
-
}
|
|
113
|
-
async function askSystemOne(screenshot, overlayText) {
|
|
114
|
-
const apiKey = process.env.TYPESAFE_API_KEY;
|
|
115
|
-
if (!apiKey) {
|
|
116
|
-
throw new Error("TYPESAFE_API_KEY is not set");
|
|
117
|
-
}
|
|
118
|
-
const reference = (0, node_crypto_1.randomUUID)();
|
|
119
|
-
const popup = overlayText
|
|
120
|
-
? `the popup that contains the text "${overlayText.trim().slice(0, 300)}"`
|
|
121
|
-
: "the popup";
|
|
122
|
-
const body = {
|
|
123
|
-
model: MODEL,
|
|
124
|
-
state: {
|
|
125
|
-
screenshot: reference,
|
|
126
|
-
context: "A browser test was blocked because a popup (modal, toast, survey, banner or product tour) covers the element it wants to click.",
|
|
127
|
-
},
|
|
128
|
-
assets: {
|
|
129
|
-
[reference]: {
|
|
130
|
-
type: "image",
|
|
131
|
-
format: "png",
|
|
132
|
-
data_base64: screenshot.toString("base64"),
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
questions: {
|
|
136
|
-
popup_visible: {
|
|
137
|
-
type: "noul",
|
|
138
|
-
instructions: `Is ${popup} still visible in \`screenshot\`?`,
|
|
139
|
-
},
|
|
140
|
-
dismiss_control: {
|
|
141
|
-
type: "box",
|
|
142
|
-
instructions: `the single control in \`screenshot\` to click next to dismiss ${popup}: a close (×) button, or a Close, Skip, No thanks, Got it, Accept, Agree or Continue button. Prefer the option that accepts or continues over Decline or Cancel. If a required checkbox must be ticked first, the checkbox. Never the page's own controls behind the popup.`,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
const response = await fetch(SYSTEM_ONE_URL, {
|
|
147
|
-
method: "POST",
|
|
148
|
-
headers: {
|
|
149
|
-
Authorization: `Bearer ${apiKey}`,
|
|
150
|
-
"Content-Type": "application/json",
|
|
151
|
-
"TypeSafe-Danger-Zone-Images": "true",
|
|
152
|
-
},
|
|
153
|
-
body: JSON.stringify(body),
|
|
154
|
-
});
|
|
155
|
-
if (!response.ok) {
|
|
156
|
-
throw new Error(`TypeSafe ${response.status}: ${await response.text()}`);
|
|
157
|
-
}
|
|
158
|
-
return (await response.json());
|
|
159
|
-
}
|