Anki-Android icon indicating copy to clipboard operation
Anki-Android copied to clipboard

fix: load video tags via relative src instead of file:// URI

Open Ayush-Patel-56 opened this issue 7 months ago • 10 comments

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

Ayush-Patel-56 avatar Apr 13 '26 04:04 Ayush-Patel-56

Please test it with some special chars that probably should be encoded: %, , numbers, kanji, emoji, etc

BrayanDSO avatar Apr 16 '26 14:04 BrayanDSO

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!

Ayush-Patel-56 avatar Apr 19 '26 07:04 Ayush-Patel-56

Asked for a apkg for reproduction in the original issue https://github.com/ankidroid/Anki-Android/issues/20668#issuecomment-4233939041

BrayanDSO avatar Apr 23 '26 22:04 BrayanDSO

sent apkg file in the comment https://github.com/ankidroid/Anki-Android/issues/20668#issuecomment-4310548776

Ayush-Patel-56 avatar Apr 24 '26 04:04 Ayush-Patel-56

@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.

david-allison avatar Jun 03 '26 16:06 david-allison

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

Ayush-Patel-56 avatar Jun 08 '26 07:06 Ayush-Patel-56

@david-allison can you please review this once when you have a time ? Thanks!

Ayush-Patel-56 avatar Jun 15 '26 09:06 Ayush-Patel-56

@david-allison requesting a friendly review

Ayush-Patel-56 avatar Jun 18 '26 13:06 Ayush-Patel-56

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

david-allison avatar Jun 18 '26 13:06 david-allison

Apologies for tagging, totally understandable about low time. Excited for some cool changing in desktop btw.

Thanks!

Ayush-Patel-56 avatar Jun 18 '26 13:06 Ayush-Patel-56