twitchdev / issues

Issue tracker for third party developers.
Apache License 2.0
73 stars 6 forks source link

Callback crash - stops onAuth and/or viewer. variables to populate #820

Open BarryCarlyon opened 1 year ago

BarryCarlyon commented 1 year ago

Brief description

If javascript crashes inside the function window.Twitch.ext.configuration.onChanged for example via an uncaught exception

It will stop onAuthorized being called And/or will stop window.Twitch.ext.viewer.sessionToken (and other viewer vars) populating

How to reproduce

Crash you javascript in onChanged callback

Expected behavior

Uncaught extensions in any callback doesn't stop other callbacks occuring

Additional context or questions

This paticular issue is only effecting one of my extensions on mobile

Which might be indicative of something odd/race conditiony inside the Twitch mobile app.

I serve the same HTML/JS/CSS to mobile and desktop platforms.

This is something I can resolve with a try/catch tweak in my code, it's just weird it only is screwing up the Mobile platform.

But I have caused this issue in the past which effected all platforms, where as today it's just mobile which is bizarre

BarryCarlyon commented 1 year ago

In this example

My global segment is populated My developer segment is not

On mobile my code is uncaught exceptioning in the developer segment loading part of my code. I can tell as if I populate the dev segement on a channel with {} the extension now works on mobile for that channel.

My this issue doesn't plague desktop users.

BarryCarlyon commented 1 year ago

I have found the issue.

It found appear the config service and perhaps other parts of the JS Helper functions differently compared to mobile and desktop

At the top is a JSON.stringify of window.Twitch.ext.configuration on desktop At the bottom a JSON.stringify of window.Twitch.ext.configuration on mobile (iOS specifically, but droid gets the same object)

image

This is causing a issue in my code, which yes I can fix as somewhere my code is not null checking properly

But this indicates that my code is throwing an uncaught exception but only on mobile platforms. Which is interesting to debug.

Specifically here, on desktop broadcaster and developer segments are null. But on Mobile broadcaster and developer keys are missing.

Since I don't try/catch correctly or handle this data correctly, the code is uncaught exceptioning and then stopping everything else running. Such as onAuthorised

My code/other notes

    if (window.Twitch.ext.configuration.hasOwnProperty('developer') && typeof window.Twitch.ext.configuration.developer != 'undefined') {
        if (window.Twitch.ext.configuration.developer.hasOwnProperty('content')) {

for completeness is my bit of code thats causing the fault, and the intercepted console.log for a mobile run/load, It's undefined on desktop but null on mobile causing the hasOwnProperty('content') to trip

In has global
PUNTED
{"broadcaster":null,"developer":null,"global":{"content":"{\"ebs\":\"https://twitch.extensions.barrycarlyon.co.uk/igdb/api/\",\"igdb_cover\":\"//images.igdb.com/igdb/image/upload/t_cover_big/{id}.jpg\",\"igdb_screenshot\":\"//images.igdb.com/igdb/image/upload/t_screenshot_big/{id}.jpg\",\"twitch_cover\":\"//static-cdn.jtvnw.net/ttv-boxart/{id}\"}","version":""}}
In on changed
In parsed global
TRYING DEVELOPER
Dev errored
TypeError: null is not an object (evaluating 'window.Twitch.ext.configuration.developer.hasOwnProperty')

My "in production" extension doesn't catch the null is not an object so crash we go.

jbulava commented 1 year ago

The team has reviewed this bug in detail and has decided no changes to the Extensions product are to be made at this time. However, they would like to encourage the use of a try-catch during Extension development to handle this situation gracefully.

With that in mind I'm curious if there are any resources or examples we need to update on the developer site. We can look into this further, though if there is specific content that comes to mind, please let us know here.