16
votes

There are some HTML files (no pattern that I've figured out) that I can't open via the terminal, GUI or right clicking Open in Browser via Sublime Text 3.

The default browser to open the file is definitely set to Chrome. When I say to open the file in the browser it takes me to the Chrome window, but doesn't actually open the file I want.

I can open these files in Chrome itself via command + O and in Firefox or Safari by right clicking on the file and selecting them in the GUI.

It'd be great if Chrome would open files when I expect it to. I'd appreciate any help.

7

7 Answers

14
votes

I had the same problem. Fixed it by running this in the terminal after closing Chrome:

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

The command line args can be viewed in Chrome by visiting chrome://version/

Chrome didn't load local files for me before running this command, but for some reason Chrome Canary did.

12
votes

On your mac, right click the file and choose 'Open with' and then choose 'other'. Change the default to 'Safari' and then check the 'Always Open With' box. Click open. This should launch the file in Safari. Close the file in the browser and verify that double-clicking it will open it in Safari. Now do the same thing again except change the default back to Chrome.

You may have some security issue if you downloaded the *.html file from somewhere else.

3
votes

it's a problem of extend attributes. If you use ls -l to see the attributes of your file, you will see some weird @ .

ls -l xxxx.html -rwxr-xr-x@

the solution is to use xattr.

xattr -c filename xattr -rc directory

3
votes

None of the previous answers worked for me, but this one did:

  1. On your Mac, choose Apple menu >> System Preferences >> click Security & Privacy >> click Privacy.
  2. Select Files and Folders.
  3. Please select the checkbox below the Nicepage application to access files and folders in that location.

Source: https://nicepage.com/doc/84207/access-denied-for-documents-folder-macos

Good luck, lads

1
votes

The solution provided by Xiaoou Wang works.

Explanation

I would like to extend this answer and provide below a different solution, which was not given yet.

Chrome (Mac) indeed does not open .html files that have the extended attribute com.apple.quarantine. This attribute is automatically applied on files that are downloaded from the web and are not Apple-authorized applications.

From the terminal, by typing

xattr 'your .html file name'

you can verify whether your .html file has the quarantine attribute set.

With xattr -c command you will remove all attributes, in case there are others set. If you want to only remove the quarantine attribute, type instead

xattr -d com.apple.quarantine 'your .html file name'

Alternative solution

This alternative solution might be even simpler for some people. With my Chrome (mac) I can open .html files by simply dragging the file from finder onto an already opened Chrome window, in spite of their com.apple.quarantine attribute. Important: It does not work if you drag the file onto Chrome's icon in the dock.

0
votes

There might be an issue with your permissions settings. I tried everything and this is worked for me:

Open your Google Chrome Browser: click Chrome, open Preferences, click Privacy and Security, click Advanced (at the bottom), scroll down to "Downloads", under Location click the Change button. Then choose where the file you are attempting to open is saved.

-1
votes

you can open this html file and try "command + option + I" to see the file content in the console window, if it's real html file there will be source code reveal. i don't think it can be the chrome's problem.