Extension Input Method Editor API: Composition, Candidates, and Virtual Keyboards
How Chrome extension input.ime methods control composition, candidates, key events, and assistive windows—and when calls fail without the active IME.
This page summarises Chrome extension documentation for browser.input.ime and the Manifest V2 alias chrome.input.ime. Developers use these APIs when an extension acts as the active input method engine: updating inline composition, showing conversion candidates, driving a virtual keyboard, or exposing language-menu actions. Almost every write path is scoped by a contextID that identifies which focused input context owns the operation.
input.ime: what the API is for
Section titled “input.ime: what the API is for”An input method extension does not replace normal typing by itself; it receives events from the platform (including onKeyEvent when configured) and pushes state back through promise-based methods on browser.input.ime. The MV2 reference chrome.input.ime documents the same surface with optional callbacks on each call, while the unified browser.* namespace returns promises only.
Typical workflows fall into three buckets: composition (provisional text before commit), candidate UI (pick lists and paging), and synthetic keys (sendKeyEvents for on-screen keyboards). Menu APIs (setMenuItems, updateMenuItems) extend the language menu while your engine is active.
Owning the active IME: when calls succeed or fail
Section titled “Owning the active IME: when calls succeed or fail”Many methods check whether your extension owns the engine the user is typing with right now. If not, the platform rejects the update or treats the call as a no-op.
| Method | If extension does not own the active IME |
|---|---|
clearComposition, setComposition, setCandidates, setCandidateWindowProperties |
Returns false (failed) |
setCursorPosition |
No-op |
setComposition / clearComposition (stated explicitly) |
Fails |
Clear the current composition. If this extension does not own the active IME, this fails.
— Chrome, browser.input.ime
Sets the current candidate list. This fails if this extension doesn’t own the active IME
— Chrome, browser.input.ime
Set the position of the cursor in the candidate window. This is a no-op if this extension does not own the active IME.
— Chrome, browser.input.ime
Always thread the contextID from the active input context into parameters. Using a stale contextID after focus moves is a common reason composition updates appear to “do nothing” even when your extension is selected in the IME list.
Composition: set, clear, and commit text
Section titled “Composition: set, clear, and commit text”Composition is the provisional string shown before the user confirms a word or phrase.
How setComposition and clearComposition work
Section titled “How setComposition and clearComposition work”setComposition installs composition text, caret index, optional selection range, and optional segments (each with start, end, and style as an UnderlineStyle). clearComposition drops the in-progress composition for the given contextID. Both return Promise<boolean> and fail when your extension is not the active IME.
Set the current composition. If this extension does not own the active IME, this fails.
— Chrome, browser.input.ime
How commitText finalises input
Section titled “How commitText finalises input”commitText writes finished characters into the field. Parameters are contextID and text. Use commit when the user accepts a reading—not while you still want an underline “in progress” state.
Commits the provided text to the current input.
— Chrome, browser.input.ime
A practical sequence for many scripts is: setComposition while the user narrows readings → user confirms → commitText → optionally clearComposition if the platform still holds stale composition state.
Candidate window: lists, layout, and selection
Section titled “Candidate window: lists, layout, and selection”Candidate APIs separate what to show from how the window behaves.
setCandidates structure
Section titled “setCandidates structure”setCandidates takes contextID and an array of candidate objects. Each candidate needs id and candidate (display string). Optional fields include label (shortcut or index), annotation, parentId for hierarchy, and usage with title / body for detail text.
setCandidateWindowProperties options
Section titled “setCandidateWindowProperties options”setCandidateWindowProperties targets an engineID and a properties object. Notable toggles:
| Property | Effect |
|---|---|
visible |
Show or hide the candidate window |
pageSize |
Candidates per page |
vertical |
Vertical vs horizontal layout |
windowPosition |
WindowPosition placement |
auxiliaryText / auxiliaryTextVisible |
Footer line below the list |
cursorVisible |
Caret visibility inside the window |
currentCandidateIndex / totalCandidates |
Highlight and counts (Chrome 84+) |
Sets the properties of the candidate window. This fails if the extension doesn’t own the active IME
— Chrome, browser.input.ime
setCursorPosition selects a candidate by candidateID within the owning contextID. Pair it with setCandidates / window property updates when the user moves through pages with keyboard shortcuts.
Virtual keyboards and keyEventHandled
Section titled “Virtual keyboards and keyEventHandled”sendKeyEvents for on-screen keys
Section titled “sendKeyEvents for on-screen keys”Virtual keyboards should not only insert Unicode strings; sometimes they must replay key semantics (modifiers, arrows, shortcuts). sendKeyEvents accepts contextID (or 0 to target a non-input focus) and keyData as an array of KeyboardEvent-shaped objects.
Sends the key events. This function is expected to be used by virtual keyboards. When key(s) on a virtual keyboard is pressed by a user, this function is used to propagate that event to the system.
— Chrome, browser.input.ime
Answering onKeyEvent when handling is asynchronous
Section titled “Answering onKeyEvent when handling is asynchronous”If your onKeyEvent listener decides keys asynchronously, you must report completion with keyEventHandled(requestId, response), passing whether the extension consumed the event (response boolean). The docs restrict this to async handling paths.
Indicates that the key event received by onKeyEvent is handled. This should only be called if the onKeyEvent listener is asynchronous.
— Chrome, browser.input.ime
Forgetting keyEventHandled leaves the input pipeline waiting; calling it on a synchronous listener can double-handle keys.
Assistive windows, input view, and language menu
Section titled “Assistive windows, input view, and language menu”AssistiveWindow properties and undo UI
Section titled “AssistiveWindow properties and undo UI”setAssistiveWindowProperties (Chrome 85+) shows or hides an assistive window for a contextID, using AssistiveWindowProperties. Related types include visible and optional announceString for ChromeVox. For undo-style UI, type may be "undo".
setAssistiveWindowButtonHighlighted (Chrome 86+) toggles highlight on an AssistiveWindowButton inside a given windowType (e.g. "undo"), with optional announceString for screen reader announcement.
hideInputView
Section titled “hideInputView”hideInputView() dismisses the system-populated input view. If it is already hidden, the call does nothing—safe to invoke when your custom UI fully replaces the default view.
Hides the input view window, which is popped up automatically by system. If the input view window is already hidden, this function will do nothing.
— Chrome, browser.input.ime
Language menu items
Section titled “Language menu items”setMenuItems adds entries to the language menu while your IME is active; updateMenuItems mutates existing MenuParameters. These are Promise<void> entry points without the same ownership boolean return as composition, but they only matter when users have picked your engine.
browser.input.ime vs chrome.input.ime
Section titled “browser.input.ime vs chrome.input.ime”| Aspect | browser.input.ime |
chrome.input.ime |
|---|---|---|
| Reference | input IME (MV3 / unified) | input_ime (MV2) |
| Callbacks | Promises only | Optional per-call callbacks plus promises |
| Method set | Same names and parameters for the methods covered here | Same |
New work should target browser.input.ime; MV2 pages remain relevant when maintaining legacy extensions that still call chrome.input.ime.* with callbacks.
Common mistakes
Section titled “Common mistakes”- Calling
setCompositionorsetCandidateswithout checking the returnedbooleanafter focus or IME switches. - Committing with
commitTextwhile a composition underline should still be visible—users see duplicated or out-of-order glyphs. - Using
sendKeyEventswith a non-zerocontextIDwhen focus is not in an editable field (use0only when you intend non-input targeting). - Invoking
keyEventHandledfrom synchronousonKeyEventhandlers. - Omitting
engineIDonsetCandidateWindowPropertiesordeleteSurroundingTextwhen multiple engines are registered.
How to check this on your site
Section titled “How to check this on your site”-
Load your unpacked extension, select its IME in the OS/browser input method list, and focus a text field so you receive a stable
contextIDin IME events. -
Step through composition: call
setComposition, confirm the underline appears, thencommitTextand verify committed characters match expectations per browser.input.ime. -
Populate
setCandidatesand togglesetCandidateWindowProperties(visible,pageSize); confirm failure returnsfalsewhen another IME is active. -
On a virtual keyboard path, press a key and verify
sendKeyEventsreaches the focused field; for asynconKeyEvent, confirmkeyEventHandledfires once per pending request. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page does not match the behaviour you see in Chrome, email yimasynthetic@gmail.com with the page URL and the exact statement you are questioning so it can be corrected or clarified.