Phenomenon
In iOS Safari, when using Korean keyboard input, composition events may not fire as expected. This makes it difficult to detect when IME composition is active, leading to issues with character handling and event processing.
Reproduction example
- Open a contenteditable div in iOS Safari.
- Switch to Korean keyboard.
- Type Korean characters (e.g., โ์๋ ํ์ธ์โ).
- Monitor for
compositionstart,compositionupdate, andcompositionendevents. - Observe that these events may not fire or fire inconsistently.
Observed behavior
- compositionstart: May not fire when Korean input begins.
- compositionupdate: May not fire during character composition.
- compositionend: May not fire when composition completes.
- beforeinput events: May fire with
inputType: "insertCompositionText"but composition events are missing. - input events: Fire normally but without composition context.
- This behavior is specific to iOS Safari and may not occur in other browsers.
Expected behavior
compositionstartshould fire when IME composition begins.compositionupdateshould fire as the composition text changes.compositionendshould fire when composition is committed or cancelled.- Event sequence should be:
compositionstartโcompositionupdate(multiple) โcompositionendโinput.
Analysis
iOS Safari handles IME input differently from desktop browsers. The composition events may be suppressed or handled internally by the browser, making them unavailable to JavaScript event listeners.
Workarounds
- Rely on
beforeinputevents withinputType: "insertCompositionText"to detect composition. - Use
inputevents and track state manually. - Check for composition state using
document.activeElementand selection ranges. - Implement fallback detection mechanisms for iOS Safari.