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",
|
cdp_call(ws, "DOM.setFileInputFiles",
|
||||||
{"nodeId": node_id, "files": [os.path.abspath(filepath)]})
|
{"nodeId": node_id, "files": [os.path.abspath(filepath)]})
|
||||||
time.sleep(2)
|
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)
|
base = os.path.basename(filepath)
|
||||||
preview = ev(ws, """(() => {
|
preview = ev(ws, """(() => {
|
||||||
const needle = %s;
|
const needle = %s;
|
||||||
const hits = [...document.querySelectorAll('*')].filter(e => {
|
const own = e => [...e.childNodes].filter(n => n.nodeType === 3)
|
||||||
const t = e.innerText || '';
|
.map(n => n.nodeValue).join('');
|
||||||
return t.length < 300 && t.includes(needle);
|
const hits = [...document.querySelectorAll('*')]
|
||||||
}).map(e => e.innerText.slice(0, 120));
|
.filter(e => own(e).includes(needle))
|
||||||
|
.map(e => e.tagName + ': ' + own(e).slice(0, 80));
|
||||||
return JSON.stringify(hits.slice(0, 5));
|
return JSON.stringify(hits.slice(0, 5));
|
||||||
})()""" % json.dumps(base))
|
})()""" % json.dumps(base))
|
||||||
print("preview: %s" % preview)
|
print("preview: %s" % preview)
|
||||||
|
|||||||
Reference in New Issue
Block a user