简体   繁体   English

如何在 Chrome DevTools 中调试 ajax 请求中加载的 js

[英]How to debug js loaded in ajax request in Chrome DevTools

Actually I am a big fan of Google Chrome DevTools but it is very vast area for learning.实际上,我是 Google Chrome DevTools 的忠实粉丝,但它是一个非常广阔的学习领域。 I don't know much about it.我对此了解不多。 I know how to out debug point, searching (Ctrl+Alt+F) and debugging, etc. basic things.我知道如何调试点,搜索(Ctrl+Alt+F)和调试等基本的东西。

But in one of my project (its in asp.net MVC), it is requesting different views in Ajax request and in that views there are some js loading.但是在我的一个项目中(它在 asp.net MVC 中),它在 Ajax 请求中请求不同的视图,并且在该视图中加载了一些 js。 I want to debug them but I am not able to.我想调试它们,但我做不到。 Actually I don't know where can I see them - especially the JS which is load after ajax call (its not inline javascript but a separate js files).实际上我不知道在哪里可以看到它们——尤其是在 ajax 调用之后加载的 JS(它不是内联 javascript,而是一个单独的 js 文件)。

A workaround I found is - if I put 1 " debugger; " in that js file then it opens with some VM3012 or similar name with different numbers.我发现的一个解决方法是 - 如果我在那个 js 文件中放了 1 个“ debugger; ”,那么它会以一些 VM3012 或具有不同数字的类似名称打开。 Then only I can see the files.然后只有我可以看到文件。 But I can not put debugger when I publish the code.但是我发布代码时无法放置调试器。

Any body knows then please help.任何人都知道然后请帮助。

Thanks a lot for reading.非常感谢您的阅读。

EDIT编辑

as per first answer, I have tried but I can see that option "Open in Source panel" for normal JS file.根据第一个答案,我已经尝试过,但我可以看到普通 JS 文件的“在源面板中打开”选项。 But in my case my request is passing some query string to the js file like assets/components/utility/mycustom.js?_=1528282662460 and I am not able to see that option for such request.但在我的情况下,我的请求是将一些查询字符串传递给像assets/components/utility/mycustom.js?_=1528282662460这样的 js 文件,我无法看到此类请求的选项。 This help is appreciated but need more.对此帮助表示赞赏,但需要更多。

I know it's been 3 years but...我知道已经3年了,但是...

You can name the piece of javascript code inside the dynamic loaded file by adding the following above the code:您可以通过在代码上方添加以下内容来命名动态加载文件中的一段 javascript 代码:

//# sourceURL=my-file-name.js

By doing it, that piece of javascript will be available in the file tree of the source panel and can also be found by the DevTools' CTRL+P shortcut.通过这样做,这段 javascript 将在源面板的文件树中可用,也可以通过 DevTools 的 CTRL+P 快捷方式找到。

Go to the network tab of the dev tools.转到开发工具的网络选项卡。 You can filter by js files to help you find the file you need.可以通过js文件过滤,帮你找到需要的文件。 Right click on the file you want and select Open in sources panel.右键单击所需的文件,然后选择在源面板中打开。 You should now be able to put the breakpoint where you like as you are used to.您现在应该能够按照习惯将断点放在您喜欢的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM