How to detect closure of chrome.windows windows?

If I create a popup using chrome.windows.create(), is there a way the calling script can detect said window being closed? Without ugly things like wait loops?

It seems windows.create resolves with a promise which has windowId. You can then watch for that windowId with the window.onRemoved listener -

Thanks. It seems that in my case the windows.onRemoved listener fires not when the window is closed, but the next time after that that one is opened. This is my first time dealing with Javascript Promises, so I must not be thinking async enough.