6

In Microsoft Edge, a GET request is not running. I have stepped through the code to the point of the AJAX request being run, and set a breakpoint in the callback(s). However, the code never reaches the callbacks.

I already have a .then() and .fail() setup with callbacks, and tried adding a .done() and .always() with callbacks, but none of the code in the callbacks is running.

I then checked the network tab in dev-tools, and I cannot find the request at all. It seems as though Edge is not firing the request off for some reason.

request = function(options, resolveScope) {
    var deferred = $.Deferred();
    corsHandler.makeRequest(options)
        .done(this._wrap(function(response) {
            deferred.resolveWith(resolveScope, [response]); //never gets here
        }, this))
        .fail(this._wrap(function(response) {
            deferred.rejectWith(resolveScope, [response]); //never gets here
        }, this));
    return deferred;
}

This is what calls the request function above.

ajaxFunc = function(data, scope) {
    return request({
        url: '/path/to/server',
        internalUrl: true,
        method: 'GET',
        datatype: 'json',
        data: data
    }, scope);
}

This is the implementation used to make that request.

(function() {
    // set data var
    return ajaxFunc(data, self)
        .then(function(res) { console.log(res); }) //never gets here
        .done(function(res) { console.log(res); }) //never gets here
        .fail(function(res) { console.log(res); }) //never gets here
        .finally(function(res) { console.log(res); }) //never gets here
 })();

Here is the cors stuff. (I don't know a whole lot about this.)

 corsHandler.makeRequest = function(options) {
        // resolve default options
        _.defaults(options, {
            xhr:        null,
            corsUrl:    null,
            url:        null,
            method:     'GET',
            data:       {},
            success:    function() {},
            error:      function() {},
            terminate:  false,
            binary:     false,
            headers:    {},
            internalUrl: false,
            datatype: ''
        });
        // if url is internal, create absolute url from relative url
        if (options.internalUrl) {
            options.url = this.createAbsoluteInternalUrl(options.url);
        }

        // resolve cors url or proxy url
        options.corsUrl = options.corsUrl || this.getCorsUrl(options.url);
        if (!options.corsUrl) {
            options.url     = this.getProxyUrl(options.url);
            options.corsUrl = this.getCorsUrl(options.url);
        }

        // create xhr
        if (!options.xhr && options.corsUrl) {
            options.xhr = this.createXhr(options.corsUrl);
        }

        // create cleanup procedure
        var cleanUpAfterRequest = $.proxy(function() {
            if (options.terminate) {
                options.xhr.destroy();
                this._removeCacheXhr(options.corsUrl);
            }
        }, this);

        // prepare deffered object
        var deferred = $.Deferred();
        deferred
            .done(function() {
                if (options.success) {
                   options.success.apply(null, Array.prototype.slice.call(arguments));
                }
            })
            .fail(function() {
                if (options.error) {
                    options.error.apply(null, Array.prototype.slice.call(arguments));
                }
            });

        // make actual request
        if (!options.xhr) {
            throw 'corsHandler: xhr object was not created or defined to make request'; 
            // this does not happen
        }
        options.xhr.request(
            {
                url:    options.url,
                method: options.method,
                data:   options.data,
                binary: options.binary,
                headers: options.headers,
                datatype: options.datatype
            },
            function() {
                deferred.resolve.apply(null, Array.prototype.slice.call(arguments));
                cleanUpAfterRequest();
            },
            function() {
                deferred.reject.apply(null, Array.prototype.slice.call(arguments));
                cleanUpAfterRequest();
            }
        );
        return deferred;
    }

UPDATE

It looks like the issue is in easyXDM. waitForReady() is not firing on(window, "message", waitForReady) in edge. I'm looking into the issue more now.

easyXDM snippet:

    targetOrigin = getLocation(config.remote);
    if (config.isHost) {
        // add the event handler for listening
        var waitForReady = function(event){
            if (event.data == config.channel + "-ready") {
                // replace the eventlistener
                callerWindow = ("postMessage" in frame.contentWindow) ? frame.contentWindow : frame.contentWindow.document;
                un(window, "message", waitForReady);
                on(window, "message", _window_onMessage);
                setTimeout(function(){
                    pub.up.callback(true);
                }, 0);
            }
        };
        on(window, "message", waitForReady);

        // set up the iframe
        apply(config.props, {
            src: appendQueryParameters(config.remote, {
                xdm_e: getLocation(location.href),
                xdm_c: config.channel,
                xdm_p: 1 // 1 = PostMessage
            }),
            name: IFRAME_PREFIX + config.channel + "_provider"
        });
        frame = createFrame(config);
    }

The above snippet runs, but the waitForReady method is never called. The only browser it's not called in is Edge (Works in IE8+, Chrome, Safari, FF, and mobile chrome/safari).

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Jacques ジャック
  • 3,682
  • 2
  • 20
  • 43
  • Isn't the attribute is dataType not datatype? Don't think that would be the issue, but worth correcting. I've experienced requests failing to fire in the past when making that mistake – Antonio Manente Dec 23 '15 at 19:32
  • 2
    wouldn't hurt to put `console.log` just about everywhere there is `.done` `.fail` `.then` to see what is run. – SoluableNonagon Dec 23 '15 at 19:36
  • @AntonioManente Thanks for the input, I'll look into that. – Jacques ジャック Dec 23 '15 at 19:40
  • @SoluableNonagon The I added breakpoints at every one, I'll try console.logs as well and let you know. – Jacques ジャック Dec 23 '15 at 19:41
  • @SoluableNonagon I added console.logs everywhere. None showed up in the console. – Jacques ジャック Dec 23 '15 at 19:45
  • I think the biggest thing to point out is that the XHR request is not happening (there is no evidence of it actually happening in the network tab). Since it's not happening, I would assume none of the callbacks would run. – Jacques ジャック Dec 23 '15 at 19:50
  • In the block labeled 'This is the implementation used to make that request.' i see the parentheses at the end appear to be out of order. Is it the same in the code as well? or just a typo here – Antonio Manente Dec 23 '15 at 20:04
  • 1
    Ah, sorry, typo here. I've updated it. – Jacques ジャック Dec 23 '15 at 20:13
  • 1
    Also, someone voted the question down, if you're going to vote down, at least comment on why you voted it down. If it's a "stupid" question, then the answer would be nice as well... – Jacques ジャック Dec 23 '15 at 20:14
  • Simplify the code.Follow it, start to finish, until it stops. Note where it stops. Is it even reaching xhr.send? – Kevin B Dec 23 '15 at 20:36
  • @KevinB Can you elaborate? The cors code is called in several places, and the request method is as well. I think any simplification would lead to repetitive code. – Jacques ジャック Dec 23 '15 at 20:39
  • Look at it this way. If you aren't even getting to the xhr.send, then the fact that this is an ajax request is irrelevant, no? if it IS reaching xhr.send, it would be visible in the network tab. – Kevin B Dec 23 '15 at 20:39
  • @KevinB I suppose it is, however, there is no issue getting there in any other browsers. Anything beyond what I've posted starts getting into deps we're loading, and I assumed they would not be the issue. – Jacques ジャック Dec 23 '15 at 20:44
  • Basically, you need to either step through the code with a debugger (if that exists in Edge,) or add more console logging to see how far it gets and why it stops. currently i'm having a hard time following your code to see where it could possibly be stopping. – Kevin B Dec 23 '15 at 20:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/98857/discussion-between-jacques-and-kevin-b). – Jacques ジャック Dec 23 '15 at 20:56
  • Looks like the issue is postMessage not working in Edge, I'll update the question with details later. – Jacques ジャック Jan 01 '16 at 14:51
  • https://dev.windows.com/en-us/microsoft-edge/platform/status/postmessage - postMessage works in Edge (http://caniuse.com/#search=postMessage). https://davidwalsh.name/demo/window-post-message.php - this is a demo for postMessage and it does something in Edge's console :) – MartyIX Jan 03 '16 at 20:51
  • @MartinVseticka I created a postMessage listener and fired it in edge and the callback never ran (It was just a `console.log()`). It fired perfectly fine in Chrome. I'm checking out the links you posted, but that is why I commented that I thought it was an issue with postMessage not working in edge. – Jacques ジャック Jan 04 '16 at 00:47
  • @MartinVseticka You are correct, there was an issue in my event in Edge. It was not erroring how chrome was with the same issue, so I assumed it wasn't working properly. Now I'm back to square one. – Jacques ジャック Jan 04 '16 at 15:45

1 Answers1

0

It turns out there was a required "hack" that a previous developer wrote into our implementation of easyXDM.

In our implementation of easyXDM, we had to update the Window object on IE because our app launches in an iFrame. As Edge isn't technically a version of IE, our test was failing, so the code was not running to update window to be window.parent in the context of easyXDM.

We are using typeof document.documentMode === 'number' to detect IE, but document.documentMode is undefined in Edge, so we added a navigator.userAgent check for Edge.

This resolved the issue.

Jacques ジャック
  • 3,682
  • 2
  • 20
  • 43
  • What is this window / window.parent fix? I am detecting Edge in my app for various reasons but what is this code that runs that updates window to be window.parent in the context of easyXDM? Ref? There is no window.parent code in any of your example code snippets. Thanks – OG Sean Dec 11 '19 at 03:56
  • This question is quite old, and I don’t remember the specifics, but our code was in an iFrame, so it’s probably a reference to the iframes parent window. – Jacques ジャック Dec 11 '19 at 08:35