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).
Guenter

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

All worked fine with the project described above … with Ubuntu and also on Android devices. For whatever reason, I try to change to an iPhone and … I’m running into some (iOS specific?) problems:

  • FX – which I use for decades and are kneen to use it also on iPhone – can’t be used as the primary browser (will be available with IOS14?). Possible already with current iOS 13.x?
  • My HTML file should be started with a button on the home screen. Is there any possibility to create a shortcut/home page button?
  • A click on an HTML file in the ‘Dateien’ folder opens on Safari, but obviously there is an error. No change to get the details for it … how to debug it (on other platforms there is no problem with HTML file)?

There is word that iOS14 will allow you to change your default browser, but the browser internals will still be webkit/Safari. All 3rd party browsers in iOS are really just WebView-like elements powered by webkit.

For having your HTML file on the home screen, that functionality has existed for some time. This article goes into more detail: https://www.macrumors.com/how-to/add-a-web-link-to-home-screen-iphone-ipad/

For debugging iOS Safari, you can use Web Inspector. This article can help: https://www.kenst.com/2019/03/how-to-debug-problems-on-mobile-safari/

:slight_smile:

OK, with the first link it works … didn’t found the “Add to home page” before. :face_with_monocle:
The second page describes well how to establish a development setup between iPhone and Mac. And debugging the python/bottle works :smile:
No chance to debug the html/js/css file which I open on iPhone File Mngr :crazy_face:. It seems to render, is it on Safari?


Anyway there is no possibility to get the connection between iPhone and Mac for debugging this “file” :frowning_face:
(Note: The file opens fine on other devices with LX, Android)