How to Set the –allow-file-access-from-files Flag Option in Chrome on Different OS.

The problem you encounter when developing and testing your applications

Ever found yourself needing help when you’re trying to run tests on your local machine, only to find that the browser blocks access? Don’t worry! This is because browsers have security restrictions against running files like an HTML files or JavaScript from local files. Fortunately, this can be bypassed by enabling an access flag – and it’s different for each operating system.

The unique flag in question is the allow-file-access-from-files flag.

In browsers like Firefox, this is a simple switch from True to false’ however in Chrome, it’s a little more cumbersome. The request by programmers for this to be an option in the preferences page for each browser goes back as far as 2011, sadly this has not happened and this is still the most reasonable, workable solution.

There are a couple of ways to do it.

  1. You can set it up temporarily each time you launch Chrome by adding it to a copy of the existing chrome launcher
  2. Or via the command line by simply getting the URL of your Chrome installation path and launching from there.

Then you can check if it’s running by viewing the flags that Chrome is currently using. Simply type chrome://version the chrome address bar.

Simply switching this on with enable your local file to load as needed.

Read on to learn how to do this on different operating systems.

Local files & Google Chrome Browser

The Solution On Each Operating System

windows logo

Enable on Windows OS 

On a Windows OS, you can enable the –allow-file-access-from-files option simply by running Google Chrome from the command line. Open the command line window, type in the appropriate command, and you’ll be good. 

linux logo

Enable on Linux OS 

On a Linux OS, you can enable the –allow-file-access-from-files option by editing the Google Chrome configuration file. All you have to do is open the configuration file, add the appropriate command and that’s it.

mac os logo

Enable on Mac OS 

For Mac users, you can enable the –allow-file-access-from-files option by editing the Google Chrome configuration file. All you have to do is open the configuration file, add the appropriate command, save the file, and you’re good to go.

Are there other ways to access local files in the browser?

While enabling the allow-file-access-from-files flag option is one way to do this, there are other methods as well. Read more about those other options that lean towards setting up a local server of some type. While this may feel like an overkill, there are many some really simple local server methods that you can have running in minutes. We’ll explore some of these additional ways and discuss why they may be more suitable for certain types of projects. 

Frequently Asked Questions

Q: I’ve tried this and it’s still not working.

A: After making sure you’ve followed each step carefully, make sure you have closed all already-open instances of Chrome for the allow-file-access-from-files flag to register before starting chrome.