Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MiniProfiler and AngularJS

Recently I was trying to profile ASP MVC methods called with AngularJS $http service and I noticed that MiniProfiler does not update the data as it does for AJAX calls from JQuery, for example.

Is there a way to use MiniProfiler with Angular ?

like image 657
iliyan tanev Avatar asked Apr 28 '15 14:04

iliyan tanev


2 Answers

Adjustment needed for Angular (1.3.10)

(not needed if you are using another library for your XHR-needs)

MiniProfiler does this to XMLHttpRequest to be able to intercept all XHR-calls for angular

XMLHttpRequest.prototype.send = function sendReplacement(data) {
   if (this.onreadystatechange) {
    ...

Well, Angular never sets xhr.onreadystatechange so we need to adjust this in a harmless way:

function createXhr() {
   var xhr = new window.XMLHttpRequest();
   xhr.onreadystatechange = function () { };
   return xhr;
}

Explained in detail here

like image 130
Jeyara Avatar answered Nov 18 '22 13:11

Jeyara


This issue was addressed with this pull request and has been fixed in the current MiniProfiler nuger.

like image 1
Yaakov Ellis Avatar answered Nov 18 '22 14:11

Yaakov Ellis