Difference between revisions of "Troubleshooting/Local Files"
AngelHerraez (talk | contribs) (update and expand explanation of browser security restrictions and possible solutions) |
AngelHerraez (talk | contribs) (update and expand explanation of browser security restrictions and possible solutions) |
||
Line 1: | Line 1: | ||
− | = Accessing | + | = Accessing JSmol-containing webpages in local disk, or loading models from local files = |
+ | |||
+ | Security policies of web browsers prevent some JavaScript being executed from local disk (i.e. from a file:// url). | ||
== JSmol does not load when the web page is in a local disk == | == JSmol does not load when the web page is in a local disk == | ||
− | + | Some solutions you may try if you need to do this: | |
− | If you feel confident to override | + | # Install a local web server and use it to access the pages via an http:// url. |
− | + | # If you feel confident to override the 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, | + | # Another solution, in some cases is that the page is local, but the JSmol files are in a web server. Then, less security restrictions apply. |
=== Symptoms === | === Symptoms === | ||
Line 43: | Line 45: | ||
== JSmol loads, but cannot load files from a local disk == | == JSmol loads, but cannot load files from a local disk == | ||
− | Once we managed to authorise loading of JSmol, | + | Once we managed to authorise loading of JSmol, there may still be additional restrictions for loading molecular files from local disk. This may also depend on whether the files are plain text or binary formats. |
+ | * Some plain text formats: <code>.xyz .mol .sdf .pdb .cml .cif</code> | ||
+ | * Some binary formats: <code>.bin .gz .jmol .jpg .map .mrc .omap .png .pse .smol .spartan .zip</code> | ||
+ | |||
+ | This is because binary formats may need to go through a php script* to be loaded, and php cannot be run in local disk. | ||
+ | : (*) That is the {{file|jsmol.php}} file pointed at by <code>Info.serverURL</code> in JSmol initialization. | ||
+ | |||
+ | It is '''not''' possible to load local '''binary''' files into JSmol_HTML5 from standard script commands. | ||
+ | This does not apply to files drag-dropped onto the JSmol panel or files loaded using "?", which use the HTML5 FileReader object. That method reads binary files without a problem. | ||
=== MacOS === | === MacOS === | ||
Line 51: | Line 61: | ||
'''Caveat''': when models in binary-format files are to be loaded, Safari may fail in any case for local files. | '''Caveat''': when models in binary-format files are to be loaded, Safari may fail in any case for local files. | ||
− | == Windows == | + | === Windows === |
− | === Firefox === | + | ==== Firefox ==== |
If you have applied the security override described above, you will be able to read both binary and text files locally. | If you have applied the security override described above, you will be able to read both binary and text files locally. | ||
− | === Chrome === | + | ==== Chrome ==== |
If you have applied the security override described above, .... | If you have applied the security override described above, .... | ||
− | |||
− | |||
− | |||
− |
Latest revision as of 17:06, 8 February 2025
Contents
Accessing JSmol-containing webpages in local disk, or loading models from local files
Security policies of web browsers prevent some JavaScript being executed from local disk (i.e. from a file:// url).
JSmol does not load when the web page is in a local disk
Some solutions you may try if you need to do this:
- Install a local web server and use it to access the pages via an http:// url.
- If you feel confident to override the security measures (e.g. for pages you have authored), read below.
- Another solution, in some cases is that the page is local, but the JSmol files are in a web server. Then, less security restrictions apply.
Symptoms
When trying to load a page, JSmol does not complete loading, or some of these error warnings are shown in an alert box:
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
Close all instances of the browser. Then, 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
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
Once we managed to authorise loading of JSmol, there may still be additional restrictions for loading molecular files from local disk. This may also depend on whether the files are plain text or binary formats.
- Some plain text formats:
.xyz .mol .sdf .pdb .cml .cif
- Some binary formats:
.bin .gz .jmol .jpg .map .mrc .omap .png .pse .smol .spartan .zip
This is because binary formats may need to go through a php script* to be loaded, and php cannot be run in local disk.
It is not possible to load local binary files into JSmol_HTML5 from standard script commands. This does not apply to files drag-dropped onto the JSmol panel or files loaded using "?", which use the HTML5 FileReader object. That method reads binary files without a problem.
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
If you have applied the security override described above, you will be able to read both binary and text files locally.
Chrome
If you have applied the security override described above, ....