Conversation
Replace `dart:io` Platform checks with `package:flutter/foundation.dart` defaultTargetPlatform in model files, making them compatible with web. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract ChannelClient into client_io.dart and use conditional imports to select the platform client at compile time. Add client_web.dart with stub implementations that print method names for start(), setUser(), and notify(). Register the web platform in pubspec.yaml with a no-op plugin entry point. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Which makes it easier to find it amongst other logs.
Call Bugsnag.start() via dart:js_interop to initialize the browser SDK. Pass through apiKey, appVersion, releaseStage, enabledReleaseStages, and collectUserIp to the JS config. Hook up Flutter error handlers when autoDetectErrors is enabled. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Called automatically on bootstrap when autoTrackSessions is enabled. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sends errors to bugsnag-js with Dart error metadata attached. Constructs a BugsnagEvent for Dart-side onError callbacks before delegating to the JS SDK. Also fixes BugsnagError.toJson() to properly serialize stackframes into plain maps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Aligns with ChannelClient pattern where autoDetectErrors is handled in the constructor rather than platformStart. Removes unused _autoDetectErrors field. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix _notifyUnhandled to correctly mark errors as unhandled - Fix _bugsnagNotify to use proper JS onError callback instead of options object - Add _BugsnagJsEvent extension type for bugsnag-js event interop - Bump minimum Dart SDK to >=3.3.0 (required for extension types) - Remove unused web dependency Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
This pull request refactors the platform-specific implementation of the
bugsnag_flutterclient to use a more modular and extensible approach, enabling preliminary support for web.Note that our goal is to add MVP support for Flutter on web. Only the methods and properties that are actually used in our applications are supported; other methods throw
UnimplementedErrors.Installation
In order to add support for bugsnag on Flutter web, the following script needs to be added to the index.html of the application (taken from the docs).
Design
The core change splits the monolithic
client.dartinto a platform-conditional architecture using Dart's conditionalimports:
At compile time, Dart selects the correct implementation file based on the target platform's available libraries. Each file exports the same two top-level factory functions —
platformStart()andplatformAttach()— which the Bugsnag facade calls to obtain a platform-specific BugsnagClient.graph TD subgraph "Public API" C["BugsnagClient<br/><i>abstract class</i>"] end subgraph "Platform resolution" C -->|"dart.library.io"| D["client_io.dart<br/><b>ChannelClient</b>"] C -->|"dart.library.js_interop"| E["client_web.dart<br/><b>WebClient</b>"] C -->|"fallback"| F["client_stub.dart<br/><i>throws UnsupportedError</i>"] end subgraph "Native layer" D -->|"MethodChannel"| G["Android/iOS<br/>Bugsnag SDK"] E -->|"dart:js_interop"| H["@bugsnag/browser<br/>JS library"] endFile responsibilities
dart:ioordart:js_interopimports.MethodChannel. Selected whendart.library.iois available.@bugsnag/browserviadart:js_interopbindings (@JS()annotations). Selected whendart.library.js_interopis available.platformStart()andplatformAttach()throwUnsupportedError.How delegation works
The Bugsnag singleton uses the DelegateClient mixin, which holds a nullable _client reference. When bugsnag.start() or bugsnag.attach() is called, it invokes the conditionally-imported platformStart()/platformAttach() function, which returns a ChannelClient (IO) or WebClient (web). All subsequent API calls on bugsnag are forwarded to this inner client.
Web implementation details
WebClient uses
dart:js_interopto call the@bugsnag/browserJS library that must already be loaded in the host page. Currently implemented:start,notify,setUser,resumeSession, and automatic unhandled error capture (viaFlutterError.onErrorandPlatformDispatcher.instance.onError). Remaining API methods throwUnimplementedErrorand can be added incrementally.Changeset
Testing