Skip to content

document.execCommand has valid use cases without viable alternatives #40245

Open
@lionel-rowe

Description

@lionel-rowe

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand

What specific section or headline is this issue about?

Top

What information was incorrect, unhelpful, or incomplete?

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

That's a bit misleading, especially the "Be aware that this feature may cease to work at any time" part (removing execCommand will never happen as it would be massively web-breaking).

What did you expect to see?

Perhaps a custom warning instead, noting that behavior may differ somewhat between browsers, but also noting that there are still valid use cases given that there's still no viable alternative.

Do you have any supporting links, references, or citations?

javascript - execCommand() is now obsolete, what's the alternative? - Stack Overflow

Year 2022–2025 answer: The execCommand() is officially obsolete/deprecated but there's no alternative. So if you must have rich text support, you have to keep using execCommand() and figure out yourself what actually works with browsers that you want to support.

Note that real world user agents (browsers such as Chrome, Firefox and Safari) cannot drop support for execCommand() because so many services require support for it.

...

All the current standardization efforts (Input Events 2, Clipboard API) fail to even try to cover the features that execCommand() actually does (for example, undo/redo, actually changing content within the selection range).

...

For background information: medium.com/content-uneditable/…

Do you have anything more you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions