1

Access to XMLHttpRequest at "./sounds/sound.mp3" from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

I am making a project where I want to make a game, but nothing major is a canvas element. (all moving IMG tags and divs)

OTHER SOLUTIONS DO NOT WORK. I am using howler.js to play a sound clip and I get this, however sometimes tone.js DOES work. I don't know how to fix this because I need non-tech savvy people to use this file, so chrome settings are off limits for me. Also, I can't use localhost or web servers. Does anyone know how to fix this?

SuperJumpBros
  • 193
  • 2
  • 15
  • Please visit [help], take [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output. – mplungjan Apr 14 '20 at 12:29
  • You cannot use a page loaded from file protocol to Ajax to a CORS enabled server – mplungjan Apr 14 '20 at 12:30
  • You will have to download the resources to the same file system as the page – mplungjan Apr 14 '20 at 12:33

2 Answers2

0

Run the entire website as localhost (using xampp for example) should fix it

Tom Truyen
  • 318
  • 1
  • 3
  • 15
-2

You can put this code in a batch script (Windows) or a shell script (Linux/Mac) and ask them to double click on the script (if they are using Google Chrome - I don't think you can do this on Firefox):

Windows:

C:\Program Files (x86)\Google\Chrome\Application\chrome.exe <path to file>

Linux:

google-chrome <path to file> -allow-file-access-from-files

Mac:

open -a 'Google Chrome' <path to file> —allow-file-access-from-files

TheKodeToad
  • 301
  • 2
  • 10