I was working on a script to mention members on WhatsApp groups by JS. All the work stopped when I wanted to change the innerHTML using the .innerHTML property to place a mention HTML block in it instead of writing the names of the members then focus the elemnt and clik on the contact name that pops up.
HTML of the input textbox on WA web
<div
class="fd365im1 to2l77zo bbv8nyr4 gfz4du6o ag5g9lrv bze30y65 kao4egtt"
style="max-height: 7.35em;
user-select: text;
white-space:
pre-wrap; word-break:
break-word;"
role="textbox"
spellcheck="false"
title="Type a message"
data-testid="conversation-compose-box-input"
data-tab="10"
data-lexical-editor="true"
contenteditable="true">
<!-- the inner HTML -->
<p class="selectable-text copyable-text iq0m558w">Test text</p>
</div>
JS to change its inner HTML
var typespace = document
.querySelector('div.fd365im1.to2l77zo.bbv8nyr4.gfz4du6o.ag5g9lrv.bze30y65.kao4egtt');
I have trying accessing the DOM by many ways and all the ways go to Rome and return the right address of the DOM but sruprisingly trying to
typespace.innerHTML = '<p class="selectable-text copyable-text iq0m558w" dir="ltr"><span class="selectable-text copyable-text o0rubyzf" data-app-text-template="201144292107@c.us" data-lexical-text="true">@Abdo Eid</span><span class="selectable-text copyable-text" data-lexical-text="true"> </span></p>
doesn't work at all. I noticed that after changing it manally from the HTML and trys to use innerHTML it works as expected.
OS: windows 10 lang: JS browser: Chrome, Firefox both at latest versions