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

XMLHttpRequest upload (upload.onprogress) event is not supported #573

Closed
MeetinaXD opened this issue May 11, 2024 · 4 comments · Fixed by #613
Closed

XMLHttpRequest upload (upload.onprogress) event is not supported #573

MeetinaXD opened this issue May 11, 2024 · 4 comments · Fixed by #613
Assignees

Comments

@MeetinaXD
Copy link

Hi, I noticed that #292 mentioned that interceptor has added support for the upload event of XMLHttpRequest, but I tried to use XHR to upload files in the latest version of msw, and the progress event was not triggered.

By the way, #292 mentions adding support for the progress event, but this only works in response.

I'm wondering if it's possible to add support for the progress event in upload?


Environment

  • msw: 2.3.0
  • nodejs: 2.3.0
  • pnpm: 9.0.6

To Reproduce

const xhr = new XMLHttpRequest()

// codes...
xhr.upload.onprogress =({ loaded, total }) => {
    console.log(loaded, total) // not triggered
};

xhr.send(someFormData)
@pantoninho
Copy link

I am experiencing the same issue.
I'm using axios within a node environment and onUploadProgress is not being called either.

@kettanaito
Copy link
Member

Hi! Thanks for raising this.

I've opened a fix at #613, and the XMLHttpRequestInterceptor now correctly emits upload events for requests with body (tested on multipart/form-data file uploads).

Important

This will not be supported in JSDOM. JSDOM does not implement the upload events at all, and I always get a single progress event where both loaded and total are always 0. That is a different behavior from the browser, where the loaded and total are calculated correctly. We are going to use browser as the source of truth from now on and disregard any discrepancies JSOM may introduce. If you encounter any, please raise them with the JSDOM maintainers to provide proper implementation.

@kettanaito
Copy link
Member

Released: v0.34.2 🎉

This has been released in v0.34.2!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

@MeetinaXD
Copy link
Author

thank you for explaining the behavior of jsom. it works now. that's amazing and very kind of you, many thanks @kettanaito

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

Successfully merging a pull request may close this issue.

3 participants