Replace Ctrl+J with click-based chat activation\n\n- New _ensure_chat_active(): compose -> switcher -> nav-chat priority\n- hatch-nav-chat click recovers from stripped /thread/new state\n- Ctrl+J needed keyboard focus which stripped states lack
This commit is contained in:
+32
-30
@@ -271,36 +271,38 @@ def cmd_sidechat_create(ws):
|
|||||||
"""
|
"""
|
||||||
import time as _time
|
import time as _time
|
||||||
import json as _json
|
import json as _json
|
||||||
# Navigate to main chat first for known good state.
|
import sys as _sys2
|
||||||
# (Previous create may have left browser on /thread/new with stripped DOM.)
|
# Ensure chat is active via DOM clicks (replaces Ctrl+J).
|
||||||
# Uses Ctrl+J via CDP (proven method from cmd_sidechat_main).
|
# Ctrl+J needs keyboard focus which stripped states (/thread/new) lack.
|
||||||
# Fixed 2026-10-04 per reliability test: success poisons next run.
|
# Priority: compose (fast path) -> switcher -> nav-chat (recovery).
|
||||||
ws.send(_json.dumps({
|
# Verified 2026-10-04: hatch-nav-chat click recovers from /thread/new.
|
||||||
"id": 30, "method": "Input.dispatchKeyEvent",
|
def _ensure_chat_active(timeout=20):
|
||||||
"params": {"type": "keyDown", "key": "j", "code": "KeyJ",
|
t0 = _time.time()
|
||||||
"ctrlKey": True, "modifiers": 2}
|
while _time.time() - t0 < timeout:
|
||||||
}))
|
st = ev(ws, """(() => ({
|
||||||
_json.loads(ws.recv())
|
compose: !!document.querySelector('[data-testid="hatch-chat-compose"]'),
|
||||||
ws.send(_json.dumps({
|
switcher: !!document.querySelector('[data-testid="hatch-chat-switcher-trigger"]'),
|
||||||
"id": 31, "method": "Input.dispatchKeyEvent",
|
navchat: !!document.querySelector('[data-testid="hatch-nav-chat"]')
|
||||||
"params": {"type": "keyUp", "key": "j", "code": "KeyJ",
|
}))()""")
|
||||||
"ctrlKey": True, "modifiers": 2}
|
if not isinstance(st, dict):
|
||||||
}))
|
_time.sleep(1)
|
||||||
_json.loads(ws.recv())
|
continue
|
||||||
_time.sleep(3)
|
if st.get("compose"):
|
||||||
# Now open panel via switcher (should be on main chat with panel available)
|
return True
|
||||||
# Check for + button; if not present, click switcher.
|
if st.get("switcher"):
|
||||||
def _has_plus():
|
ev(ws, """document.querySelector('[data-testid="hatch-chat-switcher-trigger"]').click()""")
|
||||||
return ev(ws, """(() => {
|
_time.sleep(1.5)
|
||||||
return !!document.querySelector('[data-testid="hatch-chat-compose"]');
|
continue
|
||||||
})()""")
|
if st.get("navchat"):
|
||||||
|
ev(ws, """document.querySelector('[data-testid="hatch-nav-chat"]').click()""")
|
||||||
if not _has_plus():
|
_time.sleep(2)
|
||||||
ev(ws, """(() => {
|
continue
|
||||||
const sw = document.querySelector('[data-testid="hatch-chat-switcher-trigger"]');
|
_time.sleep(1)
|
||||||
if (sw) sw.click();
|
return False
|
||||||
})()""")
|
if not _ensure_chat_active():
|
||||||
_time.sleep(2)
|
print("ERROR: Could not activate chat (no compose/switcher/nav-chat)", file=_sys2.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
print("Chat active", file=_sys2.stderr)
|
||||||
# Find + button via data-testid (verified selector, SVG icon no text)
|
# Find + button via data-testid (verified selector, SVG icon no text)
|
||||||
result = ev(ws, """(() => {
|
result = ev(ws, """(() => {
|
||||||
const btn = document.querySelector('[data-testid="hatch-chat-compose"]');
|
const btn = document.querySelector('[data-testid="hatch-chat-compose"]');
|
||||||
|
|||||||
Reference in New Issue
Block a user