Skip to content
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

XHR's onreadystatechange execution order #2471

Closed
woshiwanglizhi opened this issue Feb 22, 2021 · 0 comments
Closed

XHR's onreadystatechange execution order #2471

woshiwanglizhi opened this issue Feb 22, 2021 · 0 comments

Comments

@woshiwanglizhi
Copy link

function loadAsset(path, callback, errorCallback) {
var response;
var xhr = new XMLHttpRequest();
xhr.open('GET', path, true);
// set responseType after calling open or IE will break.
try {
// This crashes on Android WebView prior to KitKat
xhr.responseType = 'json';
} catch (err) {} // eslint-disable-line no-empty
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
response = formatResponse(xhr);
callback(response);
} else {
try {
response = formatResponse(xhr);
callback(response);
} catch (err) {
if (errorCallback) {
errorCallback(err);
}
}
}
}
};
}
return {
load: loadAsset,
};
}());

We need to change the order of execution here,Place the onreadystatechange event before the open and send assignments.
Since onreadystatechange is intercepted in open in some third-party plug-ins (such as Sentry), subsequent assignments to onreadystatechange break this mechanism, causing an exception.

https://github.com/getsentry/sentry-javascript/blob/d7798ebb4877f41faa6d1a67ce682b5b4043dde2/packages/tracing/src/browser/request.ts#L214-L270

dreamoftrees pushed a commit to immutable/lottie-web-threejs that referenced this issue Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant