kwaschny / unwanted-twitch

Hide unwanted streams, games, categories and channels on: twitch.tv
https://kwaschny.net
MIT License
102 stars 13 forks source link

Extension config does not save, local or cloud. When twitch tabs are already open upon installation of extension #121

Closed erieflin closed 5 months ago

erieflin commented 5 months ago

I'm seeing what appears to be the same issue as this ticket #118

However i can provide more information on my end

with the localstorage checkbox selected or unselected i get the following

background.js:43 Error: Could not establish connection. Receiving end does not exist.

occuring at line 40 in background.js forwardMessageToTabs method

Additionally i get some of the following

Uncaught (in promise) Error: No tab with id: 393832882.

Further testing leads me to the following root cause. The problem occurs when you have multiple twitch.tv links open in your browser, and you have installed the extension after at least one of them was opened. And is reproduceable this way

  1. open twitch tab
  2. install extension
  3. open second twitch tab (do not touch original tab)
  4. open config in second twitch tab
  5. try to make a change and click the save button

this prevents saving config on all tabs, as well as directly through the extension, causing one twitch tab forgotten on another open window to brick the extension until the browser is refreshed or the tab is otherwise closed

erieflin commented 5 months ago

Using extension version 23.10.17 Appears using Version 1.63.174 Chromium

kwaschny commented 5 months ago

Thank you for this detailed report. Your observation is correct. The service worker expects the first available tab (as queried via chrome.tabs.query) to process the save operation (to prevent saving multiple times). When the first tab doesn't receive the message due to not being "connected" however, the save operation is lost entirely.

While I think that this issue should be fixed in the WebExtensions API (either don't return disconnected tabs or at least indicate if they are even connected), the easiest solution is only counting resolved chrome.tabs.sendMessage. And that's the fix here.

I will immediately publish the fix. Hopefully this has been the cause of the many reports about "not saving". Thanks again!