kakaroto / Beyond20

D&D Beyond Character Sheet Integration in Roll20
GNU General Public License v3.0
497 stars 145 forks source link

MV3 service worker gets killed #1032

Closed kakaroto closed 5 months ago

kakaroto commented 1 year ago

I had a bug where the ddb character page got multiple copies of the extension loaded, causing one click to send 12 rolls to the vtt, since there were multiple listeners to that button. Seems to be that the service worker gets killed automatically after 5 minutes, so it would suddenly die and then reload for whatever reason, causing it to re-inject the extension into the page. We need to keep it alive somehow (a timer probably) and see if it's affecting any of the custom domain tab detection https://stackoverflow.com/questions/66618136/persistent-service-worker-in-chrome-extension

kakaroto commented 1 year ago

Dropping MV3 support for 2.8.0 because of the service worker issue causing it to be unreliable/unpredictable and just plain buggy.

kakaroto commented 1 year ago

According to the most recent update here: https://developer.chrome.com/blog/longer-esw-lifetimes/ We should be able to prevent it from getting killed by doing an API call every 20 seconds. Something low impact like a local storage get for example, would be ideal. Timer on 20 seconds because the idle timeout is now 30 seconds 🤦‍♂️

This would likely still be a nightmare because it will only work on newer chrome releases, and we have no idea how firefox would react to that either.

jjchambl commented 1 year ago

@kakaroto could this just be a simple heartbeat function it calls ("hello world-ish")? Could be on a short interval (~5 seconds) in that case.

kakaroto commented 1 year ago

@kakaroto could this just be a simple heartbeat function it calls ("hello world-ish")? Could be on a short interval (~5 seconds) in that case.

Yeah, that's what I meant with a "local storage get" which would reset the timeout automatically. Again, would only work on newer versions of chrome, so anyone who didn't update would still be plagued with issues unfortunately.

jjchambl commented 1 year ago

Ah okay, so it needs to call the Google API on an interval. Is there a max threshold/timeout that we want to limit the session to, or should we make it configurable in settings? Or neither?

kakaroto commented 1 year ago

Neither, since the timeout is 30 seconds, doing the API call every 15 seconds or so should be good enough to prevent the service worker getting killed. That's assuming everyone's using the latest version of Chrome. For now, they've put the brakes on requiring MV3 so until it becomes something urgent again, I'm going to bother with it. It's only having negative consequences and Google only tries to push MV3 in order to kill adblockers. Will wait to see if it ever gets adopted and/or requried.