Android WebView Triggers Double Requests for a One-Time Use Download Link

25 Views Asked by At

I'm experiencing an issue with Android WebView concerning a download functionality implemented on the web frontend. The process involves a button that, when clicked, triggers a request to generate a one-time use link for file download. This is followed by creating an invisible element with the download attribute and programmatically clicking it to initiate the download, mimicking the behavior of a regular download link.

However, when attempting to initiate the download from within the Android app through WebView, the downloadListener is activated, but I encounter an error indicating that the link has already been used. This suggests that the WebView has already invoked the request before the downloadListener could process it. Despite observing only a single request in my Logcat, a proxyman analysis reveals that two requests are being made to the download button's endpoint.

I have attempted to use Android's DownloadManager and OkHttp as alternative methods for downloading the files, but neither approach has resolved the issue. Additionally, I've tried intercepting the download endpoint within shouldOverrideUrlLoading and shouldInterceptRequest, yet the endpoint is still called twice.

It's worth noting that the download functionality works as expected in web browsers and in the iOS app, where a different download behavior is implemented using iOS's WKWebView.

Given these challenges, I'm seeking advice on how to ensure that Android WebView makes only a single request to the download link in the downloadListener or through any other potential solution. It's important to mention that using Blob objects is not a viable option due to security concerns.

0

There are 0 best solutions below