realtime-csharp icon indicating copy to clipboard operation
realtime-csharp copied to clipboard

Failed to start Websocket client , error: 'Operation is not supported on this platform.'

Open MoienTajik opened this issue 1 year ago • 3 comments

Bug report

Describe the bug

I am using Supabase v1.1.1 in a Blazor WebAssembly (WASM) application running on .NET 8. The issue occurs with this commit in the Supabase.Realtime package, so v1.1.0 is working without any issue. Specifically, the problem is on this line, where the following method is invoked:

socket.Options.SetRequestHeader(header.Key, header.Value);

This method is marked with [UnsupportedOSPlatform("browser")], and when calling InitializeAsync in a Blazor WASM application, the following exception is thrown:

Error: One or more errors occurred. (Failed to start Websocket client , error: 'Operation is not supported on this platform.')

To Reproduce

  1. Create a new Blazor WASM project.
  2. Install the Supabase NuGet package v1.1.1.
  3. Register Supabase in DI Container (or manually create an instance of it) as shown below:
builder.Services.AddSingleton(sp =>
    {
        var client = new SupabaseClient(
            Constants.Supabase.Url,
            Constants.Supabase.ApiKey,
            new()
            {
                AutoRefreshToken = true,
                AutoConnectRealtime = true,
                SessionHandler = sp.GetRequiredService<SupabaseSessionProvider>()
            });

        return client;
    }
);

Call InitializeAsync on the Supabase client:

await supabase.InitializeAsync();

Expected behavior

The InitializeAsync method should not throw an exception, or there should be a guard like [UnsupportedOSPlatform("browser")] to prevent setting AutoConnectRealtime to true on the WASM runtime.

System information

  • OS: macOS
  • Browser: Arc (Chromium)
  • Supabase NuGet Package Version: 1.1.1

MoienTajik avatar Aug 12 '24 16:08 MoienTajik

Same here.

mzke avatar Sep 21 '24 08:09 mzke

This is happening in my project as well.

trucksmart avatar Oct 03 '24 18:10 trucksmart

The only workaround for now is to mark AutoConnectRealtime as false, if you don't really need it.

MoienTajik avatar Oct 05 '24 05:10 MoienTajik