Question:
Currently, due to thesecurity policy of chromium , it is impossible to upload local files via ajax without the "–allow-file-access-from-files" argument. But at the moment I need to create a web application where the database is an xml file (at least json) located next to index.html. It is assumed that the user can run this application locally. Are there any workarounds for cross-browser (ie11 +) reading an xml- (json-) file, without wrapping it in a function and renaming it to js format?
UPD
There is a code for IE, but as it turned out, there were no problems with it.
function loadXMLFile(filename) {
return new Promise(function(resolve, reject) {
// Если мы имеем дело с IE, то работает с ActiveX-контентом
if('ActiveXObject' in window) {
// Получение xml-текста из файла для осла
var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xmlDoc.load(filename);
resolve(xmlDoc.xml);
} else {
// Если мы работаем с нормальными браузерами,
// то здесь необходимо как-то получить xml-файл
// ...
//
}
}
}
Answer:
The following options are possible:
-
Browser extension. It works almost like local files (in the sense that the files are static and are located in the file system) – but for accessing resources, it is not the
file:///path/to/file
scheme, but thechrome-extension:///{guid}/path/to/file
. In this scheme, there are no restrictions on access to the resources of your own application. All you need to do is compose the correct manifest and package the application into an archive. Well, and add it to the browser, of course.Here is the full format of the manifest file: https://developer.chrome.com/extensions/manifest
The minimal manifest is like this:
{ "manifest_version": 2, "name": "Мое приложение", "version": "1.0", "default_locale": "ru", "description": "Описание приложения", "icons": { "16": "icon16.png", "48": "icon48.png", "128": "icon128.png" } }
If I haven't messed up anything, such a minimal manifest is enough to simply display static files.
In order to add an application in chrome, you need to publish it in the app store, but for chrome it is not necessary.
-
Local server. There are enough lightweight web servers on the network that do not require installation and that can serve static files at some URL like
http://127.0.0.1:8081/
.Or, on the contrary, you can make an application that requires installation and during this installation itself brings the site to IIS. It is not so difficult to set up a static site, it is more difficult to install IIS itself automatically (this is definitely possible, but I don’t remember how).
-
Built-in browser. If you embed chromium in your application, you can "slip" any files into it according to a non-standard scheme. Or according to the standard one – but having set all the necessary flags.
From ready-made solutions on hearing Electron . Among other features, Electron allows locally stored "client" code to use the entire Node.js API.