Difference between revisions of "Troubleshooting/Local Files"

From Jmol
Jump to navigation Jump to search
(using local files in browsers)
(update and expand explanation of browser security restrictions and possible solutions)
Line 1: Line 1:
 
= Accessing J(S)mol-containing webpages in local disk, or loading models from local files =
 
= Accessing J(S)mol-containing webpages in local disk, or loading models from local files =
  
== Symptoms ==
+
== JSmol does not load when the web page is in a local disk ==
When trying to load a page, some of these error warnings are shown in an alert box:
 
  
[[File:Local file error.png|border|center]]
+
Security policies of web browsers prevent some JavaScript being executed from local disk.
 +
If you feel confident to override this security measures (e.g. for pages you have authored), read below.
  
== MacOS ==
+
Another solution is that the page is local, but the JSmol files are in a web server. Then, no security restrictions apply.
  
=== Safari ===
+
=== Symptoms ===
 +
When trying to load a page, some of these error warnings are shown in an alert box:
 +
[[File:Local file error.png|border|center]]
  
'''Symptom''': trying to load an html file with JSmol/Java in Safari. The applet tries to load but then fails.  
+
=== MacOS ===
 +
==== Safari ====
 +
'''Symptom''': trying to load an html file in Safari, JSmol fails to load.  
  
 
'''Solution''': Safari > Preferences > Advanced > check the <code>Show Develop menu in menu bar</code> option.
 
'''Solution''': Safari > Preferences > Advanced > check the <code>Show Develop menu in menu bar</code> option.
 
<br>In the resulting Develop toolbar drop-down, check the <code>Disable Local File Restrictions</code> option.
 
<br>In the resulting Develop toolbar drop-down, check the <code>Disable Local File Restrictions</code> option.
  
'''Caveat''': when models in binary-format files are to be loaded, Safari may fail in any case for local files.
+
==== Chrome ====
 
 
=== Chrome ===
 
 
A command entered in the terminal allows to start up MacOS Chrome so that JSmol runs from local files:
 
A command entered in the terminal allows to start up MacOS Chrome so that JSmol runs from local files:
 
  open /Applications/Google\ Chrome.app --args --allow-file-access-from-files
 
  open /Applications/Google\ Chrome.app --args --allow-file-access-from-files
Line 23: Line 25:
  
 
There is possibly a way to [[Troubleshooting/Local_Files/MacChromeAutomator|write an AppleScript]] to do this in one fell swoop.
 
There is possibly a way to [[Troubleshooting/Local_Files/MacChromeAutomator|write an AppleScript]] to do this in one fell swoop.
 +
 +
=== Windows ===
 +
==== Firefox ====
 +
To override the security, enter <code>about:config</code> in the url address slot and then try setting as '''<code>false</code>''' this:
 +
security.fileuri.strict_origin_policy
 +
 +
==== Chrome ====
 +
To override the security, close all instances of the browser and then try starting it (from a command line or a shortcut) with one of these options:
 +
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files
 +
 +
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="C:\Users\my-user-name\Documents"
 +
...or specifying as <code>user-data-dir</code> whatever location you have your html, JSmol and molecular files in your local disk.
 +
 +
==== Edge ====
 +
Restrictions in Edge would be similar to that in Chrome. However, there seems to be no way to override the security.
 +
 +
 +
== JSmol loads, but cannot load files from a local disk ==
 +
 +
=== MacOS ===
 +
==== Safari ====
 +
'''Solution''': Probably it is enough to apply the configuration explained above.
 +
 +
'''Caveat''': when models in binary-format files are to be loaded, Safari may fail in any case for local files.
  
 
== Windows ==
 
== Windows ==
 
 
=== Firefox ===
 
=== Firefox ===
 
You will be able to read both binary and text files locally. Please enter <code>about:config</code> in the url address slot and then try setting as '''<code>false</code>''' one of these:
 
You will be able to read both binary and text files locally. Please enter <code>about:config</code> in the url address slot and then try setting as '''<code>false</code>''' one of these:
Line 40: Line 65:
 
   .bin .gz .jmol .jpg .map .mrc .omap .png .pse .smol .spartan .zip
 
   .bin .gz .jmol .jpg .map .mrc .omap .png .pse .smol .spartan .zip
 
This does not apply to files drag-dropped onto the Jmol object or files loaded using "?", which use the HTML5 FileReader object. That method reads binary files without a problem.
 
This does not apply to files drag-dropped onto the Jmol object or files loaded using "?", which use the HTML5 FileReader object. That method reads binary files without a problem.
 
=== MSIE ===
 
''Note: nowadays, you should avoid using MSIE for pages with JSmol. Its performance is much poorer and compatibility with some features is limited.''
 
 
The same limitations apply regarding local '''binary''' files as those explained above for Chrome.
 

Revision as of 12:44, 8 February 2025

Accessing J(S)mol-containing webpages in local disk, or loading models from local files

JSmol does not load when the web page is in a local disk

Security policies of web browsers prevent some JavaScript being executed from local disk. If you feel confident to override this security measures (e.g. for pages you have authored), read below.

Another solution is that the page is local, but the JSmol files are in a web server. Then, no security restrictions apply.

Symptoms

When trying to load a page, some of these error warnings are shown in an alert box:

Local file error.png

MacOS

Safari

Symptom: trying to load an html file in Safari, JSmol fails to load.

Solution: Safari > Preferences > Advanced > check the Show Develop menu in menu bar option.
In the resulting Develop toolbar drop-down, check the Disable Local File Restrictions option.

Chrome

A command entered in the terminal allows to start up MacOS Chrome so that JSmol runs from local files:

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

(Make sure an instance of Chrome is not active when you issue that command.)

There is possibly a way to write an AppleScript to do this in one fell swoop.

Windows

Firefox

To override the security, enter about:config in the url address slot and then try setting as false this:

security.fileuri.strict_origin_policy

Chrome

To override the security, close all instances of the browser and then try starting it (from a command line or a shortcut) with one of these options:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="C:\Users\my-user-name\Documents"

...or specifying as user-data-dir whatever location you have your html, JSmol and molecular files in your local disk.

Edge

Restrictions in Edge would be similar to that in Chrome. However, there seems to be no way to override the security.


JSmol loads, but cannot load files from a local disk

MacOS

Safari

Solution: Probably it is enough to apply the configuration explained above.

Caveat: when models in binary-format files are to be loaded, Safari may fail in any case for local files.

Windows

Firefox

You will be able to read both binary and text files locally. Please enter about:config in the url address slot and then try setting as false one of these:

security.fileuri.strict_origin_policy

Chrome

If you need to open local files, first close all instances of Chrome and then try starting Chrome (from a command line or a shortcut) with one of these options:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="C:\Users\my-user-name\Documents"

...or specifying as user-data-dir wherever you have your html, JSmol and molecular files in your local disk.

It is not possible to load local binary files into JSmol/HTML5 from standard script commands. That is, no direct file reading with any of the following in their names:

 .bin .gz .jmol .jpg .map .mrc .omap .png .pse .smol .spartan .zip

This does not apply to files drag-dropped onto the Jmol object or files loaded using "?", which use the HTML5 FileReader object. That method reads binary files without a problem.

Contributors

AngelHerraez