code-charity / youtube

[top~1 open YouTube & Video web-extension] Enrich your experience & choice! 🧰100+clever features📌set&forget📌Longest-standing(yet rare&tough alone. Please help/join🧩us👨‍👩‍👧‍👧) ..⋮ {playback|content discovery|player|extra buttons|distractions|related videos|shorts|ads|quality|codec|full tab|full screen}
http://improvedtube.com
Other
3.29k stars 498 forks source link

Update background.js keep focus/blur messaging to minimum #2375

Closed raszpl closed 2 weeks ago

raszpl commented 2 weeks ago

Keep track of connected tabs. Send only to connected tabs, send only to at most TWO tabs, one losing focus and one gaining it.

I tried experimenting with local

window.addEventListener("blur", (event) => {
});
window.addEventListener("focus", (event) => {
});

as mentioned in https://github.com/code-charity/youtube/pull/2375 but its much worse, clicking in browser address bar takes focus away and pauses videos :/. chrome.windows.onFocusChanged is only slightly better due to 10 year old Chrome bug https://issues.chromium.org/issues/41116352 :o Chrome doesnt tell us when user alt-tabs away. Firefox does send proper message and reacts to alt-tabbing just fine.

finally fixes https://github.com/code-charity/youtube/issues/2284 . Tested in Chrome, Vivaldi and FF.

arunchandranuniverse commented 2 weeks ago

ok

On Wed, Jun 12, 2024 at 11:05 AM Rasz_pl @.***> wrote:


You can view, comment on, or merge this pull request online at:

https://github.com/code-charity/youtube/pull/2375 Commit Summary

File Changes

(1 file https://github.com/code-charity/youtube/pull/2375/files)

Patch Links:

— Reply to this email directly, view it on GitHub https://github.com/code-charity/youtube/pull/2375, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ4GQKMR2VFDDITZYN3OPTTZG7MYJAVCNFSM6AAAAABJFTULVKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM2DOOBUG42DSOI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ImprovedTube commented 2 weeks ago

(merging untested)

ImprovedTube commented 1 week ago

thank you so much for caring in depth! @raszpl (as always)

(Did you check/compare the impact on each connected feature yet?)

chrome.windows.onFocusChanged is only slightly better due to 10 year old Chrome bug https://issues.chromium.org/issues/41116352 :o Chrome doesnt tell us when user alt-tabs away.

Can we make up for that somehow (...?)

have read alt+tab in our bug reports before


window.addEventListener("blur" ... https://github.com/code-charity/youtube/pull/2375 ... clicking in browser address bar takes focus away and pauses videos

(good to know too. might soon have more auto pause options https://github.com/code-charity/youtube/issues/2111)

raszpl commented 1 week ago

(merging untested)

at least test if its not crashing :-)

(Did you check/compare the impact on each connected feature yet?)

I didnt change the mechanism in the end. Its doing exactly same thing old code was doing, just much less of it. Instead of spamming all unassociated (and hibernated) tabs with messages it now only sends it to YT tabs that send 'tab-connected' first and are still active.

chrome.windows.onFocusChanged is only slightly better due to 10 year old Chrome bug https://issues.chromium.org/issues/41116352 :o Chrome doesnt tell us when user alt-tabs away.

Can we make up for that somehow (...?)

Tried, failed, bug report suggest no one has a workaround. It is what it is.

raszpl commented 1 week ago

Hmm, still getting errors, but now it was one instance

Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist.

after few hours

raszpl commented 1 week ago

at least test if its not crashing :-)

spoilers - it was crashing :] https://github.com/code-charity/youtube/pull/2380

ImprovedTube commented 1 week ago

at least test

some more people will already hopefully. it was also is just an acknowledgement, that the changes make me hurry :) @raszpl

chrome.windows.onFocusChanged is only slightly better due to 10 year old Chrome bug https://issues.chromium.org/issues/41116352 :o Chrome doesnt tell us when user alt-tabs away.

Can we make up for that somehow (...?)

Tried, failed, bug report suggest no one has a workaround. It is what it is.

(could monitor alt+tab keyboard events.)

raszpl commented 3 days ago

Tried, failed, bug report suggest no one has a workaround. It is what it is.

(could monitor alt+tab keyboard events.)

so you didnt click the link and read that bug report :)