| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- """Inspect the current 996box game page via CDP: what page are we on, is the
- session alive, is there a 启动 button for 玖扬复古176?
- Then click it (with capture running in background) to trigger the REAL
- launch flow: EnterGameClient -> openApp -> cq.exe -> cq2.exe -> TCP login.
- """
- import asyncio
- import base64
- import json
- import sys
- import httpx
- import websockets
- async def get_targets():
- async with httpx.AsyncClient(timeout=5) as c:
- r = await c.get("http://127.0.0.1:9222/json/list")
- return r.json()
- async def cdp(ws, msg_id, method, params=None):
- await ws.send(json.dumps({"id": msg_id, "method": method, "params": params or {}}))
- while True:
- msg = json.loads(await ws.recv())
- if msg.get("id") == msg_id:
- return msg.get("result", {})
- async def cdp_eval(ws, expr, msg_id):
- return await cdp(ws, msg_id, "Runtime.evaluate", {"expression": expr, "returnByValue": True})
- async def main():
- targets = await get_targets()
- print("=== targets ===")
- web_pages = []
- for t in targets:
- if t["type"] == "page":
- print(f" [{t['type']}] {t.get('title','')[:40]:<40} {t['url'][:70]}")
- if "http" in t["url"]:
- web_pages.append(t)
- if not web_pages:
- print("no web pages")
- return 1
- # Prefer the hzwlan/996box game page
- page = next((t for t in web_pages if "hzwlan" in t["url"] or "996box.com" in t["url"]), web_pages[0])
- print(f"\ninspecting: {page['url'][:70]}")
- async with websockets.connect(page["webSocketDebuggerUrl"], max_size=10**7) as ws:
- # 1. page state
- res = await cdp_eval(ws, """
- JSON.stringify({
- url: location.href.slice(0,80),
- title: document.title,
- bodyLen: document.body ? document.body.innerText.length : 0,
- bodyHead: document.body ? document.body.innerText.slice(0,300) : ''
- })
- """, 1)
- val = res.get("result", {}).get("value", "{}")
- try:
- st = json.loads(val)
- print(f"\nurl: {st['url']}")
- print(f"title: {st['title']}")
- print(f"body text (first 300):")
- print(f" {st['bodyHead'][:300]}")
- except Exception:
- print(val[:400])
- # 2. look for the game + start button
- res2 = await cdp_eval(ws, """
- (function() {
- // find any element mentioning 玖扬 or 复古 or the game id 206923
- const all = document.querySelectorAll('*');
- let gameEl = null;
- for (const el of all) {
- if (el.children.length === 0 && el.innerText && (
- el.innerText.includes('玖扬') || el.innerText.includes('复古176'))) {
- gameEl = el; break;
- }
- }
- // find start/launch buttons
- const starts = Array.from(document.querySelectorAll('button, [class*=start], [class*=launch], [class*=play]'))
- .filter(b => b.offsetParent && (b.innerText||'').match(/启动|开始|进入|继续/))
- .slice(0,10)
- .map(b => ({text: b.innerText.trim().slice(0,20), cls: (b.className||'').toString().slice(0,50)}));
- return JSON.stringify({
- foundGame: !!gameEl,
- gameText: gameEl ? gameEl.innerText.slice(0,40) : '',
- starts: starts
- });
- })()
- """, 2)
- val2 = res2.get("result", {}).get("value", "{}")
- try:
- g = json.loads(val2)
- print(f"\ngame found on page: {g['foundGame']} ({g['gameText']})")
- print(f"start buttons: {len(g['starts'])}")
- for s in g["starts"]:
- print(f" '{s['text']}' cls={s['cls'][:40]}")
- except Exception:
- print(val2[:400])
- # 3. screenshot
- shot = await cdp(ws, 3, "Page.captureScreenshot", {"format": "png"})
- if shot.get("data"):
- with open("cdp_game_page.png", "wb") as f:
- f.write(base64.b64decode(shot["data"]))
- print("\nscreenshot: cdp_game_page.png")
- return 0
- sys.exit(asyncio.run(main()))
|