Chrome – Bypass Access-Control-Allow-Origin on local file system

Just wanna do some proof of concept on reading a JSON file in Javascript. So i open the index.html and read the JSON file locally. But the Chrome console throw the Access-Control-Allow-Origin error.

  • XMLHttpRequest cannot load file:///C:/Users/user/Desktop/readJson/data/file-1.json. Origin null is not allowed by Access-Control-Allow-Origin.

Although it should work if i upload those sources files to a web server, i would still make it work locally especially for development purpose. So here is a small trick which could ask the Chrome browser to bypass this cross-domain restriction.

1. Close all the Chrome browser windows.

2. Run the following command in shell or windows run command prompt as follow.

chrome.exe --allow-file-access-from-files

chrome-bypass-access-control-allow-origin-locally
Done =)

Reference: StackOverflow – Problems with jQuery getJSON using local files in Chrome

2 thoughts on “Chrome – Bypass Access-Control-Allow-Origin on local file system”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.