Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIME Type Issues Even With Brotli/Disabled Compression Formatting #970

Open
nsdod opened this issue Jul 15, 2024 · 2 comments
Open

MIME Type Issues Even With Brotli/Disabled Compression Formatting #970

nsdod opened this issue Jul 15, 2024 · 2 comments
Labels
WebGL This issue is specific to the Web platform

Comments

@nsdod
Copy link

nsdod commented Jul 15, 2024

Hi! I'm seeing an issue where the Unity Flutter widget doesn't load properly when navigated to from another page (WebGL). The error log appears as follows:

errors.dart:296 Uncaught (in promise) Error
    at Object.throw_ [as throw] (errors.dart:296:3)
    at Object.assertFailed (errors.dart:29:3)
    at get page (page_view.dart:170:17)
    at page_view.PageController.new.nextPage (page_view.dart:223:26)
    at onboarding_widget._OnboardingWidgetState.new.<anonymous> (onboarding_widget.dart:41:40)
    at Generator.next (<anonymous>)
    at async_patch.dart:45:50
    at _RootZone.runUnary (zone.dart:1661:54)
    at _FutureListener.thenAwait.handleValue (future_impl.dart:163:18)
    at handleValueCallback (future_impl.dart:847:44)
    at _Future._propagateToListeners (future_impl.dart:876:13)
    at [_complete] (future_impl.dart:643:7)
    at future.dart:420:15
    at internalCallback (isolate_helper.dart:48:11)
[...]

js_primitives.dart:28 Created Unity scene: attach controller
flutter.js:3 Exception while loading service worker: DOMException: Failed to register a ServiceWorker for scope ('http://localhost:55405/modEdit/UnityLibrary/') with script ('http://localhost:55405/modEdit/UnityLibrary/flutter_service_worker.js?v='): The script has an unsupported MIME type ('text/html').
(anonymous) @ flutter.js:3
Promise.catch (async)
loadEntrypoint @ flutter.js:3
(anonymous) @ index.html:66
load (async)
(anonymous) @ index.html:64

index.html:1 Refused to execute script from 'http://localhost:55405/modEdit/UnityLibrary/main.dart.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
2errors.dart:296 Uncaught Error
    at Object.throw_ [as throw] (errors.dart:296:3)
    at Object._failedAsCheck (rti.dart:1388:3)
    at dart_rti.Rti.new._generalAsCheckImplementation (rti.dart:1366:3)
    at Object._argumentErrors (operations.dart:243:33)
    at Object._checkAndCall (operations.dart:422:22)
    at Object.callMethod (operations.dart:494:10)
    at Object.dsend (operations.dart:498:5)
    at web_unity_widget_controller.dart:114:27

The error references a MIME type issue that, from previous reports, appear to usually be caused by selecting the GZIP compression format. However, this Unity project is built to WEBGL with the compression formatting disabled (and changing it to Brotli doesn't fix the issue). The UnityLibrary assets appear to be in the correct place after exporting.

The 'modEdit' reference as seen in this error is the previous page from which the Unity widget's page is navigated to. Could this have something to do with how the iframe used to contain the Unity application loads into the widget, or a strange interaction with the Navigation stack? The base application is made with Flutterflow. However, the Unity Flutter widget is added to the project manually, after exporting the project to into Dart/Flutter code. Lottie animations are in use for page transitions.

Browser: Google Chrome 126.0.6478.127
Unity version: 2022.3.27f1
Flutter: 3.22.2
Dart: 3.4.3

@nsdod
Copy link
Author

nsdod commented Jul 25, 2024

Update! I have more information on what's going on here.

So, the iframe generated by the Unity Widget (I think) is trying to access the UnityLibrary directory from a parent directory that does not exist in the build. In particular, the page with the Unity widget on it is navigated to from a page called 'modEdit' via a button press. The iframe that's meant to have the Unity app in it looks like this:

<iframe id="webView0" src="http://localhost:51020/modEdit/UnityLibrary/index.html" style="width: 100%; height: 100%; border: none;">[...]</iframe>

But no such directory/file http://localhost:55405/modEdit/UnityLibrary/main.dart.js exists. I'm not sure why the iframe is pointed to this location when it should be looking in the root directory of the app. Does anyone have any ideas on what's causing this or how to correct it? Any additional information needed?

@timbotimbo
Copy link
Collaborator

Does it make a difference if you use the previous version of the plugin (2022.2.0) ?
2022.2.1 included a PR to allow unity to work when Flutter is not at the root of the domain, see the change here.

I believe that is also the only location in the plugin where a web directory is defined.

If this doesn't help, maybe try creating a small reproduction project that triggers this, which uses as few other plugins as possible.

@timbotimbo timbotimbo added the WebGL This issue is specific to the Web platform label Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebGL This issue is specific to the Web platform
Projects
None yet
Development

No branches or pull requests

2 participants