SpellChecker | Electron
https://www.electronjs.org/docs/latest/tutorial/spellchecker • 56 KB fetched Open original page
SpellChecker | Electron
Skip to main content
Electron Docs API Blog Tools
* Electron Forge
* Electron Fiddle
Community
* Governance
* Showcase
* Resources
Releases English
* English
* Deutsch
* Español
* Français
* 日本語
* Português
* Русский
* 中文
Search
* Get Started
* Processes in Electron
* Best Practices
* Examples
* Dark Mode
* Device Access
* In-App Purchases
*
* Keyboard Shortcuts
* Deep Links
* Desktop Launcher Actions
*
* Menus
* Multithreading
* Native File Drag & Drop
* Navigation History
* Notifications
* Offscreen Rendering
* Online/Offline Event Detection
* Progress Bars
* Recent Documents
*
*
* Representing Files in a BrowserWindow
*
* SpellChecker
* Web Embeds
* Taskbar Customization
*
* Window Customization
* Development
* Native Node Modules
* Distribution
* Testing And Debugging
* References
* Contributing
*
* Examples
* SpellChecker On this page
SpellChecker
Electron has built-in support for Chromium's spellchecker since Electron 8. On Windows and Linux this is powered by Hunspell dictionaries, and on macOS it makes use of the native spellchecker APIs.
How to enable the spellchecker?
For Electron 9 and higher the spellchecker is enabled by default. For Electron 8 you need to enable it in webPreferences .
const myWindow = new BrowserWindow ( {
webPreferences : {
spellcheck : true
}
} )
How to set the languages the spellchecker uses?
On macOS as we use the native APIs there is no way to set the language that the spellchecker uses. By default on macOS the native spellchecker will automatically detect the language being used for you.
For Windows and Linux there are a few Electron APIs you should use to set the languages for the spellchecker.
// Sets the spellchecker to check English US and French
myWindow . webContents . session . setSpellCheckerLanguages ( [ 'en-US' , 'fr' ] )
// An array of all available language codes
const possibleLanguages = myWindow . webContents . session . availableSpellCheckerLanguages
By default the spellchecker will enable the language matching the current OS locale.
How do I put the results of the spellchecker in my context menu?
All the required information to generate a context menu is provided in the context-menu event on each webContents instance. A small example
of how to make a context menu with this information is provided below.
const { Menu , MenuItem } = require ( 'electron' )
myWindow . webContents . on ( 'context-menu' , ( event , params ) => {
const menu = new Menu ( )
// Add each spelling suggestion
for ( const suggestion of params . dictionarySuggestions ) {
menu . append ( new MenuItem ( {
label : suggestion ,
click : ( ) => myWindow . webContents . replaceMisspelling ( suggestion )
} ) )
}
// Allow users to add the misspelled word to the dictionary
if ( params . misspelledWord ) {
menu . append (
new MenuItem ( {
label : 'Add to dictionary' ,
click : ( ) => myWindow . webContents . session . addWordToSpellCheckerDictionary ( params . misspelledWord )
} )
)
}
menu . popup ( )
} )
Does the spellchecker use any Google services?
Although the spellchecker itself does not send any typings, words or user input to Google services the hunspell dictionary files are downloaded from a Google CDN by default. If you want to avoid this you can provide an alternative URL to download the dictionaries from.
myWindow . webContents . session . setSpellCheckerDictionaryDownloadURL ( 'https://example.com/dictionaries/' )
Check out the docs for session.setSpellCheckerDictionaryDownloadURL for more information on where to get the dictionary files from and how you need to host them.
Edit this page
Previous
Representing Files in a BrowserWindow
Next
Web Embeds
* How to enable the spellchecker?
* How to set the languages the spellchecker uses?
* How do I put the results of the spellchecker in my context menu?
* Does the spellchecker use any Google services?
Docs
* Getting Started
* API Reference
Checklists
* Performance
* Security
Tools
* Electron Forge
* Electron Fiddle
Community
* Governance
* Resources
* Bluesky
* X
* Mastodon
* Stack Overflow
More
* GitHub
* Open Collective
* Infrastructure Dashboard
Copyright OpenJS Foundation and Electron contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation , please see our Trademark Policy and Trademark List . Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them. The OpenJS Foundation | Terms of Use | Privacy Policy | Bylaws | Code of Conduct | Trademark Policy | Trademark List | Cookie Policy
Hosting and infrastructure graciously provided by
Links found on this page
- Skip to main content [direct]
- Electron [direct]
- Docs [direct]
- API [direct]
- Blog [direct]
- Electron Forge [direct]
- Electron Fiddle [direct]
- Governance [direct]
- Showcase [direct]
- Resources [direct]
- Releases [direct]
- Deutsch [direct]
- Español [direct]
- Français [direct]
- 日本語 [direct]
- Português [direct]
- Русский [direct]
- 中文 [direct]
- Processes in Electron [direct]
- Best Practices [direct]
- Examples [direct]
- Dark Mode [direct]
- Device Access [direct]
- In-App Purchases [direct]
- Keyboard Shortcuts [direct]
- Deep Links [direct]
- Desktop Launcher Actions [direct]
- Menus [direct]
- Multithreading [direct]
- Native File Drag & Drop [direct]
- Navigation History [direct]
- Notifications [direct]
- Offscreen Rendering [direct]
- Online/Offline Event Detection [direct]
- Progress Bars [direct]
- Recent Documents [direct]
- Representing Files in a BrowserWindow [direct]
- Web Embeds [direct]
- Taskbar Customization [direct]
- Window Customization [direct]
- Development [direct]
- Native Node Modules [direct]
- Distribution [direct]
- Testing And Debugging [direct]
- References [direct]
- Contributing [direct]
- context-menu [direct]
- session.setSpellCheckerDictionaryDownloadURL [direct]
- Edit this page [direct]
- Security [direct]
- Bluesky [direct]
- X [direct]
- Mastodon [direct]
- Stack Overflow [direct]
- GitHub [direct]
- Open Collective [direct]
- Infrastructure Dashboard [direct]
- OpenJS Foundation [direct]
- Trademark Policy [direct]
- Trademark List [direct]
- Terms of Use [direct]
- Privacy Policy [direct]
- Bylaws [direct]
- Code of Conduct [direct]
- Cookie Policy [direct]
|
|