繁体   English   中英

反正有没有用javascript检测警报?

[英]Is there anyway to detect alert with javascript?

目前我是 javascript 新手,当我对我的任务有了想法时,我遇到了一些问题。

我不知道我们是否可以使用 javascript 检测警报?

我搜索并找到了这个主题,但它没有多大帮助。 检测页面上是否显示警报或确认

当我尝试用我的脚本解决验证码时出现的问题: https : //i.imgur.com/w0ISrHC.png

我预计:如果我们的脚本检测到“无法联系 reCAPTCHA。请检查您的连接并重试。”

我们将刷新页面并检查然后再次尝试解决验证码。

我认为打开警报后您将无法知道和运行任何脚本。 打开你的控制台并运行 interval 来测试它:

setInterval(() => console.log('test'), 1000);

然后运行:

alert(1);

在您关闭警报之前,您将看到该时间间隔不会记录“测试”。

要做到这一点,您可能需要创建另一个应用程序,该应用程序将在另一个选项卡中工作并向其发送消息。 如果另一个应用程序将检测到超时 - 那么您可以重新加载页面。

更新

或者您可以在警报调用时覆盖警报并重新加载页面:

window.alert = () => location.reload();

试试这个小提琴 我对警报功能做了一个黑客,然后你可以检查消息以注入你的东西。

(function (window) {
    const _alert = window.alert
    window.alert = (message) => {
        window.onAlert && window.onAlert(message, _alert)
    }
})(window)

function createRecaptcha() {
    grecaptcha.render("recaptcha", {sitekey: "6LcgSAMTAAAAACc2C7rc6HB9ZmEX4SyB0bbAJvTG", theme: "light"});
}

createRecaptcha();

window.onAlert = (message, alert) => {
  if(message === 'Cannot contact reCAPTCHA. Check your connection and try again.') {
    // do your stuffs, for example:
    document.body.innerHTML = '<h1>The alert is injected</h1>'
    return
  }

  alert(message)
}
alert('application alert')

兴趣问题,我有一些简单的解决方案来防止警报。 首先我收集并记住什么是原始警报原型方法。 我覆盖警报。 其他程序很简单...

 window["cloneOriginAlert"] = alert; alert = function (msg, prevent) { if ( typeof prevent !== 'undefined') { return; } var test = prompt("You wanna see alert ? ", "Alert is comming !!! "); if (test != null) { console.warn("Alert is allowed here ! ", msg) window["cloneOriginAlert"](msg); } else { console.log("No alert here") } } alert("Hello bug")

我希望这就是你想要的!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM