Problem with same-origin policy when testing offline

I’m developping a game which uses 2 iframes and Javascript exchanging data from one frame to the other. Works fine when my files are in a web server (protocol http://). But when I need to test my game locally, i.e. offline (protocol files:///), it is blocked by the so-called «Cross- origin resource sharing (CORS)». How can I be crossing a domain or whatever when all my files are on my own computer? Does anyone know some Javascript that would allow me to bypass this silly behaviour? I’m able to test my game locally with Internet Explorer 11, but not with Firefox or Chrome. I’ve tried LocalStorage and it seems to work with Firefox and Chrome but not with IE. So that’s not a solution… I need a Javascript that will work this out in all 3 browsers. Can you help me solve this problem?

If you have npm installed you can run npx serve in the directory and it’ll serve your files via http.
Or if you’re using VSCode there is a Live Server extension.

OOOps! I don’t know what npm is, don’t know what VSCode is. Perhaps I should have mentioned that I want my game to be playable offline as I don’t have a website and I want my friends and family to be able to play the game on their computer without having to install any kind of software or change any settings in their browser. That’s why I’m looking for a Javascript that can tell their browser «Hey stupid, all this stuff has a same-origin, we’re not connected to the internet, we’re offline, and all the files are at the same place in a main folder (with subfolders), located at files:///C:/Users/etc.» Is it possible, with Javasctipt only, to bypass that same-origin policy when running a browser offline? At least with IE, Firefox, and Chrome?

Any other solution anyone?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.