Re: [w3c/editing] Should execCommand dispatch beforeinput or not? (#200)

GaurangTandon left a comment (w3c/editing#200)

Following up on the previous WG meeting: here's a brief table comparing real user inputs to their corresponding execCommand emulation from an extension content script. (Key events and the non standard textInput event are omitted from the table, since they are not relevant here)

| Real user action                                 | Corresponding execCommand arguments  | Real user events                                                                                   |
| :------------------------------------- | :------------------------- | :------------------------------------------------------------------------------------------------- |
| letter `a` (ce / textarea / input)     | `"insertText", false, "a"` | **beforeinput(insertText, "a")** → input(insertText, "a") → selectionchange                        |
| Enter in contenteditable               | `"insertParagraph"`        | **beforeinput(insertParagraph)** → input(insertParagraph) → selectionchange                        |
| Shift+Enter in contenteditable | `"insertLineBreak"`        | **beforeinput(insertLineBreak)** → input(insertLineBreak) → selectionchange                        |
| Backspace (all)                        | `"delete"`                 | **beforeinput(deleteContentBackward)** → input(deleteContentBackward) → selectionchange            |
| Paste Ctrl+V/Cmd+V (all)                      | `"paste"`                  | paste(clipboardData) → **beforeinput(insertFromPaste)** → input(insertFromPaste) → selectionchange |

- On Chrome 154, execCommand from a content script produces the same events as the real user action, _except_ the beforeinput event (bolded).
- On Firefox 157, execCommand from a content script produces the same events as the real user action, _including_ the beforeinput event.

For our use case, emulating user input in text fields from an extension, we recommend that execCommand called from an extension content script dispatch a beforeinput event, with the same inputType and data as the equivalent user action, for at least the following `commandName`s: `insertText`, `insertParagraph`, `insertLineBreak`, `delete` and `paste`.

I think the next action is for Chrome team members to check this.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/editing/issues/200#issuecomment-5951475331
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/editing/issues/200/5951475331@github.com>

Received on Friday, 2 October 2026 11:33:44 UTC