electron
electron copied to clipboard
[Bug]: `tray.getBounds()` initially returns the incorrect `x` and `y` values on macOS
Preflight Checklist
- [X] I have read the Contributing Guidelines for this project.
- [X] I agree to follow the Code of Conduct that this project adheres to.
- [X] I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
21.1.0
What operating system are you using?
macOS
Operating System Version
12.6 (Monterey)
What arch are you using?
arm64 (including Apple Silicon)
Last Known Working Electron version
No response
Expected Behavior
tray.getBounds() should return current bounds when called shortly after the initialisation of the Tray. If this is not possible then the tray instance should emit a ready event so that we know when getBounds() will return the correct bounds.
Actual Behavior
tray.getBounds() returns an incorrect value until some arbitrary time has passed. In my testcase it takes approx 500ms for the correct value to be returned.
Testcase Gist URL
https://gist.github.com/davej/be1503e76acb237fc2ef513445d80b70
Additional Information
Output of my test case above. Only setTimeout:500 is correct.
Electron v21.1.0 started.
sync { x: 0, y: 956, width: 16, height: 36 }
setImmediate { x: 0, y: 956, width: 16, height: 36 }
setTimeout:50 { x: 0, y: 956, width: 16, height: 36 }
setTimeout:500 { x: 931, y: 0, width: 16, height: 36 }
This is probably the same bug as reported in #33515.
Just to note: there's some additional details/investigation into the cause of this in #36031, which I closed as a duplicate of this issue.
Looking forward to the fix
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
Still an issue.
Facing same shit when trying to create window based on tray bounds instantly after creating tray

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
bump
@clavin Is there any update on this issue? I'm facing it too. Here's some information to help out with debugging:
Expected Behaviour: trayIcon.getBounds() should return the correct values for x, and y which are needed for me to set my window position correctly w.r.t. the tray icon.
Extended Context: I checked getting these bound values using setTimeout too. Even after 10 * 1000 (10 seconds) of delay, the values are incorrect.
System:
Electron Version: 26.2.1
OS: Mac OS
OS Version: Sonoma (14.0)
Arch: arm64 (Apple Silicon)
Values:
trayIcon.getBounds() = { x: 0, y: 900, width: 32, height: 24 }
mainWindow.getBounds() = { x: 520, y: 287, width: 400, height: 327 }
app.isPackaged = false