How to debug lazily-loaded javascripts in Safari debugger

余生长醉 提交于 2019-12-12 23:11:57

问题


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.

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?


回答1:


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.




回答2:


I know that if you lazy load scripts with eval then the firebug debugger has a hack to get at the script.

Normally lazy loaded script can not be accessed from the debugger. You should hard link it and add the lazy loading for production.



来源:https://stackoverflow.com/questions/4840117/how-to-debug-lazily-loaded-javascripts-in-safari-debugger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!