We sold a game to a customer and he gave the the following feedback. Maybe you have a solution for this?
I’ll try to describe the issue as we faced and how we were able to drill down to the probable cause:
Context on what we are doing:
For loading the game on the android app, we download and cache the whole game bundle locally to reduce the download time for subsequent game loads. We leverage the request interceptor functionality of WebView to intercept the network request and then use the WebViewAssetLoader to load the response for the intercepted request from internal storage.
Issue we faced:
For android devices with Android 10 and lower, the game is unable to load from the local cache. Loading works fine if we load from the internet.
The following error is observed:
I/chromium: [INFO:CONSOLE(0)] “Failed to load module script: The server responded with a non-JavaScript MIME type of “text/plain”. Strict MIME type checking is enforced for module scripts per HTML spec.“, source: https://d2cx3uugochcmv.cloudfront.net/h5-game-bundles/smp_pets_rush-v15-pr_basic_table/scripts/c3runtime.js (0) I/chromium: [INFO:CONSOLE(27)] “Uncaught (in promise) #<Event>“, source:
I/chromium: [INFO:CONSOLE(27)] “Uncaught (in promise) #<Event>“, source: https://d2cx3uugochcmv.cloudfront.net/h5-game-bundles/smp_game-v15-pr_basic_table/scripts/main.js (27)
Debugging the issue
From the error message, it seems that MIME type for the js files being loaded from the cache are being reported as “text/plain” instead of “application/javascript”. The MIME type is inferred by Android’s WebViewAssetLoader when it loads the game assets from internal storage.
This seems to be the behaviour in pre Android 10 devices and is happening for all our games. For post android 10, the MIME type inference works properly for js files.
If MIME type reporting is broken then why other games are not affected?
If we revisit the above error log, we can see the following clause: “Strict MIME type checking is enforced for module scripts per HTML spec”
This means that if we are using js modules in the games, then this issue will occur. It might be possible that other games are not using js modules while the game is using them.
Goin through the code for the other games, we found out that js modules are not being used in those. Hence, the issue does not arise for other games.
Earlier game version is unaffected? What changed?
Comparing the diff between earlier and current versions of the game, we found out that indeed, js modules are being used now. In the AddScript function in c3runtime.js, we are dynamically adding script elements with type “module”. This change is not there in earlier versions. There are other instances too, but this one was the most obvious.
Conclusion
Since, the game asset loading on pre android 10 devices is not working due to this issue. I suggest we remove the use-cases of javascript modules from the game. This is because it is unknown what causes the MIME type issues in these devices. Until then, to get things working we might have to make this change.
If you guys have any insights into the MIME type issue such that it can be resolved without removing js modules, please let us know.
The initial build did not have this dependency on js module.
Can you crosscheck, if we can remove the dependency because its something that only got added on later
Thanks and Regards,
------
What could be the best solution. No idea what feedback I could give them. Could you help me/them?
THANKS IN ADVANCE