| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- """Dump ALL children of ready_start (full list) and click the actual 启动 part."""
- import asyncio
- import json
- import sys
- import httpx
- import websockets
- async def main():
- async with httpx.AsyncClient(timeout=5) as c:
- r = await c.get("http://127.0.0.1:9222/json/list")
- det = next((t for t in r.json() if "gameDetail" in t.get("url", "")), None)
- if not det:
- print("no gameDetail")
- return 1
- async with websockets.connect(det["webSocketDebuggerUrl"], max_size=10**7) as ws:
- mid = 0
- async def ev(expr):
- nonlocal mid
- mid += 1
- await ws.send(json.dumps({"id": mid, "method": "Runtime.evaluate",
- "params": {"expression": expr, "returnByValue": True}}))
- while True:
- m = json.loads(await ws.recv())
- if m.get("id") == mid:
- return m.get("result", {}).get("result", {}).get("value")
- async def click(x, y):
- nonlocal mid
- mid += 1
- await ws.send(json.dumps({"id": mid, "method": "Input.dispatchMouseEvent",
- "params": {"type": "mousePressed", "x": x, "y": y, "button": "left", "clickCount": 1, "buttons": 1}}))
- await asyncio.sleep(0.07)
- mid += 1
- await ws.send(json.dumps({"id": mid, "method": "Input.dispatchMouseEvent",
- "params": {"type": "mouseReleased", "x": x, "y": y, "button": "left", "clickCount": 1, "buttons": 0}}))
- while True:
- m = json.loads(await ws.recv())
- if m.get("id") == mid:
- return
- info = await ev("""
- (function() {
- const btn = document.querySelector('.ready_start');
- if (!btn) return JSON.stringify([]);
- const kids = [];
- btn.querySelectorAll('*').forEach(k => {
- const kr = k.getBoundingClientRect();
- if (kr.width > 20 && kr.height > 8) {
- kids.push({cls: (k.className || '').toString().slice(0, 32),
- text: (k.innerText || '').trim().slice(0, 15),
- x: Math.round(kr.x + kr.width/2), y: Math.round(kr.y + kr.height/2)});
- }
- });
- return JSON.stringify(kids);
- })()
- """)
- kids = json.loads(info or "[]")
- print("=== ready_start ALL children ===")
- for k in kids:
- print(f" '{k['text']}' cls={k['cls']} @({k['x']},{k['y']})")
- # pick the element whose class/text looks like the actual start button
- target = None
- for k in kids:
- cls = k["cls"].lower()
- if "start" in cls or "btn" in cls or "launch" in cls or "go" in cls:
- if "select" not in cls and "mode" not in cls:
- target = k
- break
- if not target:
- # bottom-most child (the button is usually below the selector rows)
- if kids:
- target = max(kids, key=lambda k: k["y"])
- if not target:
- print("no target found")
- return 1
- print(f"\nTARGET: '{target['text']}' cls={target['cls']} @({target['x']},{target['y']})")
- print("clicking...")
- await click(target["x"], target["y"])
- await asyncio.sleep(4)
- # what happened?
- url = await ev("location.href")
- print(f"url: {url[:80]}")
- modal = await ev("""
- (function() {
- const m = document.querySelector('.ant-modal, [class*=modal], [class*=dialog], [class*=downloader]');
- return m ? (m.innerText || '').slice(0, 100) : null;
- })()
- """)
- print(f"modal/dialog: {modal}")
- return 0
- sys.exit(asyncio.run(main()))
|