简体   繁体   English

如何在Chrome中调试RequreJS检索的脚本

[英]How to debug scripts retrieved by RequreJS in Chrome

I am using a third party plugin which calls scripts using RequireJS. 我正在使用第三方插件,该插件使用RequireJS调用脚本。 I want to debug eg setting breakpoints in those scripts but they didn't show up in the script tab of Chrome's developer tools. 我想调试例如在这些脚本中设置断点,但它们未显示在Chrome开发人员工具的脚本标签中。

Is there anyway for me to perform the debugging in chrome? 无论如何,我可以在chrome中执行调试吗?

The only difficulty in debugging modules loaded with RequireJS is that if a module is loaded only if conditions X happens and this condition does not exist when the application is first loaded, you have to wait until the condition occurs before you can put breakpoints on the module's code. 调试使用RequireJS加载的模块的唯一困难是,如果仅在条件X发生时才加载模块,并且在首次加载应用程序时不存在此条件,则必须等到条件出现后才能在模块的条件上放置断点码。

For instance if you want to debug the function bar in module foo and foo is loaded like this: 例如,如果要调试模块foo的功能bar ,并且foo的加载方式如下:

if (X) {
    require(["foo"], function (foo) {
        foo.bar();
    });
}

You'd have to trigger condition X before you can start adding breakpoints inside foo.bar . 您必须先触发条件X然后才能开始在foo.bar添加断点。 Most likely, you'd want to put a breakpoint at the location of the foo.bar() call so that you have the opportunity to add a breakpoint inside foo.bar . 最有可能的是,您希望在foo.bar()调用的位置放置一个断点,以便您有机会在foo.bar内添加一个断点。

This is true in Chrome and Firefox, and probably in other browsers that offer debugging facilities. 这在Chrome和Firefox中以及在提供调试功能的其他浏览器中都是如此。

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

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