#53493: fix: don't throw when adding or removing console-message listeners on a destroyed WebContents
Merged
Created: Sep 3, 2026, 7:27:52 PM
Merged: Sep 3, 2026, 8:28:08 PM
5 comments
Target: main
#53115 added newListener / removeListener hooks that call _setConsoleMessageObserved() without checking isDestroyed(). EventEmitter emits those synchronously, so on a destroyed WebContents the native Object has been destroyed error escapes from on('console-message'), removeListener('console-message') and removeAllListeners(), aborting teardown sweeps partway through.
- Skip the native call in both hooks once the WebContents is destroyed; JS listener bookkeeping is unchanged.
- Specs for add, remove and
removeAllListenerson a destroyed WebContents.
Notes: Fixed webContents.on(), removeListener() and removeAllListeners() throwing "Object has been destroyed" for console-message listeners after the WebContents was destroyed.
Backports
Semver Impact
Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.
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