Skip to content

WebGL JavaScript & native error handling #668

Description

@vaind

After the dotnet WebGL support is merged in #657, we can add support for javascript errors. There are two main approaches, the selection of the best one is part of this issue:

  1. either include sentry-javascript and let it do the reporting
  2. or implement the error handlers same as sentry-javascript does but forward errors to dotnet via wasm calls (if that's even possible - there's a list of all native functions available in development build sources)

In both cases, we would need to add an editor script that updates the generated JS sources (that supports both development & release builds, the latter including compression).

There's already a button to trigger a JS error - look for ThrowJavaScript(), enable it in NativeSupportScene.cs - but there would likely need to be more, e.g. to also include it in the SmokeTest.

As a related topic, we should check whether the selected approach also covers errors in the native code that are unhandled - you can reproduce those within the "Native Samples" scene in the sample repo.

Activity

  1. vaind commented on Mar 30, 2022

    @vaind
    ContributorAuthor

    Additional off-topic TODO: warn/error out during build when "com.unity.modules.unitywebrequest": "1.0.0" package is disabled - otherwise Unity just throws a vague error: Cannot create web request without initializing the system that I couldn't get any useful resolution for by googling

    It requires the build script to be present so sounds like a good time to do it in a single PR.

  2. bruno-garcia commented on Mar 30, 2022

    @bruno-garcia
    Member

    either include sentry-javascript and let it do the reporting

    I think this is the preferred solution as it's our largest SDK and has a lot of development going on there.

  3. vaind commented on Apr 14, 2022

    @vaind
    ContributorAuthor

    I've tried to integrate the browser bundle.js and it kinda works, as in the event is reported to sentry.io, however, I'm not sure how to get any stack trace info, because the scripts are loaded as blobs, which are, in case of a release build, also compressed...

    Maybe we'd need to create a custom integration that does the stack parsing.

    unity-web.zip

  4. vaind commented on Apr 14, 2022

    @vaind
    ContributorAuthor

    OK, so the stack traces for the embedded code coming from Unity .jslib are pretty limited but I don't think there's much we can do, they're just not there on the error reported by the browser.

    The integration could still be useful at least to get the error type/text + stack traces if they're coming from standard javascript files.

    What we would need to do is:

    1. Add sentry-js bundle to the sentry-unity package (either in repo or in CI) - I guess we're fine with including only the minified version, regardless of what kind of app user builds: https://browser.sentry-cdn.com/6.19.6/bundle.min.js
    2. Create a PostBuild integration to alter the generated index.html, adding the Sentry-javascript initialization to the beginning of <head>:
      <script src="Build/bundle.js"></script>
      <script>
        Sentry.init({
          dsn: "https://94677106febe46b88b9b9ae5efd18a00@o447951.ingest.sentry.io/5439417",
          release: "0.1.0",
          ....
        });
      </script>
    3. Make some kind of integration test: I think we could use SmokeTester.cs to launch the javascript error sample we already have in the example app. The existing WebGL python server would capture and check that.
    4. [optional] Implement scope sync - requires individual functions, similar to objective-c
  5. bitsandfoxes commented on Nov 12, 2025

    @bitsandfoxes
    Contributor

    Superseded by #2415

  6. moved this from Todo to Done in GDXon Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions