From 36e24bf9fe554e709258d3c2b985acbadc7d8b65 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Fri, 4 Dec 2026 21:09:50 +0100 Subject: [PATCH] Lobby-Klicks echt: CDP Input.dispatchMouseEvent (isTrusted) statt DOM-Ereignisse, mit Trefferpruefung und JS-Rueckfall --- lobby/cdp.mjs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lobby/cdp.mjs b/lobby/cdp.mjs index c6c2afb7..661d7b6b 100644 --- a/lobby/cdp.mjs +++ b/lobby/cdp.mjs @@ -25,11 +25,13 @@ async function seite() { || liste.find((t) => t.type === "page"); } -// Ein Klick, zwei Wege (hand/eingabe.py): im Klon die Ereignisse in der Seite; sonst mit der Maus -// nur die Bildschirmlage des Knopfs ("MAUS {x, y, text}") - den -// Klick macht Python. Alle Klicks dieser Datei und mcp/lobby_adapter.KLICK_ZEILE gehen hierüber. +// Ein Klick, drei Wege (hand/eingabe.py): mit EINGABE=maus nur die Bildschirmlage ("MAUS {x,y}") +// - den Klick macht Python; sonst ein ECHTER Klick über CDP `Input.dispatchMouseEvent` ("CDP {x,y}", +// isTrusted:true wie eine Hand); mit EINGABE=js die alten synthetischen DOM-Ereignisse als Rueckfall. +// Alle Klicks dieser Datei und mcp/lobby_adapter.KLICK_ZEILE gehen hierüber. const MAUS = process.env.EINGABE === "maus"; -const VORSPANN = `window.__pfMaus = ${MAUS}; +const JS_KLICK = process.env.EINGABE === "js"; +const VORSPANN = `window.__pfMaus = ${MAUS}; window.__pfJs = ${JS_KLICK}; window.__pfKlick = (ziel) => { // Was nicht im Bild steht, trifft kein Mausklick: der Reiterstreifen scrollt waagerecht // ("horizontal-scroll-container", overflow auto), die hinteren Reiter liegen ausserhalb des @@ -45,8 +47,14 @@ window.__pfKlick = (ziel) => { y: window.screenY + kopf + r.y + r.height / 2, text: (ziel.innerText || "").trim().replace(/\\s+/g, " ").slice(0, 50)}); } + const mitte = { x: r.x + r.width / 2, y: r.y + r.height / 2, + text: (ziel.innerText || "").trim().replace(/\\s+/g, " ").slice(0, 50) }; + // Nur echt klicken, wenn der Punkt auch trifft: liegt etwas davor, faellt es auf JS zurueck. + const oben = document.elementFromPoint(mitte.x, mitte.y); + const trifft = oben && (oben === ziel || ziel.contains(oben) || oben.contains(ziel)); + if (!window.__pfJs && trifft) return "CDP " + JSON.stringify(mitte); const opt = { bubbles: true, cancelable: true, composed: true, button: 0, - clientX: r.x + r.width / 2, clientY: r.y + r.height / 2 }; + clientX: mitte.x, clientY: mitte.y }; for (const art of ["pointerdown", "mousedown", "pointerup", "mouseup", "click"]) { ziel.dispatchEvent(art.startsWith("pointer") ? new PointerEvent(art, opt) : new MouseEvent(art, opt)); } @@ -156,7 +164,16 @@ async function main() { const r = await senden("Runtime.evaluate", { expression: VORSPANN + "\n" + expr, returnByValue: true, awaitPromise: true }); if (r.result?.exceptionDetails) return "Fehler: " + JSON.stringify(r.result.exceptionDetails).slice(0, 300); - return r.result?.result?.value; + const wert = r.result?.result?.value; + if (typeof wert === "string" && wert.startsWith("CDP ")) { // echter Klick, wie eine Hand + const p = JSON.parse(wert.slice(4)); + for (const art of ["mouseMoved", "mousePressed", "mouseReleased"]) { + await senden("Input.dispatchMouseEvent", + { type: art, x: p.x, y: p.y, button: "left", clickCount: art === "mouseMoved" ? 0 : 1 }); + } + return "geklickt (echt): " + p.text; + } + return wert; }; const klick = flag("--click");