Fix context menu when shadow DOM is enabled

Closes #4623