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

254
Views
check if a CORS error is occuring using Javascript

I'm experiencing a CORS error on a website made with webflow. Basically, I wrote a p5.js script to draw some images fetched from Webflow CMS, the problem is that when I load the images through their URL I often get an error that says: "is not allowed by Access-Control-Allow-Origin".

I did some research and I couldn't find a solution to this issue, the only thing that seems to work is refreshing the page a couple of times.

So I wanted to implement a temporary solution adding a js script that refreshes the page if a CORS error happened. I've tried with this but unfortunately, even though I see the error from the console, it seems like the script is not triggered.

Can you help me understand what I'm doing wrong?

window.onerror = function(error) {
  console.log("I detected this error: " + error);
  location.reload();
};

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Webflow has wrongly configured CORS headers (see this 4-year long discussion). CORS is a browser-level security feature, so there is is no way around it from your end. Webflow must update their platform to conform to modern Internet security, or it will continue to fail more and more often as browsers expand enforcement.

However, to answer your question:
To error-catch CORS-blocked canvas drawing, you can do so at the draw command:

try {
    canvasContext.drawImage( myCrossOriginImage, 0, 0 );
} catch ( e ) {
    console.error( "Caught a contaminated image, cannot draw it: ", e );
}

Since this error does not fire on the canvas element, it will not propagate to the window element.

Since you are using p5.js, the draw event is probably happening outside your code, so this might be difficult, but please try it at your image() command.

try {
    image( myCrossOriginImage, 0, 0 );
} catch ( e ) {
    console.error( "Caught a contaminated image, cannot draw it: ", e );
    //instead of reloading the page, please try drawing a different image?
}
about 4 years ago · Juan Pablo Isaza Report
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!