supabase-community / realtime-csharp

A C# client library for supabase/realtime.
https://supabase-community.github.io/realtime-csharp/api/Supabase.Realtime.Client.html
MIT License
70 stars 12 forks source link

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

Open MoienTajik opened 1 month ago

MoienTajik commented 1 month ago

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

mzke commented 9 hours ago

Same here.