ebidel

#55488: fix: release right-clicked nodes after the context-menu event

Merged
Created: Oct 29, 2026, 4:54:07 PM
Merged: Oct 29, 2026, 7:43:06 PM
6 comments
Target: main

Description of Change

Fixes #55487.

Electron emits 'context-menu' and leaves the menu to the app, so nothing calls WebContents::NotifyContextMenuClosed the way Chrome's RenderViewContextMenu does when its menu closes. Blink's ContextMenuController then keeps its hit-test result, which holds the right-clicked node and every ancestor, until the next context menu. A page that removes those nodes can't collect them.

This PR calls NotifyContextMenuClosed() right after the event is emitted. Electron shows its own menus and never sends the renderer a custom-item command, so nothing reads that state afterwards. The DevTools path already notifies (devtools_context_menu.cc).

Not covered: right-clicks on selected text. Blink also starts two link-to-text generators over the selection (TextFragmentHandler and AnnotationAgentGenerator), and each keeps the selection's nodes. AnnotationAgentContainer has no browser-side cancel, so that case needs a Blink change, e.g. resetting preemptive generation in ContextMenuController::ClearContextMenu(). It's tracked in #55487.

Tests. The spec right-clicks a full-page node, removes it, forces GC, and checks that a payload attached to the node was collected. On stock Electron 44.1.0 and 45.0.0 the payload stays alive in 3/3 runs, and the control without a right-click collects it. @georgexu99 built main + this change on macOS arm64: the spec passes 3/3, fails 3/3 without the change, and still passes without the window having focus.

I have not built Electron locally (no full Xcode on this machine).

Checklist

Release Notes

Notes: Fixed a leak where right-clicked elements stayed alive after removal.

Backports

45-x-y
In-flight
PR Number
#55503
Waiting to be merged
46-x-y
In-flight
PR Number
#55502
Waiting to be merged

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