12

Chrome's developer tools are an excellent set of tools that I love to use. Unfortunately, I've come across a very strange issue as of late when I refresh the page whilst keeping the developer tools window open: Chrome pauses the javascript execution and points to the line specified below.

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;
}

An exception causes the script to pause, despite that the exception itself is positioned within a try-catch block. Is there any way I can alter this behaviour? Or is there something that I've missed?

Leonard
  • 3,012
  • 2
  • 31
  • 52
  • One common case where this happens: any time in jQuery when you test `.is(':visible')` on an element that isn't visible. In Chrome, the string ':visible' throws the (caught, safe, no problem) DOMException `Error: An invalid or illegal string was specified`. The code still works fine, but if you've got the pause button set to blue ('Pause on all exceptions') it'll set off the debugger. – user56reinstatemonica8 Dec 28 '12 at 11:50

5 Answers5

37

I've just solved this problem (in my case, might be different). I have accidentally clicked on "Pause on Exceptions" button in chrome's console. This one: https://developers.google.com/chrome-developer-tools/docs/scripts-breakpoints#js_exceptions

Here's the location of that small, easy-to-miss Pause on Exceptions button, and its three toggle states:

Image showing small "Pause on Exceptions" button

user56reinstatemonica8
  • 32,576
  • 21
  • 101
  • 125
psycho brm
  • 7,494
  • 1
  • 43
  • 42
  • This fixed it for me and had been driving me insane for a week. I even had uninstalled / reinstalled Chrome to no avail. Thanks. – Mauvis Ledford Dec 06 '12 at 04:56
  • 2
    But a lot of the time you want that on to catch your OWN exceptions. – Plynx Dec 07 '12 at 04:36
  • 1
    Holy lord. I had to download the unminified version of jQuery to figure out what to google, to stumble upon this SO post, to figure out that pause on exceptions was accidentally turned on. Thanks! – rideon88 Dec 20 '12 at 05:20
  • Similar with Safari, here the "Breakpoints" > "All Exceptions" will have a dark blue arrow. Click on this to make it light blue. – QuentinUK Feb 24 '15 at 10:39
4

If someone searches for

div.querySelectorAll("*,:x");

should redirect here.

Hawk
  • 1,513
  • 1
  • 14
  • 17
  • I +1ed just in order to support your search engine visibility efforts, but I strongly encourage you to post a full answer that describes the relations between this question and your specific problem with the code you provided and an appropriate resolution. Otherwise this answer will most likely be deleted soon. – Gottlieb Notschnabel Jul 21 '14 at 23:45
4

Possibly it's a known bug , check this: http://bugs.jquery.com/ticket/7535 . I have found this solution there, I hope it helps:

 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 );
tildy
  • 979
  • 10
  • 20
  • Thanks! It seems though that jQuery is trying to work on interopability with Sizzle, hence resulting in these issues as we've observed. I'll simply bite the bullet and integrate Sizzle whilst I develop, then throw it out before I go into production. – Leonard Dec 07 '11 at 10:27
3

If you're using Chrome, do this:

Click the Settings icon in the inspector (the cog). In General, there is a button called "Manage framework blackboxing..."

You can use this to ignore certain scripts from being evaluated in the debugger. Here's a simple regex to catch jQuery stuff. /jquery(.*)\.js$

Matt Kenefick
  • 1,173
  • 1
  • 13
  • 22
  • 1
    Thanks! Save me soo much because babel's polyfill throws tons of exceptions so it becomes very hard to debug you own babeld app. Tip: In newer chrome, you find this setting under the three dots in the right upper corner of the F12 window and there settings --> Blackboxing. – David Fahlander Mar 10 '16 at 12:09
1

Found this question looking for it related to Safari, so I guess the answer may be useful:

In Safari Web Inspector this can be achieved similarly by going to the Breakpoints tab (ctrl-7). Deselect "All Exceptions" and select "All Uncaught Exceptions".

Pum Walters
  • 339
  • 1
  • 3
  • 11