#56015: fix: crash when a spellcheck provider answers a superseded request
Description of Change
Since Electron 41, using webFrame.setSpellCheckProvider can crash the renderer in editors that change the selection or contents from script, such as CKEditor.
Cause
Chromium 146 (CL 7452579) made Blink's spellcheck user-action restrictions always on. When the selection or contents change without a user gesture, Blink now cancels the in-flight spellcheck request and later sends a new one. SpellCheckClient isn't told about the cancellation, and it assumed only one request at a time.
- Request B replaces request A while the provider still holds A's callback.
- A's callback finishes B using A's results, then clears B.
- B's callback dereferences null, and the renderer crashes.
Fix
Each request gets an ID, which is bound to both the posted SpellCheckText task and the JS callback. Callbacks and tasks for requests that were replaced or already finished are now ignored. This also covers a provider calling the same callback twice. Chrome's own SpellCheckProvider uses the same approach, keying completions by ID (add) and dropping unknown ones (lookup).
Test
A new crash case, spellcheck-provider-superseded-request, holds the provider's callbacks, types until Blink sends a second request, then calls both callbacks. It's a crash case rather than a webFrame spec because spec/index.js enables UnrestrictSpellingAndGrammarForTesting, which turns off the restriction that triggers this. Without the fix it fails with exit code 1 (renderer gone). With the fix it passes, as do the existing api-web-frame and spellchecker specs.
Manual verification
I ran the reporter's CKEditor repro side by side on unfixed main (left) and on main plus this fix (right). It's not made totally clear in the video, but the before-side crashes and is totally unresponsive to clicks and any other input.
before-after-spellcheck-crash-fix.mp4
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
-
npm testpasses - tests are changed or added
- relevant API documentation, tutorials, and examples are updated and follow the documentation style guide
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, past tense, and no longer than 80 characters.
This PR fixes #55399.
Assisted-By: Claude Opus 5.5, Claude Code
Release Notes
Notes: Fixed a renderer crash when using webFrame.setSpellCheckProvider in editors that change the selection or contents from script.
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron