javascript - How to delete content from content-editable field on facebookmessenger.com? - Stack Overflow
I am building a chrome extension that inserts text into the current text box.
I want to first delete all the text in the area and then insert the new text when the function is called. I have written some javascript code that works fine on many websites (such as /
).
focusedInputBox.focus();
const range = document.createRange();
range.selectNodeContents(focusedInputBox);
const sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
document.execCommand("delete");
document.execCommand("insertText", false, newText);
The problem comes when I try to do this on /
, which is the main usecase for this code. The exec command to insert text works but the one to delete doesn't do anything and fails with no errors. Instead the new text is pasted before the existing text, leading to lots of duplication.
This is what the HTML element there looks like
<div
aria-describedby=":rav:"
aria-label="Message"
class="xzsf02u x1a2a7pz x1n2onr6 x14wi4xw x1iyjqo2 x1gh3ibb xisnujt xeuugli x1odjw0f notranslate"
contenteditable="true"
role="textbox"
spellcheck="true"
tabindex="0"
aria-placeholder="Aa"
style="user-select: text; white-space: pre-wrap; word-break: break-word;"
data-lexical-editor="true">
<p class="xat24cr xdj266r"><br></p>
</div>
I have tried setting the text content with innerHtml
and textContent
but neither work to update it.
Not sure how to debug this or delete the content as expected so anything would be helpful
- 覆盖7大手机品牌近4亿安卓用户,“互传联盟”让分享更容易
- 微软苹果和谷歌引导:硬件触控化或是大趋势
- 有点厉害 win10兼容安卓应用方式曝光
- c++ - Android OpenXR application java.io.FileNotFoundException: apexcom.meta.xrpriv-appVrDriverVrDriver.apk - Stack Overflow
- swift - How do I know how many times a thread context switch happens on an xcode Instruments? - Stack Overflow
- flutter - App Name Not Updating in Android Recent Apps View Despite Manifest and Strings Configuration - Stack Overflow
- material ui - Using ShadowDOM to address MUI 5 vs MUI 6 Compatibility Issue? - Stack Overflow
- c++ - templates are instantiated despite having extern template - Stack Overflow
- Supabase - new row violates row-level security policy - Stack Overflow
- c++ - Which option has precendence if I enable and disable FrontEndHeapDebugOptions at the same time? - Stack Overflow
- solrcloud - How to use "or" in an eDisMax query in Solr 9.4? - Stack Overflow
- python - Four MLX90640 thermal cameras on 4 custom buses in Rasberry Pi 5B - Stack Overflow
- Has Paho MQTT Client for Ionic on Android limitations regarding the number of client instances? - Stack Overflow
- I can't receive messages through my webhook with Whatsapp Cloud API - Stack Overflow
- asp.net - Delete Button does not delete in C# Webforms - Stack Overflow
- system verilog - Do delta cycles occur at intermediate stages in SystemVerilog? - Stack Overflow
- VS Code : How to deactivate matching characters in bold? - Stack Overflow