The struggle is determining the center of the current screen in a multi-monitor setup, so I finally solved this by centering the pop-up over the parent window. You have to pass the parent window as another parameter:
<script>
function popupWindow(url='', windowName='', win, w='650', h='650') {
const y = win.top.outerHeight / 2 + win.top.screenY - ( h / 2);
const x = win.top.outerWidth / 2 + win.top.screenX - ( w / 2);
return win.open(
url,