Skip to content

[Blazor WebAssembly] Not works with blazor hybrid + winform #634

@wu-yafeng

Description

@wu-yafeng

When use Fido2.BlazorWebAssembly in winform + blazor, the following exception thrown:

Cannot invoke JavaScript outside of a WebView context.

Temp solution:

InitializeComponent();
var services = new ServiceCollection();
services.AddWindowsFormsBlazorWebView();
- services.AddWebAuthn();
+ services.AddScoped<WebAuthn>();
services.AddSingleton(new HttpClient()
{
    BaseAddress = new("https://localhost:7108/")
});
blazorWebView1.HostPage = "wwwroot\\index.html";
blazorWebView1.Services = services.BuildServiceProvider();
blazorWebView1.RootComponents.Add<App>("#app");

The reason of error is singleton service created before blazor webview ready.

Should import WebAuthn.js in Init() method ?

async Task Init() => js.InvokeAsync<IJSObjectReference>("import", "./_content/Fido2.BlazorWebAssembly/js/WebAuthn.js");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions