Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!