Friday, February 10, 2017

JQuery exceptions using Internet Explorer 11 & ASP .NET

Leave a Comment

When I'm navigating through my ASP .NET site I'm getting the following JQuery exceptions while using Internet Explorer. Also, I'm using Telerik Controls suite for ASP .NET & Visual Studio 2012.

enter image description here

If I check for the line numbers in ScriptResource.axd?d=... (Telerik's file):

/*! jQuery v1.11.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */  a.querySelectorAll("*,:x"), //Line 10673  s.call(a,"[s!='']:x"), //Line 10898 

And in my jquery-2.1.0.min.js:

/*! jQuery v2.1.0 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */  a.querySelectorAll("*,:x") //Line 10357  q.call(a,"[s!='']:x") //Line 10571 

In both files I'm getting an exception in the same two sentences. Those exceptions are not causing extrange behaviour but I don't like to see them in Visual Studio as there might be a signal that something is wrong.

NOTE: If i remove Telerik's JQuery or Standard JQuery the error still there. Even if i set the Telerik's JQuery to use the standar one the error still there. Also, NO errors in console.

What's happening?

3 Answers

Answers 1

Short answer:

There is nothing wrong with jquery - sometimes it do its own 'dirty' business to make your hands clean since sometimes there is no 'clean' way to do what needs to be done

TLDR;

Long answer:

It seems like in both cases you saw caught errors from jQuery, since, according to Telerik documentation, some Telerik controls depends on jQuery - so you would have jQuery out of box

About exceptions - after jQuery loads, its do a feature detection - as you know, browser behavior vary for each browser/version and often there is no way to do detection without trying using features and catching exceptions if the feature is not supported

For example the first exception (at a.querySelectorAll("*,:x")) happens when jquery do a feature detection for selectors supported by document.querySelectorAll - you can simply find it in by searching at github or in any non minified jquery file:

// Opera 10-11 does not throw on post-comma invalid pseudos el.querySelectorAll("*,:x"); rbuggyQSA.push(",.*:"); 

As you can see its intended behavior and there is no way to avoid it as long as you have jquery on your page

Answers 2

The jQuery team uses exceptions in certain situations for logic flow. They uses the assert function to do feature detection for each browser. If you look into the jQuery code, you could find the assert function like the following

function assert( fn ) {     var el = document.createElement("fieldset");      try {         return !!fn( el );     } catch (e) {         return false;     } finally {         // Remove from its parent by default         if ( el.parentNode ) {             el.parentNode.removeChild( el );         }         // release memory in IE         el = null;     } } 

To desmontrate, I've created a sample asp.net webpage that using jQuery 3.1.1. When I run the webpage locally, selecting Internet Explorer and run it within Visual Studio, it will raise the exceptions like this

... 'iexplore.exe' (Script): Loaded 'Script Code (Windows Internet Explorer)'.  Exception was thrown at line 1361, column 4 in http://localhost:63177/Scripts/jquery-3.1.1.js 0x800a139e - JavaScript 実行時エラー: SyntaxError Exception was thrown at line 1379, column 4 in http://localhost:63177/Scripts/jquery-3.1.1.js 0x800a139e - JavaScript 実行時エラー: SyntaxError Exception was thrown at line 37, column 60610 in http://localhost:63409/15db952270ca47e19969bb659e432c6d/browserLink 0x800a139e - JavaScript 実行時エラー: SyntaxError The thread 0x5250 has exited with code 0 (0x0). ... 

Looking at lines 1361 and 1379 in jQuery 3.1.1 code, you will find these error was raised on purpose.

Line 1360-1361

// Opera 10-11 does not throw on post-comma invalid pseudos el.querySelectorAll("*,:x"); 

Line 1377-1379

// This should fail with an exception // Gecko does not error, returns false instead matches.call( el, "[s!='']:x" ); 

Since the exception was handled, the jQuery team don't consider it a problem. You could refer the similar problem as the following link https://bugs.jquery.com/ticket/14123

It's intended codes of jQuery, so I think you could leave it as it is.

Answers 3

If this issue only occurs when debugging a web site/page in the Visual Studio, try disabling the Visual Studio -> Browser Link option either using a corresponding toolbar item or by adding the following key to the Web.config:

<appSettings>     <add key="vs:EnableBrowserLink" value="false"/> </appSettings> 

Refer to the following threads to learn more about different known Browser Link effects (similar to yours), related to the aforementioned JavaScript errors:

VS 2013 Browser Link generated script causes jQuery reference to be broken when using RequireJS

Page uses an invalid or unsupported form of compression when debugging ASP.NET MVC app with Visual Studio 2013 Preview

Browser Link feature in Visual Studio Preview 2013

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment