سؤال

By default Glimpse injects its scripts just before the closing </body> tag. The result of this is that the AJAX calls done on page load are not captured. I am using $(document).ready() to invoke the AJAX.

Is there a configuration option or placeholder string to put in my Layout.cshtml that would instruct Glimpse to load before my init scripts?

Edit - the request on page load does show up when I open the full Glimpse view under Ajax tab. But it does not increase the Ajax counter on the small overlay display. Any requests that are further initiated slightly in the success handler of the first request do increase the counter. So maybe the problem is somewhere else?

هل كانت مفيدة؟

المحلول

There is no option that you can configure to determine where Glimpse will render its script tags, the script tags will, like you mentioned, be rendered right before the </body> tag, this to minimize the impact of the Glimpse client while loading the rest of the page. This injection is also done, independently of you using ASP.NET MVC or ASP.NET WebForms for instance.

On the other hand, the issue you are mentioning is already known on the Glimpse issue tracker and is being worked on, so don't hesitate to give additional feedback over there.

نصائح أخرى

The accepted answer still holds true but since it slightly reduced the usability of the tool for me, I created the following workaround that delays all calls to $(document).ready() until Glimpse HUD is loaded. If Glimpse is turned off, there is no delay.

// workaround for the problem when Glimpse does not correctly show AJAX requests that happen before the HUD is initialized
(function () {
    var origDocumentReady = $.fn.ready;
    var checkFinished = false;
    $.fn.ready = function (delegate) {
        var timerId = -1;
        var counter = 0;
        var check = function () {
            if (counter++ > 50) //~2.5sec - if still not loaded, give up
                checkFinished = true;

            if (checkFinished || document.getElementById("glimpse-hud-section-input-ajax")) {
                checkFinished = true;
                window.clearInterval(timerId);
                delegate();
            }
        }

        origDocumentReady(function () {
            if (!checkFinished && typeof glimpse === typeof undefined)
                checkFinished = true;

            if (checkFinished)
                delegate();
            else
                timerId = window.setInterval(check, 50);
        });
    }
})();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top