How to detect file download in JavaScript?
There are four known approaches to dealing with detecting when a browser download starts: Call fetch(), retrieve the entire response, attach an a tag with a download attribute, and trigger a click event. Modern web browsers will then offer the user the option to save the already retrieved file.