ig3 / zhongwen

A fork of the "Zhongwen" extension modified to support content in iframes.
https://chrome.google.com/webstore/detail/zhongwen-chinese-english/kkmlkkjojmombglmlpbpapmhcaljjkde
GNU General Public License v2.0
0 stars 0 forks source link

Intermittent load/initialization failures #6

Closed ig3 closed 1 year ago

ig3 commented 1 year ago

Sometimes the add-on doesn't run normally in an reloaded iframe. Calibre-web presents epub books in an iframe, reloading the iframe when the chapter changes. Most of the time the new chapter is loaded and zhongwen runs normally, but sometimes it fails to load. Refreshing the page or turning the add-on off then back on recovers. This probably relates to the messaging between frames and the background add-on code, but I haven't isolated the failure yet.

Difficult to say how often it happens. I often go days without seeing a failure, which makes it difficult to investigate.

ig3 commented 1 year ago

The problem is that the content script doesn't get the configuration from the background script. This is sent by the background script after receiving an onUpdated event with status === 'complete'. The background script then sends a message with the configuration. But, somehow, the content script doesn't reliably receive this. Maybe because it sets up its listener for the message too late??? It isn't obvious.

The content script already sent a message to the background script as the last thing it did in its foreground. The response was just an enabled flag. So I changed the response to be an object containing the enabled flag and the configuration. This way, the response can't come before the content script is ready.

Since making the change I haven't seen a failure, but it is a rare, intermittent problem. Nothing to do now but wait to see if the errors persist.

ig3 commented 1 year ago

This seems to be fixed. It hasn't occurred for a long time now.