gpt4 book ai didi

javascript - 控制台不记录内容脚本中的 js 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:38:55 26 4
gpt4 key购买 nike

我知道要调试内容脚本,请使用普通的 Web 开发人员工具 (https://developer.mozilla.org/en/docs/Mozilla/Add-ons/WebExtensions/Debugging#Debugging_content_scripts),这非常有效。 debugger 关键字按预期工作。

但在这种情况下,事情就坏了:

addon.id = "123-568-485"; // I never define `addon` before this line, so this cause: ReferenceError: "addon is not defined". We aren't aware of this mistake.

// Some more code
// Some more code
// Some more code
// Some more code

debugger; // Here we want to stop execution and inspect, some other stuff. Remember that we aren't aware of earlier mistake.

如我们所料,控制台中会出现关于 Reference error 的错误,但实际上并没有。控制台静默,我们不知道为什么我们的 debugger 关键字不起作用。

这种无提示错误,当我拼错变量名时发生在我身上。结果无法找出问题所在。

最佳答案

由于 Firefox bug 1410932 未修复(截至 2020 年 7 月 28 日发布的 Firefox 79),标签页的 Web 控制台中未报告内容脚本中的错误。

我在 another answer 中列出了可能的解决方法:

  • use try..catch with logging,
  • check the Browser Console (which does show errors from the content script)
  • use the Debugger's "pause on exceptions" option.

关于javascript - 控制台不记录内容脚本中的 js 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53237090/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com