csnover / TraceKit

Attempts to create stack traces for unhandled JavaScript exceptions in all major browsers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.

niemyjski opened this issue · comments

I get the following error in chrome when loadSource is called:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
function loadSource(url) {
        if (typeof url !== 'string') {
          return [];
        }

        if (!TraceKit.remoteFetching) { //Only attempt request if remoteFetching is on.
            return '';
        }
        try {
            var getXHR = function() {
                try {
                    return new window.XMLHttpRequest();
                } catch (e) {
                    // explicitly bubble up the exception if not found
                    return new window.ActiveXObject('Microsoft.XMLHTTP');
                }
            };

            var request = getXHR();
            request.open('GET', url, false);
            request.send('');
            return request.responseText;
        } catch (e) {
            return '';
        }
    }

I think this code may also have issues on IE 8/9... I'd like to abstract this code so we could inject node specific / web specific logic to get the source.

I've battle tested some code here: https://github.com/exceptionless/Exceptionless.JavaScript/blob/master/src/submission/DefaultSubmissionClient.ts#L56-L161 We should take a look and slim this down to fit this use case.

Do you recommend we leave remoteFetching off in production until this is addressed?

Yeah, I think we should make this the default, as it could cause extra requests to be made

Can you submit a pull request for this.

commented

Why do you fetch with a sync request anyway? :)

@adi518 I didn't write this logic but I assume it's because it has to work in ie6, we try and have it work as expected on all browsers.

Also, we need URL validation before making call. Sometimes error stack is not valid and that leads the call to eval at globalEval (http://cms.pharmeasy.in/assets/a929fb88/jquery.js:2:3123), <anonymous> for context

@vivekmarakana would you mind looking into this?

Hey, any updates on this? Maybe drop support of ie6 (and maybe 7,8,9)?

I never heard back, would you mind looking into it? I don't see us dropping support for IE anytime soon. (https://www.netmarketshare.com/browser-market-share.aspx?qprid=2&qpcustomd=0) there are probably ~billion?? at least in the millions users still running those crappy versions of IE and we need to detect errors still for them :(.

I recently received this as a warning level in Chrome version 63.0.3239.x

captura de tela 2017-12-19 as 11 28 27

@marceloogeda Would you mind submitting a pull request for a newer implementation that falls back based on support?

@niemyjski sure, I'll make the required changes and submit it.

Might be able to take the code from here: https://github.com/exceptionless/Exceptionless.JavaScript/blob/master/src/submission/DefaultSubmissionAdapter.ts but we need to be sure we try catch any errors.

Can anyone submit a pr for this.