muse-chat-api.py upload: verify chip by own-text (React swaps the input)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user