This is perfectly reasonable code and logically sound.
I'm speculating, in your head you're thinking, it doesn't make sense to wait for something that hasn't even happened yet. So, post, then listen, then receive.
postMessage -> addEventListener -> (receive).
But I see it like this:
I'm going to send you a message and want you to let me know when we get a reply. Promise?
addEventListener -> postMessage -> (receive)
The AI isn't being defensive, it's just ordering the logic sequence differently.
This is much closer to how event handlers and callbacks work in system/backend platforms/languages.