HTML page to load ini file -- CORS!?

For a “simple” task I used an HTML page to control some wlan devices. All worked as expected, but recently it failed because the html file at startup was loading an ini file (using XHR). Nowadys CORS stricktly came in and the previous method failed, no surprise.
But looking for a “simple” methode to overcome this limitation failed. Anyone has a good and simple idea?
(if necessary I would post some snippets of the code).

Why did the CORS issue come into effect now as opposed to earlier? Do you have access to the server the ini file is on where you can modify the CORS configuration?

The html files and the ini file are on the same ‘server’ (on the Lx PC or on an Android phone/tablet), and also in the same directory. To start the job, the html is opened from file manager or desktop (which works) with Firefox (68), but loading the ini file prompts with
Quellübergreifende (Cross-Origin) Anfrage blockiert: Die Gleiche-Quelle-Regel verbietet das Lesen der externen Ressource auf file:///home/guenter/MORE/piSchedulePlus/pi/xLicht_X.ini. (Grund: CORS-Anfrage war nicht http).
And compared to earlier setup I only can see the FX version was updated to 68

Are you loading directly from the file system? If so, do you have the ability to run it through a web server?

If it is Firefox related, can you go to about:config, search for “security.fileuri.strict_origin_policy” and disable it?

Yes for loading from file system and no for web server (having in mind to keep it simple).
Yes, changing the pref manually solves it, but I hoped for another solution. Manually changing the prefs needs to be done on each device. Is there a programatic access from the html/js to set it, load the file and reset.
Currently I’m including the ini file in a <script> block, a method which works, but the separation would be better.:frowning_face:

Does it have to be a .ini file? Is there a way for you to store this data in a JS file - even as a giant string using the string literal character:

let foo = `This is a string in code!`;

This way, you can just load your settings via a script tag and not worry about any XHR requests or similar techniques where CORS will come into play.

Absolutely! Yes with defining the required data in a <script> works. See my previous comment.
The idea was to have the html file as a general script/program and a separate config files with for the individual application situation. But the ‘clean’ way seems to be somewhat impossible here.
Thanks for the moment :upside_down_face:

Gotcha. I interpreted your earlier comment as having the contents of the ini loaded inline in your HTML page. What I’m referring to is having a file called config.js that you reference via <script src="config.js"></script>. This is still a separate file, so you can keep the HTML content different from the configuration content which is isolated inside config.js.

Bingo … such easy … many thanks! :laughing: :+1:

1 Like