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

270
Views
cross-origin error when using color-thief

I'm not gonna lie, cross-origin is not very clear to me although I've read some articles about it.

I was trying to fetch songs from an api which does not have Access-Control-Allow-Origin "*" meeans i couldn't get the data inside my app. I went to google, stackoverflow, read some articles and used the proxy: "https://www.jiosaavn.com" in package.json which i got in this article: https://medium.com/swlh/avoiding-cors-errors-on-localhost-in-2020-5a656ed8cefa

It did fix my issue, api requests are working fine.

But now I want to add color-thief to my app.

I made a recent post about it. It works when I use image from sources like unsplash and pexels with attribute crossOrigin={anonymous} on the image HTML element like this

<img
        crossOrigin={anonymous}
        ref={imgRef}
        style={{width:"400px", objectFit: "contain"}}
        src="https://images.pexels.com/photos/1534411/pexels-photo-1534411.jpeg?cs=srgb&dl=pexels-shukhrat-umarov-1534411.jpg&fm=jpg"
        alt="landscape"
        onLoad={() => {
          const colorThief = new ColorThief();
          const img = imgRef.current;
          const result = colorThief.getColor(img, 25);
          console.log(result);
        }}
/>

But adding crossOrigin={anonymous} makes the image fail to load (which I'm getting from the api).


If you're wondering why I didn't use it like this:

<img
            src={currentSong.image}
            ref={imgRef}
            alt="Songimg"
            onLoad={() => {
              const colorThief = new ColorThief();
              const img = imgRef.current;
              const result = colorThief.getColor(img, 25);
              console.log(result);
            }}
          />

then, it shows me this:

SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data
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!