Skip to content

Conversation

@bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Sep 18, 2025

Fixes #2190, #2249

The WebGL support was lacking in a couple of areas:

Exception Capture & Stack Traces

When targeting WebGL, exception support is controlled via Publishing Setting Enable Exceptions. This has multiple levels:

None,
Explicitly Thrown Exceptions Only <-- Default
Full Without Stack Trace
Full With Stack Trace <-- Debug Only

The exception capture needs to be raised above None for the SDK to function. When set to None, managed exceptions crash the game - we now halt the build if we detect this misconfiguration.

With the default setting of Explicitly Thrown Exceptions Only, the SDK's StackTraceFactory fails to create stack traces, resulting in events without stack trace information.

Solution: When targeting WebGL, the SDK now captures exceptions through the logging integration (UnityApplicationLoggingIntegration) instead of the incompatible UnityLogHandlerIntegration. This allows the SDK to parse stack traces from Unity's log messages, providing better error context even with the default WebGL exception settings.

Implementation

  • Non-WebGL platforms: Use both UnityLogHandlerIntegration (for exceptions) and UnityApplicationLoggingIntegration (for logs)
  • WebGL platform: Use only UnityApplicationLoggingIntegration with exception handling enabled (captureExceptions: true)

Before:

Screenshot 2025-09-19 at 15 18 38

After:

Screenshot 2025-09-19 at 15 21 30

Alternative

An alternative approach would have been to use .NET SDK's StringStackTraceFactory. But this comes with some drawback such as the lack of in-app and the missing mechanism key. Additionally, this would regress the state we have with Full With Stack Trace as this is a build time setting we have no access to at runtime.

Crashed Last Run

We were defaulting to false. But since the SDK does not provide native support for WebGL, this creates the false impression that the last run did not crash. We're setting the callback to null no and log the state of support when the last run state gets fetched by the user.

Improved Logging & Error Messages

Updated WebGL-specific warning messages to be clearer about known limitations:

Previously:

Sentry: (Warning) Failed to find required IL2CPP methods - Skipping line number support

Now:

Sentry: (Warning) IL2CPP line number support is unsupported on WebGL - disabling.

Build-time Validation

Fixed a bug in the build pre-processor that prevented disabling the SDK when WebGL exception settings were misconfigured, ensuring developers can always build their projects.

cursor[bot]

This comment was marked as outdated.

@bitsandfoxes bitsandfoxes requested a review from a team September 23, 2025 14:30
@bitsandfoxes bitsandfoxes merged commit 06e9cf8 into main Sep 23, 2025
148 of 151 checks passed
@bitsandfoxes bitsandfoxes deleted the feat/update-webgl-handling branch September 23, 2025 18:34
@github-actions
Copy link
Contributor

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- Handle WebGL specific options explicitly ([#2322](https://github.com/getsentry/sentry-unity/pull/2322))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against fd03d17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sentry is not sending the event to Unity WebGL

2 participants