Is there a way using JavaScript or jQuery to detect if a confirm or alert box is being displayed?
To add to @user113716's answer you can rely on time. I assume that if confirm dialog took less than 200 ms, it is blocked by browser. Below I return true if confirm dialog is blocked (by default it returns false, the code is in TypeScript).
let oldConfirm = window.confirm;
window.confirm = (msg) => {
let time = new Date().getTime();
let conf = oldConfirm(msg);
return new Date().getTime() - time > 200 ? conf : true;
}