diff --git a/bin/muse-chat-api.py b/bin/muse-chat-api.py index 8ae2c14..37599db 100755 --- a/bin/muse-chat-api.py +++ b/bin/muse-chat-api.py @@ -323,14 +323,17 @@ def cmd_upload(ws, filepath, message=None, dry_run=False): cdp_call(ws, "DOM.setFileInputFiles", {"nodeId": node_id, "files": [os.path.abspath(filepath)]}) time.sleep(2) - # Read-back: the attachment preview must appear. + # Read-back: the attachment chip must appear. Match on the + # element's OWN text: React swaps the file input after change, so + # input.files is unreliable, and innerText on ancestors over-matches. base = os.path.basename(filepath) preview = ev(ws, """(() => { const needle = %s; - const hits = [...document.querySelectorAll('*')].filter(e => { - const t = e.innerText || ''; - return t.length < 300 && t.includes(needle); - }).map(e => e.innerText.slice(0, 120)); + const own = e => [...e.childNodes].filter(n => n.nodeType === 3) + .map(n => n.nodeValue).join(''); + const hits = [...document.querySelectorAll('*')] + .filter(e => own(e).includes(needle)) + .map(e => e.tagName + ': ' + own(e).slice(0, 80)); return JSON.stringify(hits.slice(0, 5)); })()""" % json.dumps(base)) print("preview: %s" % preview)