Reliably inserting text into various fields

114 views
Skip to first unread message

Rahul Bansal

unread,
Sep 14, 2024, 12:01:13 AMSep 14
to Chromium Extensions
I'm building a Chrome extension which can insert text into places where the user can type. It could be a text field, text area, input field, content editable, or the WYSIWYG editor.

my current approach for building is to simulate paste by below command      document.execCommand('insertText', false, content); // Simulate paste

This approach doesn't work reliably across all websites. For example, it doesn't work in Google Chat, and it doesn't work in Slack Web. It works reliably in Twitter, Reddit, etc. How do I solve this problem reliably across multiple websites?

And if I want to extend it further by allowing me to change existing text inside, how can I achieve that?

My approach is to select via the selection page and then insert via the paste event, but the paste event doesn't work reliably.

Reply all
Reply to author
Forward
0 new messages