Fix sidechat selectors from DOM investigation\n\n- + button: [data-testid=hatch-chat-compose] (SVG, no text)\n- Panel: [data-testid=hatch-chat-switcher-trigger] (idempotent)\n- ensure_sidebar: check + button presence, not text (was false-positive\n on DM text containing Side chats)

This commit is contained in:
operator-main
2026-10-04 03:36:06 +00:00
parent 1cffacc7d1
commit bc4cd77a52
2 changed files with 29 additions and 54 deletions
+12 -15
View File
@@ -29,34 +29,31 @@ def _ev(ws, js, await_result=True):
def ensure_sidebar(ws, max_retries=3):
"""
Ensure the sidebar is open. Returns True if open, False otherwise.
Retries with backoff if the open button isn't found immediately.
Uses data-testid="hatch-chat-switcher-trigger" (reliable selector).
Fixed 2026-10-04: was using text matching which was flaky.
Ensure the chat panel is open. Returns True if open, False otherwise.
Checks for + button presence (not text - avoids false-positive on DM text
containing 'Side chats').
Fixed 2026-10-04: was checking innerText.includes('Side chats') which matched
DM message text, not the UI. Now checks for [data-testid="hatch-chat-compose"].
"""
for attempt in range(max_retries):
# Check if sidebar is already open (Side chats text visible)
# Check if panel is open via + button presence (reliable)
is_open = _ev(ws, """(() => {
return document.body.innerText.includes('Side chats');
return !!document.querySelector('[data-testid="hatch-chat-compose"]');
})()""")
if is_open:
return True
# Try to open it via data-testid (reliable)
clicked = _ev(ws, """(() => {
# Open via switcher trigger (idempotent)
_ev(ws, """(() => {
const btn = document.querySelector('[data-testid="hatch-chat-switcher-trigger"]');
if (btn) { btn.click(); return true; }
// Fallback: text matching
const fb = [...document.querySelectorAll('button')].find(b =>
(b.textContent||'').includes('Open chat and side chats'));
if (fb) { fb.click(); return true; }
return false;
if (btn) btn.click();
return !!btn;
})()""")
time.sleep(2 * (attempt + 1)) # Exponential backoff: 2s, 4s, 6s
# Final check
return _ev(ws, """(() => {
return document.body.innerText.includes('Side chats');
return !!document.querySelector('[data-testid="hatch-chat-compose"]');
})()""")
def list_sidechats(ws):