LoginSignup
10

More than 5 years have passed since last update.

posted at

updated at

【Mac】Google Chromeでローカルファイル参照時のエラー回避

Google ChromeでJSONなどのローカルなデータを読み込もうとするとエラーが表示されます。

Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 

ターミナル.appから以下のようにchromeを起動すると良いです。

open -a /Applications/Google\ Chrome.app --args -allow-file-access-from-files index.html

今後起動しやすいように.bash_profileに以下の記述をしました。

alias google_chrome_dev="open -a /Applications/Google\ Chrome.app --args -allow-file-access-from-files"

これで、$ google_chrome_devと起動するとエラーが出ない状態のChromeが立ち上がります。
JSONを用いたアプリケーションの開発等で役にたつことでしょう。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
10