推荐关注
› Meteor
› JSLint - a JavaScript code quality tool
› jsFiddle
› D3.js
› WebStorm
推荐书目
› JavaScript 权威指南第 5 版
› Closure: The Definitive Guide
shanlanlan

chrome 的事件监听断点(event listener breakpoints)能监听: alert 吗?

  •  
  •   shanlanlan · Jun 24, 2020 · 3541 views
    This topic created in 2348 days ago, the information mentioned may be changed or developed.

    在页面 debug 调试的时候,经常被 alert 打断,有办法直接定位到这个 alert 吗?

    例如:click 事件可以设置事件断点,那么 alert 方法可以断点吗?


    虚心请教大佬。

    6 replies  •  2020-06-24 21:06:11 +08:00
    Mutoo
    Mutoo
    Jun 24, 2020❤️1
    1
    alert 是全局函数,直接替换掉:

    origAlert = alert;
    alert = (...parmas) => {
    debugger;
    origAlert(...params)
    }

    然后断点后看 Call Stack 即可。
    rioshikelong121
    rioshikelong121
    Jun 24, 2020❤️2
    2
    控制台 debug(window.alert) 试试
    azcvcza
    azcvcza
    Jun 24, 2020❤️1
    3
    参照 js 高级程序设计的例子,可以给 Function prototype 绑 before 和 after,然后传入 window.alert,在 before 和 after 里调 debugger 吧
    shanlanlan
    shanlanlan
    OP
    Jun 24, 2020
    4
    @rioshikelong121 #2 原文:“控制台 debug(window.alert) 试试”
    ======
    回复:亲测有效。
    shanlanlan
    shanlanlan
    OP
    Jun 24, 2020
    5
    @rioshikelong121 #2 原文:“控制台 debug(window.alert) 试试”
    ======
    回复:感谢,已经成功解决了问题。定位到代码后,直接把网站的 if 判断改为了:if(true)了,调试通过。
    rioshikelong121
    rioshikelong121
    Jun 24, 2020❤️1
    6
    @shanlanlan 嗯 没事可以看看 Chrome DevTools 的文档。 还是有很多新奇的功能。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1927 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 11:13 · PVG 19:13 · LAX 03:13 · JFK 06:13
    ♥ Do have faith in what you're doing.