0

Everything is working fine in Chrome the problem is with FireFox and Microsoft Edge. With these two browsers I keep on getting CORS errors. I am making no API calls in this website. All this function that is causing this error is doing is resetting the opacity of some text I hid back to 1.

This is the function that is causing the error:

setTimeout(() => {
  opacityP.style.opacity = 1;
  opacityB.style.opacity = 1;
}, 3000);

This are the error message from FireFox and Microsoft Edge: Firefox Cors Error

Microsoft Edge Cors Error

Thanks in advance for your help.

Khanya
  • 81
  • 5
  • Could you post your HTML as well? I assume you are using a wrong src in your script tag that happens to work in Chrome but not in Firefox and Edge because it's not standard. I know firefox tends to yeet out a lot of things and says they are caused by CORS while they really aren't (like blocking trackers). – geisterfurz007 Apr 20 '22 at 08:36
  • you probably have some setting turned on in Chrome that allows this to happen - find it and turn it off immediately – Bravo Apr 20 '22 at 08:41
  • I'd assume it is working in Chrome because it is loading the HTML document through a web server so has an HTTP URL and those is not a cross origin request. I've never known Firefox to complain about a CORS problem that wasn't really a CORS problem. – Quentin Apr 20 '22 at 08:41
  • Do you want me just add the HTML part that is involved or the whole script? – Khanya Apr 20 '22 at 08:44
  • All I have been running the script through is the Live server on VS code, the default browser that I set is Chrome. – Khanya Apr 20 '22 at 08:47

1 Answers1

0

I think it's not possible to access local script files at the browser level. You can run the code through a local server like localhost:3000 or so. Xampp or Wamp would work for you. If you're using VS Code, you can use their extension. https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer

Hope this helps you!

RM-Digit
  • 94
  • 8
  • I have been running it through the Live server in VS code (the default browser being Chrome which is why I think it's working on Chrome). I tried opening the website version that is on Xampp on Firefox and Microsoft Edge but it's not working. Maybe there is something I'm not doing right with Xampp that might be causing the issue. – Khanya Apr 20 '22 at 08:51
  • Got it. Did you put `type=" text/javascript"` when importing the script into your HTML file? – RM-Digit Apr 21 '22 at 09:12