Duplicated broadcast messages

I can confirm I am also experiencing this issue. My Extension has been live for months and this issue has never been noted before, however I personally started observing it as of yesterday.

For reference, here is my listener code

window.onload = function () {
    window.Twitch.ext.listen('broadcast', broadcastMessage);
};

Note - I initially had this code outside of the window.onload and the same thing was happening.

I noticed if I remove the listen from my JS file and instead register it by pasting into the brower dev tools console some time after my Extension was loaded I do not get the duplication issue.


Edit: After some testing, I believe the duplication only happens if the listen is bound before the initial onAuthorized is triggered. I tested this by having my listen outside the onAuthorized and binding it after several different timeouts (1ms, 100ms, 1000ms). The only instances I have observed the broadcast duplicating has been those in which the listen bind happens before the initial onAuthorized has been received.

I have now moved my listen bind inside the onAuthorized handler with a boolean to ensure it only happens on the first onAuthorized and am no longer observing duplicates. E.g.

var listenBound = false;
window.Twitch.ext.onAuthorized(function (auth) {
    if (listenBound === false) {
        window.Twitch.ext.listen('broadcast', broadcastMessage);
        listenBound = true;
    }
});

I also used the Wayback Machine to find older versions of the Twitch JavaScript helper file. The version from August 22nd appeared to have the same duplication and any older versions (March and earlier) seemed to have other API related issues which rendered them untestable. So, either this issue has been occurring since on or before August 22nd, or it is not directly related to the JavaScript helper file.

Of course my observations above may be a red herring entirely, but my testing thus far has seemed pretty consistent and I have in place what seems to be a reliable work around :crossed_fingers:

1 Like