Need help: Failed to load module script (MIME type, WebViewAssetLoader)

0 favourites
  • 2 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

    Can I ask why you are doing this in the first place? Construct's built-in Android export option already gives you an Android app with all the resources bundled, so it works offline, and you don't need to download anything from the Internet, do anything else to manage offline support, or write your own network request interceptor. Construct's Android export has quite a lot of complicated compatibility code to work around all these types of issues, and so if you don't use Construct's Android export, you're going to have a long path of reinventing all these difficult compatibility headaches, such as this one, and probably several more you will encounter in future.

    Anyway, this specific problem should be simple to solve: as the error message says you just need to make sure the returned MIME type is application/javascript for .js files. A quick Google shows that you can set this on the returned WebResourceResponse via setMimeType. However as I said, this will probably look like it works until you run in to the next compatibility problem which you have to add further hacks for...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)