TLDR: App uses webview to load page from file. Serviceworkers only work via http. Searching for a solution to get serviceworkers running. Preferably not by compiling my own webserver into the app.
The problem is, that serviceworkers are not allowed when the page is served via the file: protocol.
An app for ubuntu touch solved this by spinning up a small http server which serves the file locally.
For an ecosystem however it does not sound nice, when every other app brings their own webserver just to solve this problem. Imagine there is a critical security issue with this server and every application that ships it to solve a common problem needs to be patched… That would result in more app nightmares that we already have with outdated apps.
The next question would be, if that is actually allowed in the store.
Does anyone have ideas to do that better? Either circumvent the local webserver entirely, or a solution provided by the platform.
Followup question: if I am shipping my own webserver, what do I need to look for? Its basically only serving once files at app startup, so I’d want something which is not eating resources afterwards.
Yeah, we’ve discussed the communication between QML and the JS interpreter as well.
I think a very minimal web server is not actually an issue if only one request needs to be served. It could be launched and shut down immediately, or? And as @nephros suggests, you could use the python3
In that case, the system updates to python3 should have you covered where security is a concern, I would have a look to see if you can simply discard post/get input and if so, do that to stay safe?
EDIT: I do much more evil stuff with python in, for instance, Videoworks. I pass a filehandle to ffmpeg via python system calls and collect data dynamically (frames, meta data) … passing it back to QML.
So, I’m building a demo on the side. It’s not quite as simple as starting the server A background thread is required. I’ll post a repo link when it’s working properly.
EDIT! After measuring out the roof of the shed, moving some rocks about, staring at sagging foundations, it started to hail. soooo…
There’s one catch, I haven’t figured how/if I can set the SimpleHTTPRequestHandler path properly. So I just shoved the index.html and framescript.js files into ~/
It works. The Server sits in a thread which seems to be cleaned up properly when the app exits.
Ah, I was being lazy and avoiding implementing the class. I couldn’t find a fast and dirty method to initialize the post 3.7 python Handler. So, the simple version would be something like:
class Handler(http.server.SimpleHTTPRequestHandler):
directory = "~/.config/orgname/appname/"
? And then copy the index (etc) there on install? I modified the example to keep the javascript in the application qml, since that works without issue and seemed safer.
It does, serviceworker seems to work now, but I messed it up somehow and can’t clean the caches apperantly…
Removing the applications .cache directory does not seem to help.
(currently trying to proof, that its not an issue of the app)