Allow download of blob for trace and try to get proper filename#6631
Allow download of blob for trace and try to get proper filename#6631
Conversation
I've used Claude to fix this one |
There was a problem hiding this comment.
Pull request overview
This PR addresses WebView blob download failures (notably automation trace downloads) by injecting JavaScript to retain Blob references past URL.revokeObjectURL, and attempts to improve downloaded file naming by capturing the anchor download attribute when available.
Changes:
- Inject a Blob registry/interceptor script on page finish to keep Blob references alive for asynchronous download handling
- Update blob download logic to read from the registry first, falling back to XHR when needed
- Attempt to propagate a better filename from the frontend (anchor
download) into the native download flow
app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewActivity.kt
Outdated
Show resolved
Hide resolved
app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewActivity.kt
Show resolved
Hide resolved
app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewActivity.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
jpelgrom
left a comment
There was a problem hiding this comment.
window.__blobRegistry is global and accessible to any JS code. As it is a plain map it could allow third party JS to enumerate and get blobs even if it's loaded after the blob is created but before downloaded. Maybe theoretical and we tend to trust the server, but it is a new risk.
Can you improve it to be more secure? My first thought would be to scope the registry to the original function and expose a specific window.__getBlob globally which only works if you have the correct blob URL, so enumeration becomes impossible.
This now has a merge conflict.
Summary
Fixes #6291 and also try to get the name of the file from the frontend whenever we can, otherwise the guessFilename is not really great to get the name of files.
Checklist