I’m opening a pop-up from a page (main page). I’m then checking constantly if the pop-up is still open or has been closed. I’m doing that with the code below
const checkForPopUp = async function() {
try {
while(!extFrame?.closed) {
await new Promise(resolve => setTimeout(resolve, 250));
}
return true;
}
catch (error) {
console.log(error);
}
}
However, at some point the pop-up redirects to another domain so the browser throws the error Cross-Origin-Opener-Policy policy would block the window.closed call
directly when checking if the pop-up is still open or not. The error is not caught by try/catch
nor by window.onerror
, nor by window.onunhandledrejection
.
How can I catch this specific error and handle it differently so that it doesn’t print as an error?