New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response.url support for older MS Edge Build #443

Closed
yiransheng opened this Issue Nov 22, 2016 · 8 comments

Comments

Projects
None yet
4 participants
@yiransheng
Copy link

yiransheng commented Nov 22, 2016

I have located the implementation for response.url polyfill:

https://github.com/github/fetch/blob/master/fetch.js#L427

options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL')

However, there's a bug in older build of Edge, where xhr.responseURL is an empty string. The only reference to this bug I can find is this stackover flow question

Basically I use the responseURL variable that XMLHttpRequest's give back. The problem is for some reason my code wasn't working on Microsoft Edge, but it was on Chrome/Firefox. You will also notice that the responseURL property isn't in the Edge docs, https://msdn.microsoft.com/enus/library/ms535874(v=vs.85).aspx

I have observed this buggy behavior a old version of Edge, and the following code failed to work:

fetch(url)
  .then(response => {
    if (isValidAPI(response.url)) {
      // do stuff
    }
  ))

Because fetch polyfill's response.url evaluates to an empty string.

This could be fixed by something like:

options.url = 'responseURL' in xhr ? (xhr.responseURL || request.url) : options.headers.get('X-Request-URL')

EDIT: a bit more thoughts, just use request.url is not enough in case of 30x redirects, a compromise could be special check for Edge and fallback to request.url only if xhr.responseURL is empty, and browser is Edge.

@mislav

This comment has been minimized.

Copy link
Member

mislav commented Nov 22, 2016

Thanks for letting us know. How about this?

xhr.responseURL || options.headers.get('X-Request-URL') || request.url
@yiransheng

This comment has been minimized.

Copy link
Author

yiransheng commented Nov 22, 2016

Thanks for the fast response, looks like a good solution!

@barbarosalp

This comment has been minimized.

Copy link

barbarosalp commented Feb 16, 2017

Hi @mislav / @yiransheng,

How can i get "responseURL" for the request below for Edge browser:
Note: url is redirected to another domain which i try to get the last url in the redirect chain.

     var request = new Request(url, {
           method: 'HEAD',
           mode: 'cors',
           redirect: 'follow'            
       });

       var b = fetch(request)
       .then(function (response) {
           var a = "";
       }).catch(function (ex) {
           var b = "";
       });
@idavollen

This comment has been minimized.

Copy link

idavollen commented Nov 8, 2017

@mislav what if the fetch(url, {redirect: 'follow'}) call got redirected to a new url ? How to retrieve the redirected url in IE 11? and fetch Response.redirected has wrong value false even though the ajax call was redirected in IE 11 and it works well with Chrome, Firefox.

So can you shed the light on how to detected if fetch was redirected or not? if redirected, how to retrieve the redirected url in IE 11? Thanks in advance!

@mislav

This comment has been minimized.

Copy link
Member

mislav commented Nov 8, 2017

@idavollen Unless the server explicitly sets the X-Request-URL response header (which it probably doesn't, unless it's under your control), I don't think it's possible to access the redirected URL from the Response object in IE 11.

@idavollen

This comment has been minimized.

Copy link

idavollen commented Nov 8, 2017

@mislav thanks for your prompt reply. How about the field redirected in fetch Response when redirect occurs, https://developer.mozilla.org/en-US/docs/Web/API/Response/redirected?

@mislav

This comment has been minimized.

Copy link
Member

mislav commented Nov 9, 2017

@idavollen We don't seem to implement this property in the polyfilled Response object. Browsers don't usually give us any insight into whether the XHR response was obtained after following a redirect or not, and the polyfill is implemented using XHR.

@mislav

This comment has been minimized.

Copy link
Member

mislav commented Sep 3, 2018

This was a while ago, and since the fix was supposed to target an older version of Edge, I'm going to assume that such an ancient version of Edge isn't in circulation anymore. Thanks for all your thoughts!

@mislav mislav closed this Sep 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment