You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks #51064
I agree to follow the Code of Conduct that this project adheres to.
I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
41.2.0, 36.4.0
What operating system(s) are you using?
Windows
Operating System Version
Windows 11 26100
What arch are you using?
x64
Last Known Working Electron version
No response
Does the issue also appear in Chromium / Google Chrome?
No
Expected Behavior
NativeWindowViews::SetForwardMouseMessages function unhooks the global mouse hook using UnhookWindowsHookEx(mouse_hook_) when the forwarding_windows_ set becomes empty. It should verify the return value of UnhookWindowsHookEx
Actual Behavior
If UnhookWindowsHookEx fails (returns FALSE), the existing hook remains active in the system. Because mouse_hook_ is reset to nullptr regardless of success, subsequent calls to SetForwardMouseMessages(true) will evaluate if (!mouse_hook_) as true. This causes SetWindowsHookEx to be called again, installing an additional, duplicate mouse hook
changed the title [-]Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/-][+][Windows] Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/+]on Apr 15, 2026
changed the title [-][Windows] Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/-][+]Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/+]on Apr 15, 2026
Would you be able to download Electron Fiddle, use it to create a small sample app that allows maintainers to reproduce this issue, and upload it as a GitHub gist from Fiddle?
Hello @qiaohang. Thanks for reporting this and helping to make Electron better!
Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.
Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.
Now adding the
blocked/need-reproNeeds a test case to reproduce the bug
label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.
Would you be able to download Electron Fiddle, use it to create a small sample app that allows maintainers to reproduce this issue, and upload it as a GitHub gist from Fiddle?
This issue is not consistently reproducible and tends to occur more easily on certain machines, though not on mine. Through code review and checking the API documentation for UnhookWindowsHookEx it was found that the return value of UnhookWindowsHookEx is not being checked.
Activity
electron-issue-triage commentedon Apr 15, 2026
[-]Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/-][+][Windows] Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/+][-][Windows] Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/-][+]Unchecked return value of UnhookWindowsHookEx in NativeWindowViews::SetForwardMouseMessages leads to duplicate mouse hooks[/+]nikwen commentedon Apr 15, 2026
Thanks for reporting!
Would you be able to download Electron Fiddle, use it to create a small sample app that allows maintainers to reproduce this issue, and upload it as a GitHub gist from Fiddle?
electron-issue-triage commentedon Apr 15, 2026
Hello @qiaohang. Thanks for reporting this and helping to make Electron better!
Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.
Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.
Now adding the blocked/need-reproNeeds a test case to reproduce the bug
label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.
qiaohang commentedon Apr 15, 2026
This issue is not consistently reproducible and tends to occur more easily on certain machines, though not on mine. Through code review and checking the API documentation for UnhookWindowsHookEx it was found that the return value of UnhookWindowsHookEx is not being checked.
fix: preserve mouse hook handle when UnhookWindowsHookEx fails
fix: preserve mouse hook handle when UnhookWindowsHookEx fails
fix: preserve mouse hook handle when UnhookWindowsHookEx fails
fix: preserve mouse hook handle when UnhookWindowsHookEx fails
fix: preserve mouse hook handle when UnhookWindowsHookEx fails
fix: preserve mouse hook handle when UnhookWindowsHookEx fails
fix: preserve mouse hook handle when UnhookWindowsHookEx fails (#51098)
fix: preserve mouse hook handle when UnhookWindowsHookEx fails (#51418)
fix: preserve mouse hook handle when UnhookWindowsHookEx fails (#51419)