fix: load video tags via relative src instead of file:// URI
Purpose / Description
Regression introduced in v2.17 when card HTML switched to loading via http://127.0.0.1 as the WebView base URL. Modern WebView blocks file:// resources from an http:// origin (cross-origin policy), causing video src attributes to silently fail. Worked in v2.16.5 and earlier.
Fixes
- Fixes #20668
Approach
Use a relative filename as the video src instead of a file:// URI. ViewerResourceHandler intercepts the request and serves the file over HTTP, avoiding the cross-origin restriction.
How Has This Been Tested?
Built locally. Tested on a flashcard with an embedded video file to verify that the inline <video> tag loads the player and successfully plays back with functioning playback/scrubbing controls.
Video:
https://github.com/user-attachments/assets/d44bbf5c-3bb9-4a9d-9080-4f318ad3dc3b
Checklist
- [x] You have a descriptive commit message with a short title (first line, max 50 chars).
- [x] You have commented your code, particularly in hard-to-understand areas
- [x] You have performed a self-review of your own code
- [x] UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
- [ ] UI Changes: You have tested your change using the Google Accessibility Scanner
Please test it with some special chars that probably should be encoded: %, , numbers, kanji, emoji, etc
Thanks for pointing it out, I've updated the PR with URI encoding for the src attribute and fixed the path resolution in ViewerResourceHandler. Using the filename test % 123 汉字 😄.mp4, the video loads and plays perfectly!
Asked for a apkg for reproduction in the original issue https://github.com/ankidroid/Anki-Android/issues/20668#issuecomment-4233939041
sent apkg file in the comment https://github.com/ankidroid/Anki-Android/issues/20668#issuecomment-4310548776
@Ayush-Patel-56
Could you clarify testing requirements from: https://github.com/ankidroid/Anki-Android/issues/20668
- What WebView version shows a regression, and is fixed by this PR
- Could you also include this information in the commit description, and the PR description
I'll then get to this ASAP. Please ping every 24 hours for a review if it's not handled.
Updated the commit message and PR description with the regression context (broken since v2.17 due to the http://127.0.0.1 base URL switch).
The code is ready for review. @david-allison
@david-allison can you please review this once when you have a time ? Thanks!
@david-allison requesting a friendly review
Could you check in Discord, I'm low on free time and need to focus on the new Anki Desktop release when I get free time
Apologies for tagging, totally understandable about low time. Excited for some cool changing in desktop btw.
Thanks!