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

[BUG]: Fetch API cannot load, URL scheme "file" is not supported.

Open justarmadillo opened this issue 9 months ago • 4 comments

Checked for duplicates?

  • [X] This issue is not a duplicate

Does it also happen in the desktop version?

  • [X] This bug does not occur in the latest version of Anki

What are the steps to reproduce this bug?

I use interactive buttons inside my card, And I have button to access to _collection.html from media folder and grab content from there, It was working perfectly, until I updated Ankidroid to 2.18 (as I think, but I don't remember the exact version, about 2 months ago it was working with the latest version), when I tried to remote debug, it shows this:

Fetch API cannot load file:///storage/emulated/0/AnkiDroid/collection.media/_collection.html. URL scheme "file" is not supported.
searchAndShowPopup @ _script.js:93
(anonymous) @ _script.js:62
_script.js:105  Error fetching collection: TypeError: Failed to fetch
    at searchAndShowPopup (_script.js:93:9)
    at HTMLSpanElement.<anonymous> (_script.js:62:11)

Is there any solutions ? I need interactive cards. NOTE: it is working perfectly on Anki desktop 24 (latest version as of today)

Expected behaviour

be able to access _collection.html file without any errors

Actual behaviour

fails to access the file.

Debug info

AnkiDroid Version = 2.18beta2 (dc5348852b15e0f27521acd3c5457595f4676f54)

Backend Version = 0.1.38-anki24.04.1 (24.04.1 ccd9ca1a8309b80bcb50ddc5d99c7ce63440bce9)

Android Version = 13 (SDK 33)

ProductFlavor = full

Manufacturer = Xiaomi

Model = M2101K6G

Hardware = qcom

Webview User Agent = Mozilla/5.0 (Linux; Android 13; M2101K6G Build/TKQ1.221013.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/124.0.6367.123 Mobile Safari/537.36

ACRA UUID = b8213169-64ed-473b-b9ac-bf2dafbccea7

FSRS Enabled = true

Crash Reports Enabled = true

(Optional) Anything else you want to share?

No response

Research

  • [x] I am reporting a bug specific to AnkiDroid (Android app)
  • [X] I have checked the manual and the FAQ and could not find a solution to my issue
  • [X] (Optional) I have confirmed the issue is not resolved in the latest alpha release (instructions)

justarmadillo avatar May 11 '24 08:05 justarmadillo

Hi there. Could you please share a zipped apkg file with a card affected by that?

BrayanDSO avatar May 11 '24 09:05 BrayanDSO

tried using xhr, same error (ankidroid only, anki desktop works perfectly)

[collection.media/#answer:1 Access to XMLHttpRequest at 'file:///storage/emulated/0/AnkiDroid/collection.media/_collection.html' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, https, chrome-untrusted.](url)

justarmadillo avatar May 11 '24 09:05 justarmadillo

Likely solved with #16353

BrayanDSO avatar May 11 '24 09:05 BrayanDSO

Hi there. Could you please share a zipped apkg file with a card affected by that?

sure! @BrayanDSO Fetch error deck.zip

justarmadillo avatar May 11 '24 10:05 justarmadillo

A difference about Anki and AnkiDroid is that Anki handles media requests with a local HTTP server hosted at 127.0.0.1, while AnkiDroid serves files directly by using file:/// scheme. The reason of that is because that is WAY faster than by using a server. So, fetch works there, but not here for this specific case.

2.17 also used a local server for delivering files, but after noting that it was several times slower, we reverted back to the 2.16/2.15.6 behavior in AnkiDroid 2.18 (although we still use a server for other stuff).

After #16353 is merged, the CORS issue will be resolved and you can use the XMLHttpRequest approach

BrayanDSO avatar May 11 '24 12:05 BrayanDSO

A difference about Anki and AnkiDroid is that Anki handles media requests with a local HTTP server hosted at 127.0.0.1, while AnkiDroid serves files directly by using file:/// scheme. The reason of that is because that is WAY faster than by using a server. So, fetch works there, but not here for this specific case.

2.17 also used a local server for delivering files, but after noting that it was several times slower, we reverted back to the 2.16/2.15.6 behavior in AnkiDroid 2.18 (although we still use a server for other stuff).

After #16353 is merged, the CORS issue will be resolved and you can use the XMLHttpRequest approach

Thanks for the clarification. Hope that this approach will remain compatible with both desktop and Ankidroid in the future.

justarmadillo avatar May 11 '24 14:05 justarmadillo