如何找出javascript中加载了哪些javascript?
继另一个问题的评论之后,我问自己是否有办法获取页面上加载的所有 js 代码的列表。就像 Firebug 或 chrome Inspector 所做的那样。
有没有一个纯javascript的方法?
一种方法是抓取脚本标签,但这样你可能会错过动态加载的 js。我希望有一个API。
对于另一个问题,可以 grep 所有调用 console.debug()
的脚本,以防止忘记它们并让它们进入生产环境。
谢谢
Following up on a comment on another I question I asked myself if there's a way to get a list of all js code that is loaded on a page. Something like what firebug or chrome inspector do.
Is there a pure javascript way for that?
One way would be to scrape for script tags, but then you could miss dynamically loaded js. I'd hope for an API.
In the case of the other question, one could grep all the scripts for calls to console.debug()
to prevent forgetting them and letting them slip into production.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想不出不需要做很多工作的事情。这是我最初失败的尝试。当它尝试迭代 window 的所有内部属性时,它会陷入无限递归。
您是否听过这样一句话:“当您拥有的唯一工具是锤子时,所有问题看起来都像钉子”?
为什么要在 JS 中这样做?
I can't think of something that doesn't require a lot of work. Here's my initial failed attempt. It gets into infinite recursion as it tries to iterate through all the inner properties of window.
You ever hear the expression, "when the only tool you have is a hammer, every problem looks like a nail"?
Why would you do this in JS?
使用 jQuery:
});
using jQuery:
});
这就是萤火虫的做法。我想那就没有更好的方法了。
http://fbug.googlecode.com/svn /lite/branches/firebug1.3/content/firebug/script.js
This is how firebug does it. I guess there's no fancier way then.
http://fbug.googlecode.com/svn/lite/branches/firebug1.3/content/firebug/script.js