Chrome开发者工具暂停了jQuery 1.7的初始化

Leo*_*ard 12 javascript jquery google-chrome google-chrome-devtools

Chrome的开发者工具是我喜欢使用的一套优秀的工具.不幸的是,当我刷新页面同时保持开发人员工具窗口打开时,我遇到了一个非常奇怪的问题:Chrome暂停javascript执行并指向下面指定的行.

try {
        // This should fail with an exception
        // Gecko does not error, returns false instead
        matches.call(document.documentElement, "[test!='']:sizzle"); // this is where it breaks

} catch (pseudoError) {
    pseudoWorks = true;
}
Run Code Online (Sandbox Code Playgroud)

尽管异常本身位于try-catch块中,但异常会导致脚本暂停.有什么方法可以改变这种行为吗?还是有什么我错过了?

psy*_*brm 37

我刚刚解决了这个问题(在我的情况下,可能会有所不同).我不小心点击了chrome控制台中的"Pause on Exceptions"按钮.这一个:https://developers.google.com/chrome-developer-tools/docs/scripts-breakpoints#js_exceptions

这是一个小的,容易错过的Pause on Exceptions按钮的位置,以及它的三个切换状态:

图像显示小

  • 但是很多时候你想要捕获你的OWN异常. (2认同)

til*_*ldy 4

可能这是一个已知的错误,请检查: http: //bugs.jquery.com/ticket/7535。我在那里找到了这个解决方案,希望它能有所帮助:

 try {
// This should fail with an exception
// Gecko does not error, returns false instead
// <orig. $jquery-1.5:>
// matches.call( document.documentElement, "[test!='']:sizzle" );
// <proposal to Ticket #7535, 2011-03-24:>
  if( ! html.mozMatchesSelector || document.currentScript ){
    matches.call( html, "[test!='']:sizzle" );
  }
//else{
// /*FF lt 4*/
//}


} catch( pseudoError ) {
    pseudoWorks = true;
  }
  // <testing only>
  // alert('MalformedSelectorException thrown: ' + pseudoWorks );
Run Code Online (Sandbox Code Playgroud)