Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
IJSRuntime returns null in Blazor component

So I have a blazor component which runs a javascript method inside its OnInitializedAsync method. But it returns null somehow, although the javascript function itself returns something for sure which I checked using debugging. I logged the result of the javascript function and put console.log before and behind the return and behind it didn't show which means it returned something. What it's supposed to return i already debuged using console.log and its the correct result. This is the code of my blazor component:

@using System.Diagnostics
@inject IJSRuntime _jsRuntime

<div class="summoner-icon" style='background-image: url("@IconPath");'>
    <div class="summoner-level-circle" style="background-color: @_mainColor;">
        <a>@Level</a>
    </div>
</div>

@code {
    [Parameter]
    public string IconPath { get; set; }
    [Parameter]
    public long Level { get; set; }
    private string _mainColor;
    protected override async Task OnInitializedAsync()
    {
        _mainColor = await _jsRuntime.InvokeAsync<string>
            ("getProfileIconMainColor", IconPath);
    }
}

Besides that, here you can see the javascript function:

window.getProfileIconMainColor = function (url) {
    const image = document.createElement('img');
    image.src = url;
    image.crossOrigin = "anonymous";
    image.onload = function () {
        const colorThief = new ColorThief();
        const mainColor = colorThief.getColor(image);
        return rgbToHex(mainColor[0], mainColor[1], mainColor[2]);
        /*return "rgb(" + colorThief.getColor(image).join(",") + ")";*/
    }
}

const rgbToHex = (r, g, b) => '#' + [r, g, b].map(x => {
    const hex = x.toString(16)
    return hex.length === 1 ? '0' + hex : hex
}).join('');
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda