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

axios hook not working #674

Open
toddsmith-adsk opened this issue Oct 18, 2024 · 1 comment
Open

axios hook not working #674

toddsmith-adsk opened this issue Oct 18, 2024 · 1 comment

Comments

@toddsmith-adsk
Copy link

In 2021 axios added the following change to onreadystatechange axios/axios#3688 which replaces onloadend instead of onreadystatechange on the axios instance:

if ('onloadend' in request) {
      // Use onloadend if available
      request.onloadend = onloadend;
    } else {
      // Listen for ready state to emulate onloadend
      request.onreadystatechange = function handleLoad() {
      ...
   }

this causes the MiniProfiler hooks for axios to stop working because onreadystatechange is no longer available as a hook

if (this.onreadystatechange) {

this.onreadystatechange will always be null for axios:

  if ((window.angular || window.axios || window.xhr) && typeof (XMLHttpRequest) !== 'undefined') {
              const oldSend = XMLHttpRequest.prototype.send;

              XMLHttpRequest.prototype.send = function sendReplacement(data) {
                    if (this.onreadystatechange) {
                        if (typeof (this.miniprofiler) === 'undefined' || typeof (this.miniprofiler.prev_onreadystatechange) === 'undefined') {
                            this.miniprofiler = { prev_onreadystatechange: this.onreadystatechange };

                            this.onreadystatechange = function onReadyStateChangeReplacement() {
                                if (this.readyState === 4) {
                                    handleXHR(this);
                                }

                                if (this.miniprofiler.prev_onreadystatechange != null) {
                                    return this.miniprofiler.prev_onreadystatechange.apply(this, arguments);
                                }
                            };
                        }
                    } else if (this.onload) {
                        if (typeof (this.miniprofiler) === 'undefined' || typeof (this.miniprofiler.prev_onload) === 'undefined') {
                            this.miniprofiler = { prev_onload: this.onload };

                            this.onload = function onLoadReplacement() {
                                handleXHR(this);

                                if (this.miniprofiler.prev_onload != null) {
                                    return this.miniprofiler.prev_onload.apply(this, arguments);
                                }
                            };
                        }
                    }
@NickCraver
Copy link
Member

I am not familiar with Axios at all (loooooong ago support), but if someone has a contribution here for checking for the new hook also, I think it's totally reasonable to add that and would be happy to review PR there.

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

2 participants