javascript - Mozilla CORS issue work around -
i have following code in script on page:
function getjson(url, passedfunction) { console.log("getjson start: "+url); var xhr = new xmlhttprequest(); globalforxhr = xhr; xhr.open("get", url, true); xhr.overridemimetype("application/json"); //stop mozilla bug xhr.withcredentials = true; xhr.onreadystatechange = function() { console.log("getjson ready state change: "+xhr.readystate+" , xhr: "+xhr.status); if (xhr.readystate == 4 && xhr.status == 200) { try { passedfunction(json.parse(xhr.responsetext)); } catch (e) { alert("got exception ("+e+") whille trying handle: "+url); } } } xhr.send(); }
i have 2 situations: page served remote server s1, , code calling remote server s2. standard cors headers in place , works fine in both mozilla , chrome.
but, running tomcat on local machine l1, , again calling same remote server s2. when served l1 (via http) works in chrome in mozilla fails.
first call local server (which served page), , second call global external s2. console output in chrome is:
getjson start: http://myserver.local:8080/weaver/auth/ getjson ready state change: 2 , xhr: 200 getjson ready state change: 3 , xhr: 200 getjson ready state change: 4 , xhr: 200 getjson start: https://external.server.com/eid/?openid.mode=apiwho getjson ready state change: 2 , xhr: 200 getjson ready state change: 3 , xhr: 200 getjson ready state change: 4 , xhr: 200
however, in mozilla, getting failure when page served local tomcat server, when requesting remote server, , in mozilla:
"getjson start: http://myserver.local:8080/weaver/auth/" getjson ready state change: 2 , xhr: 200 getjson ready state change: 3 , xhr: 200 getjson ready state change: 4 , xhr: 200 "getjson start: https://external.server.com/eid/?openid.mode=apiwho" getjson ready state change: 2 , xhr: 0 getjson ready state change: 4 , xhr: 0
xhr.status returning 0 when call remote (s2) server called. there lot of discussion on web how status can return 0 in sorts of situations poorly documented @ best. many of them decisions mozilla abort call because cross site scripting paranoia -- , not tell when doing this.
i suspect serving page local server might detected mozilla, aborts request, , fails without telling why.
does know of way confirm reason mozilla failing make request?
i saw documentation of way set mozilla go ahead , make request, other notes removed in 2015. test site in mozilla served local server. know of way turn off behavior?
update
there no mention in network tab call. call .../weaver/auth there witha 200 response, call external server not appearing in list. there no error message can find anywhere. not make request. frustrating.
to assure myself not cache issue, have changed url being requested (by adding dummy query parameter) , behavior remains same: works on chrome, status=0 on mozilla.
the external server https , has valid certificate. identity server , using authenticate user -- , way call through https. mixed http , https not problem when page served other (s1) server http.
i must make call credentials because single signon protocol. if logged identity server, want them authenticated. comes cookies. making call without credentials defeat whole purpose of sso. if remove 'withcredentials' page fetched without issue (but of course authentication of user defeated).
the headers server includes access-control-max-age value of "1".
update 2
problem caused "privacy badger" attempt block calls made tracking purposes. blocks calls, makes no entry in console. prevents attempt @ fetching page appearing in network panel.
i not sure why privacy badger behaved differently sites hosted in different places. might point in past 'approved' access site site, , remembered that. other sites not have registered, , blocked.
lesson learned: disable plugins when start having browser problems
Comments
Post a Comment