TraceKit icon indicating copy to clipboard operation
TraceKit copied to clipboard

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

Open niemyjski opened this issue 9 years ago • 17 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 '';
        }
    }

niemyjski avatar May 15 '15 14:05 niemyjski

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.

niemyjski avatar Jun 19 '15 21:06 niemyjski

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.

niemyjski avatar Jun 19 '15 21:06 niemyjski

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

yavorg avatar Dec 27 '15 23:12 yavorg

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

niemyjski avatar Dec 28 '15 13:12 niemyjski

Can you submit a pull request for this.

niemyjski avatar Dec 28 '15 13:12 niemyjski

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

adi518 avatar Jul 31 '16 11:07 adi518

@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.

niemyjski avatar Jul 31 '16 13:07 niemyjski

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 avatar Nov 16 '16 09:11 vivekmarakana

@vivekmarakana would you mind looking into this?

niemyjski avatar Nov 16 '16 20:11 niemyjski

sure

vivekmarakana avatar Nov 17 '16 05:11 vivekmarakana

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

sdwvit avatar Jan 06 '17 11:01 sdwvit

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 :(.

niemyjski avatar Jan 06 '17 14:01 niemyjski

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 avatar Dec 19 '17 18:12 marceloogeda

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

niemyjski avatar Dec 20 '17 21:12 niemyjski

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

marceloogeda avatar Dec 22 '17 12:12 marceloogeda

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.

niemyjski avatar Dec 22 '17 13:12 niemyjski

Can anyone submit a pr for this.

niemyjski avatar Apr 08 '20 14:04 niemyjski