-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a workaround to enable ServiceWorker mode in Firefox Extension #764
Comments
A prerequisite for this is to decide where to serve the https: version from. The obvious place would be https://kiwix.github.io/kiwix-js , because we already keep that synchronized with our releases, so there would be no scope for the codebases to desynchronize. However, do all Mozilla users (I'm thinking of one in particular!) trust GitHub enough to use this? Would we be better off leveraging a docker container, like I do for https://pwa.kiwix.org ? It would probably need to be a different container, since the codebases are different,, so maybe https://pwa.kiwixjs.org ? But that would be more work than just using our existing implementation. |
We have to think about which lifecycle we want to have for this PWA version Regarding the URL, we don't seem to own kiwixjs.org domain name, it's probably better to stick with kiwix.org. Another approach would be something like https://pwa-kiwix-js.kiwix.org/3.2.0/ but it would need to handle another SSL certificate (except if we have a wildcard one?) @kelson42 : what would you prefer/advise? The most important is that whatever URL we choose, it will be hardcoded in the extensions, so we won't be able to change it afterwards. It might be possible to deploy all versions on github instead. I tend to prefer kiwix.org (more flexible, and trusted), OTOH some countries might block access to kiwix.org domain name, where it might be more difficult for them to block github.com without impacting their companies business. |
@mossroy That's an interesting idea, to have frozen versions. It would certainly be possible to do that with kiwix.github.io/kiwix-js/ (we simply create the appropriate directories and copy the files in). https://pwa.kiwix.org isn't hard-coded in development code, but it is hard coded in prior versions of the software. I have a parameter in The main issue I see is that we can't easily have two repos re-building the same docker container. It could create confusion rebuilding it at the wrong time, since a rebuild would have to include data from both repos (I'm not even sure if that can work). IMHO it would be easier and cleaner to have a separate docker container for kiwix-js. How about using https://kiwixjs.kiwix.org instead? I don't think it has to be advertised as a PWA, as it will only be used (at least currently) in the Mozilla extension. If later we converge the two code-bases (that would be quite difficult now!), we could produce a unified PWA at https://pwa.kiwix.org. Let's see what @kelson42 advises about naming. |
Another possible name, a bit cryptic, is https://js.kiwix.org . But it's also an interesting point that https://kiwix.github.io is a bit harder to block. |
Other possibilities: https://app.kiwix.org or https://webapp.kiwix.org. |
@kelson42 Any views on this issue? To summarize, to enable Service Worker mode in the Firefox Extension, we need to serve the app from a secure server (https://) at least one time, so that the Service Worker can cache the app's own code securely. Thereafter the app will work offline in SW mode, but will auto-update (from the same server) if the code is changed and it is online. In practice we might freeze the app version, so it will not update this way, but we can't stop it checking the server when online. (It will always be possible for the user to switch back to (or stay with) 100% local code if they do not want this, but with loss of features.) The issue is where to serve the app from. There are various possibilities:
Can you help us decide? |
@kelson42 Did you have any advice for us, or do you want us to decide? See my summary in the comment above this one. There are pros and cons which you will know more about than we do. |
Thank you for your patience and sorry for the lack on feedback of my side here. What I miss is a description of the following things available at:
Does all of this comes from the same repo? For my (little) level of understanding, all of this should be basically the same!? |
@kelson42 Here are the descriptions:
Really, we would just like you to say from the Kiwix perspective, what would be the preferred URL for the Extension to access (when switched to Service Worker mode): 1. https://kiwix.github.io/v3.2/ or 2. https://js.kiwix.org/v3.2/ (or another similar name in the |
IMO publishing on Github.io might be the best solution... but not sure how you could elegantly solve the versioning issue. |
Thank you @kelson42. We have full control over subdirectories of https://kiwix.github.io/kiwix-js/, so versioning shouldn't be problematic I think. We just replicate the required code from master into a subdirectory during the release and testing phase, and everything should run relative to that subdirectory. We would end up with (eventually) a number of old versions, but perhaps they could be deleted after a set number of cycles. |
@mossroy Maybe we can weigh up, when we next meet, the pros and cons of freezing the code version vs allowing the Service Worker to update the cached code when there is a new release (and the client is online). Since the Firefox extension auto-updates anyway (like a PWA) maybe the added complexity of versioning is unnecessary: we will never update the gh-pages version without releasing a new extension version, and the local vs online codebases run independently of each other (apart from the local code bootstrapping to the [cached] SW code and vice versa). Anyway, hopefully we can talk about this. There are advantages and disadvantages. EDIT: Here is the code we need to implement (in the Service Worker) for the offline-first and self-updating logic: https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Offline_Service_workers The key to self-updating is to ensure a hard-coded version number is added to the Service Worker's javascript (this will also be used to set the Cache version, and delete obsolete versions of the Cache). As long as there is a byte-difference between the currently running Service Worker and the online Service Worker, the SW will update itself in the background, re-cache all the files it needs for offline use, and will wait until the user restarts the browser or tab before taking over. |
@Jaifroid : sure, we can discuss this when we meet. |
After #771 we'll need to implement the following:
Once the above are complete, we may be able to implement #196, though I think we should probably have a bedding-in period with the SW mode available as an option in the extension before considering how and whether to make it the default (it is somewhat complicated for the Mozilla extension, because it involves the user giving permission to access the remote server). |
This issue is complete. For next steps see #196. |
This is an explanation form #727 of what this would look like:
@mossroy I think I have a workaround for Firefox Extension users that allows them to access the Service Worker mode. I've done a bit of experimenting today which confirms that:
This means that I believe it would be feasible to adopt the same solution I've adopted with the UWP app, viz.:
Below are some screenshots of how this works in the UWP app. I think it is a feasible model for Firefox Extensions. It would require #388 to be completed first. It is a workaround rathet than a solution, but one that is perfectly viable.
SWITCHING FROM JQUERY TO SW MODE:
SWITCHING BACK FROM SW MODE TO JQUERY MODE:
To be clear, apart from some controlling code (in
backgroundscript.js
) that detects the mode of operation and opens the appropriate tab, what this workaround would do is to act as a glorified bookmark to the PWA version. The clever work is done by the Service Worker and the Cache API, not by the extension itself. But for the user, this makes little difference other than that they will notice an https:// address in their browser instead of a moz-extension: address. Above all, this workaround is confirmed to work fully offline once the app has cached its code.Originally posted by @Jaifroid in #727 (comment)
The text was updated successfully, but these errors were encountered: