JSFiddle - React, Tailwind, and code Playground
HTML
<button id="btn">open popup</button>
<pre id="log"></pre>
JavaScript
btn.onclick = e => {
const popup = window.open('https://google.com');
waitForClose(popup, e => log.textContent += 'closed');
};
function waitForClose(win, cb) {
function poll() {
if(win.closed) {
cb();
}
else {
requestAnimationFrame(poll);
}
}
poll();
}