I want to read window.devicePixelRatio in javascript from C# in ASP Core Blazor.
This is my javascript in wwwroot/index.html:
<body><script> function PixelRatio() { return window.devicePixelRatio; }</script> ...And in Index.razor, I trying to call it like this:
@inject IJSRuntime JS protected override void OnAfterRender(bool firstRender) { base.OnAfterRender(firstRender); if (firstRender) { GetDevicePixelRatio(); } } private async Task GetDevicePixelRatio() { Console.WriteLine("GetDevicePixelRatio Calling"); // This shows in Output-log m_dpiScale = await JS.InvokeAsync<double>("PixelRatio"); Console.WriteLine("GetDevicePixelRatio Called with value " + m_dpiScale); // This is not called. }I expected the returnvalue be 2.5, but the second Console.WriteLine is not called, I dont know if the InvokeAsync is hanning, or if it throws an silence exception, but nothing i can see.
I can debug in javascript in function PixelRatio() but nothing happens when it returns.