如何在Safari调试器中调试延迟加载的JavaScript [英] How to debug lazily-loaded javascripts in Safari debugger

查看:106
本文介绍了如何在Safari调试器中调试延迟加载的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的脚本,可以在运行时延迟加载javascript.每个页面上都有未知的依赖项,因此直到需要时才会全部加载它们.

I have a very simple script that lazy-loads javascripts at runtime. There are unknown dependencies on each page, so they are not all loaded until needed.

与大多数框架一样,这可以通过向文档头添加脚本标签来实现.

Like most frameworks, this works by adding a script tag to the document head.

一切正常,但是Safari调试器既未在元素"检查器中看到新的脚本标签,也未在脚本"选项卡中显示它们.错误被报告为发生在根文档上,而不是正确的脚本.

Everything executes fine, but the Safari debugger neither sees the new script tags in the "Elements" inspector, nor shows them in the "Scripts" tab. Errors are reported as occurring on the root document, rather than the proper script.

一个明显的解决方法是正常编写和调试所有内容,然后添加依赖项加载作为最后一步.但是我很想知道是否有更好的方法可以使调试器更快乐地进行延迟加载脚本?

An obvious workaround is to author and debug everything normally, and then add the dependency loading as a last step. But I would love to know if there is there a better way to lazy-load scripts that makes the debugger happier?

推荐答案

Safari在脚本"选项卡中有一个设置来暂停异常,从而在抛出异常时(或仅在抛出异常时)在代码点为您提供一个交互式调试器对于未处理的异常.

Safari has a setting in the Script tab to pause on exceptions, giving you an interactive debugger at the point in code whenever an exception is thrown, or alternately, only on unhandled exceptions.

它看起来像一个带有两个竖线的八角形.这是一个三态按钮,工具提示总结了每种状态的功能.

It looks like a little octagon with two vertical bars. It's a tri-state button, and the tooltips summarize each state's functionality.

这篇关于如何在Safari调试器中调试延迟加载的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆