fix obs popup issues
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { runOverlaySmoke } from "./browser_overlays.js";
|
||||
import { runRaceSetupSmoke } from "./browser_race_setup.js";
|
||||
import { runRaceDaySmoke } from "./browser_race_day.js";
|
||||
import { runObsPopupSmoke } from "./browser_obs_popup.js";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn } from "node:child_process";
|
||||
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
||||
@@ -78,6 +79,20 @@ try {
|
||||
if (result.exceptionDetails) throw new Error(result.exceptionDetails.exception?.description || result.exceptionDetails.text);
|
||||
return result.result.value;
|
||||
}
|
||||
// A synthetic element.click() from Runtime.evaluate does not count as a trusted user
|
||||
// gesture, so Chrome's popup blocker silently drops any window.open() it triggers.
|
||||
// Dispatching real input events is required for scenarios that open a popup window.
|
||||
async function realClick(selector) {
|
||||
// scrollIntoView first: Input.dispatchMouseEvent uses viewport coordinates, so a
|
||||
// button below the fold (the default headless window is short) would otherwise get
|
||||
// "clicked" at a point outside the visible page and silently hit nothing.
|
||||
const box = await evaluate(`(() => { const el = document.querySelector(${JSON.stringify(selector)}); if (!el) return null; el.scrollIntoView({ block: "center" }); const r = el.getBoundingClientRect(); return JSON.stringify({ x: r.x + r.width / 2, y: r.y + r.height / 2, w: r.width, h: r.height }); })()`);
|
||||
if (!box) throw new Error("realClick: element not found for " + selector);
|
||||
const { x, y, w, h } = JSON.parse(box);
|
||||
if (!w || !h) throw new Error("realClick: element has zero size for " + selector);
|
||||
await send("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "left", clickCount: 1 });
|
||||
await send("Input.dispatchMouseEvent", { type: "mouseReleased", x, y, button: "left", clickCount: 1 });
|
||||
}
|
||||
await send("Runtime.enable");
|
||||
await send("Page.enable");
|
||||
await send("Network.enable");
|
||||
@@ -118,6 +133,7 @@ try {
|
||||
}
|
||||
await runRaceSetupSmoke({ evaluate, navigate, fill, savedState, waitFor, pause });
|
||||
await runRaceDaySmoke({ evaluate, navigate, fill, savedState, waitFor, pause, base, dialogs });
|
||||
await runObsPopupSmoke({ evaluate, navigate, fill, savedState, waitFor, pause, base, debugPort, dialogs, realClick });
|
||||
await navigate("classes", "classForm");
|
||||
await send("Network.emulateNetworkConditions", { offline: true, latency: 0, downloadThroughput: -1, uploadThroughput: -1 });
|
||||
await fill("classForm", { name: "Offline Draft" });
|
||||
|
||||
Reference in New Issue
Block a user