GithubHelp home page GithubHelp logo

Comments (8)

jpillora avatar jpillora commented on September 6, 2024

Good question, read from jpillora/xdomain#21 (comment) onwards. In short, it's for jQuery, however, due to all these conflicts maybe a smarter way to do is to add a custom ajax transport.

from xhook.

jpillora avatar jpillora commented on September 6, 2024

Actually, a much easier fix if(jQuery) jQuery.support.cors = true;, trying to remember if we patch withCredentials for any other reason...

from xhook.

jpillora avatar jpillora commented on September 6, 2024

Oh yes, script load sequence. If jQuery is loaded after XHook, then XHook won't have a reference to it yet. If jQuery is loaded before then possibly other libraries are also loaded before, and some libraries grab hold of window.XMLHttpRequest thereby preventing XHook from patching it. And adding an ajax transport would have the same load sequence problem. Still, there might be a nicer solution to this...

from xhook.

brian-mann avatar brian-mann commented on September 6, 2024

Okay I'm testing with what was suggested: turn off xhook withCredentials, and forcing jQuery support cors to be true.

All of our authenticated CORS goes over XDomain (which works wonderfully well) via jQuery, and the only times it uses the native XHR is 3rd party services without authentication.

from xhook.

jpillora avatar jpillora commented on September 6, 2024

So yep, that's why I've just left this with the

//fix trackers
xhook.addWithCredentials = false;
//fix jquery cors
jQuery.support.cors = true;

work around though this does need to be added to the docs...

from xhook.

brian-mann avatar brian-mann commented on September 6, 2024

Yup everything works with the suggested fix.

from xhook.

brian-mann avatar brian-mann commented on September 6, 2024

Okay... actually forcing addWithCredentials to false will then also remove it from modern browsers. I noticed suddenly all my errors stopped reporting in non IE browsers, and to my surprise, I saw that withCredentials was returning false in all new XHR instances including Firefox + Chrome.

I think the real fix here is intelligently figure out whether we should add the withCredentials by doing a check to see if the browser supports it. As it stands right now, you have to set addWithCredentials to a boolean - but I propose this fix:

xhook.addWithCredentials = ("withCredentials" in new XMLHttpRequest());

This will dynamically set that value so modern browsers have it included, and older browsers which don't natively support that property won't.

This should wrap up everything without having to educate users of the addWithCredentials method - it should just work as expected out of the box. Though, it's still worth noting the jQuery cors support patch.

from xhook.

jpillora avatar jpillora commented on September 6, 2024

I agree, it should always be added in modern browsers. The problem with doing:

xhook.addWithCredentials = ("withCredentials" in new XMLHttpRequest());

is this will cause jQuery ajax to stop working under older browsers. So maybe, setting:

xhook.addWithCredentials = false

will prevent it from being added so one might assume that if it's already there, this will have no effect, so the real fix might be:

  # initialise 'withCredentials' on facade xhr in browsers with it
  # or if explicitly told to do so
  if 'withCredentials' of xhr or xhook.addWithCredentials
    facade.withCredentials = false

Putting this in now

from xhook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.