corollari / ankiTab

Browser extension that replaces the new tab page with Anki flashcards
https://ankitab.com
The Unlicense
187 stars 16 forks source link

Answer buttons not showing on media-only card #15

Closed RickCarlino closed 5 years ago

RickCarlino commented 5 years ago

image

I'm running AnkiTab on Firefox 66.0 in Xubuntu. I am using a deck that has media-only (listening comprehension- no written hints)

I've been using it for a few days now and noticed that yesterday the quiz response buttons have disappeared. Please note that in the screenshot above the card I am studying is audio only, so the lack of text is expected.

Thanks for all the great work on this!

RickCarlino commented 5 years ago

Side note: In the JS console it says:

Gui review is not currently active.
RickCarlino commented 5 years ago

I found a few other deprecations (I just noticed that FireFox 66 shipped three days ago :thinking:)

Could not read chrome manifest 'file:///usr/lib/firefox/chrome.manifest'.
Key event not available on some keyboard layouts: key=“r” modifiers=“accel,alt” id=“key_toggleReaderMode” browser.xul
Key event not available on some keyboard layouts: key=“i” modifiers=“accel,alt,shift” id=“key_browserToolbox” browser.xul
No such native application com.lastpass.nplastpass NativeMessaging.jsm:99
Use of Mutation Events is deprecated. Use MutationObserver instead. modern.vendor.00f75c5bdfb0b0f756a8.min.js:1:688914
Use of nsIFile in content process is deprecated.
NetUtil.jsm:259:12
Source map error: TypeError: NetworkError when attempting to fetch resource.
Resource URL: moz-extension://f76b4f15-8de5-4b86-9412-ef2596cd0e7e/libs/bootstrap.css
Source Map URL: bootstrap.css.map[Learn More]
corollari commented 5 years ago

Thanks for reporting it! I'll look into it.

corollari commented 5 years ago

I'm not able to reproduce the issue on my own Firefox (which has been updated to v66). Still I've looked into it and the JS error are you seeing ("Gui review is not currently active.") is thrown by ankiConnect when there's a call to guiCurrentCard() and anki is not in the proper state. One of the reasons that could lead to that happening is if some of the messages that ankiTab sends to ankiConnect are dropped or there's a race condition somewhere. I'm not able to reproduce the issue so it's hard to determine what's causing the issue, if you could give me some more details on when that bug is triggered and maybe send me the card that triggers it I could investigate further.

RickCarlino commented 5 years ago

One of the reasons that could lead to that happening is if some of the messages that ankiTab sends to ankiConnect are dropped

This could be the issue. I am surprised I did not notice this in my initial post:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8765/. (Reason: CORS request did not succeed).[Learn More]

It looks like FireFox is blocking the request because of the same origin policy. I have never directly accessed the AnkiConnect API, nor have I ever authored a Firefox addon, but I would think:

  1. The AnkiConnect plugin needs to allow CORs headers. (judging by this and this, it looks like it does)
  2. The addon is missing/misconfiguring a manifest directive allowing localhost:8765 (perhaps, this one? I am not sure)

The one thing I did notice is that the FireFox manifest for the project lists https://127.0.0.1:8765/ in the permissions array. Since my AnkiConnect server runs on http:// rather than https://, this would be a violation of the same origin policy (the fact that it worked a few days ago is somewhat confusing, still).

Root cause: I still have no idea. The ideas listed above are unvalidated assumpitons. I wonder if Firefox < 66 was not enforcing the same origin policy against protocols (eg: allowing http and https to be used interchangeably).

Possible fix: Would changing the entry in permissions from https://127.0.0.1:8765/ to *://127.0.0.1:8765 or http://127.0.0.1:8765 fix the issue? Please let me know if you would like to try this. I would be happy to send you a pull request if so.

Thanks again for all the great work on this project!

RickCarlino commented 5 years ago

@corollari Nevermind- I found the problem:

I will propose a PR shortly.

corollari commented 5 years ago

Thanks for investigating! I'll also change the permissions to use *://127.0.0.1:8765 instead to avoid any other issues that could arise.

RickCarlino commented 5 years ago

@corollari No problem! I will say though, I did not investigate the CORs issue after discovering the exception in #16 - it is possible that the CORs issue noted is caused by some other issue (I'm quite a noob when it comes to FF addons)

corollari commented 5 years ago

The CORS issue that you found is probably related to the problem explained in #5, the browser tries to send HTTP requests to get resources and ankiConnect just drops them.