bookmarks icon indicating copy to clipboard operation
bookmarks copied to clipboard

Implement installing as webAPK?

Open szaimen opened this issue 4 years ago • 23 comments

With v3.2.0 released you can now install the nextcloud bookmarks web app as a progressive web app on your android or iOS phone.

Thank you very much for implementing this feature. It is working great!

Would it be possible to feature the installment as "WebAPK"? This would allow the PWA to become much more independent from the Browser and some other advantages.

Here are the docs: https://developers.google.com/web/fundamentals/integration/webapks

Being installed via an APK makes it possible for your app to show up in the app launcher, in Android's app settings and to register a set of intent filters.

Originally posted by @szaimen in https://github.com/nextcloud/bookmarks/issues/1051#issuecomment-643833023

szaimen avatar Jun 15 '20 22:06 szaimen

Hello @szaimen

I didn't know about WebAPKs. According to the article you linked this should be done automatically when installing the PWA in chrome.

marcelklehr avatar Jun 16 '20 09:06 marcelklehr

Hi @marcelklehr unfortunately installing as WebAPK currently doesn't work automatically. I've inspected the bookmarks app with "Google Chrome Lighthouse" and found those issues. I think the one that prevents installing is "Does not register a service worker that controls page and start_url" Here is the corresponding "Learn more" link: https://web.dev/service-worker/?utm_source=lighthouse&utm_medium=devtools image

szaimen avatar Jun 16 '20 10:06 szaimen

@marcelklehr I am not sure but it could be problematic that there isn't a scope attribute defined inside the manifest; maybe this is the problem here. https://web.dev/add-manifest/#scope https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/audits/service-worker.js

szaimen avatar Jun 16 '20 10:06 szaimen

Here are some additional docs to compare the start_url and scope attributes. https://developer.mozilla.org/en-US/docs/Web/Manifest/start_url https://developer.mozilla.org/en-US/docs/Web/Manifest/scope

szaimen avatar Jun 16 '20 10:06 szaimen

I am not sure but adding the following line: 'scope' => $this->urlGenerator->linkToRouteAbsolute('bookmarks.web_view.index'), to the manifest function: https://github.com/nextcloud/bookmarks/blob/master/lib/Controller/WebViewController.php#L155 Might solve the problem.

Edit: I've tried adding that line to my productive instance and cleared the cache on android mobile chrome but it still doesn't work and still the same report by Lighthouse :/

szaimen avatar Jun 16 '20 10:06 szaimen

BTW: I get those errors in the console: image and this message in the "installable" section: image Maybe it is related?

szaimen avatar Jun 18 '20 09:06 szaimen

BTW: I get those errors in the console: image and this message in the "installable" section: image Maybe it is related?

After testing a bit further, I think that this is the main reason why it doesnt show up as beeing installable. @marcelklehr Do you have an idea why it fails to install the service worker? Maybe it is because the script isn't actually existing?

szaimen avatar Jul 07 '20 00:07 szaimen

@marcelklehr Does the service-worker work on your installation? (No issue while registering the serviceworker -> listed as installable on Google Chrome Lighthouse.)

Here, you can find a working service-worker: https://github.com/lindnerju/ePaeko/blob/master/service-worker.js

with the following webmanifest: https://github.com/lindnerju/ePaeko/blob/master/manifest.webmanifest

The service-worker is called by: https://github.com/lindnerju/ePaeko/blob/master/index.html#L38-L42

It might help you fix the service-worker. I am unfortunately not able to fix it myself since I am not a developer and have no dev setup for Nextcloud. The changes that I made to the productive instance seem to make no difference.

szaimen avatar Jul 12 '20 21:07 szaimen

Mmmh, installation works with firefox but not with Chromium :/

Update: But that's only with my self-signed dev cert. On my prod server it works even in chrome.

marcelklehr avatar Jul 19 '20 15:07 marcelklehr

Mmmh, installation works with firefox but not with Chromium :/

Do you have the same error message there?

TypeError: failed to register a service worker for scope ... with script ... A bad http response was received when fetching the script


Update: But that's only with my self-signed dev cert. On my prod server it works even in chrome.

Are you using a lets encrypt certificate on your prod server? If not, maybe it is a problem with lets encrypt certificates (which I am using).

Could you please have a look if you are seeing any Errors in the browser console when navigating to the bookmarks app on your prod server? This could help to debug the issue.

szaimen avatar Jul 19 '20 18:07 szaimen

Do you have the same error message there?

Nope, on my dev setup i get two different errors. One is about the TLS cert and the other about a CSP rule that forbids loading of the script.

On my prod server I'm using let's encrypt yep. In the console I get ServiceWorker registered so things look good there.

I notice you're using mod_rewrite, though. Maybe there's something going wrong there, causing it to 404. On my server the URL is index.php/apps/bookmarks/ while it looks for /apps/bookmarks/ on your server.

marcelklehr avatar Jul 20 '20 08:07 marcelklehr

I'm closing this for now, as I cannot replicate your issue so far and there haven't been any updates. Feel free to give me a shout if this is still an issue.

marcelklehr avatar Jan 07 '21 19:01 marcelklehr

Yes, its unfortunately still an issue and it seems like I cannot provide any sensible information on this to make it reproducible for you. The only thing I can mention is, that I am using the Nextcloud VM and activated TLS using the built-in script.

So it should be reproducible following:

  1. install VM-Player or VM-Fusion
  2. Download the image from here and import it into the program
  3. run the initial script and set up Lets encrypt by running the built-in Activate TLS script
  4. install the bookmarks app
  5. now open the bookmarks app and you should see in Chrome that it fails to load the service worker.

szaimen avatar Jan 07 '21 19:01 szaimen

I can't reproduce this, sorry.

marcelklehr avatar Aug 13 '21 13:08 marcelklehr

I still have this problem. Seems like because of some reasons https://myncdomain.com/index.php/apps/bookmarks/service-worker.js works fine but not https://myncdomain.com/apps/bookmarks/service-worker.js. (pretty urls are enabled on my instance so the second link should work nonetheless) So maybe always add index.php to the service worker url here? https://github.com/nextcloud/bookmarks/blob/03c57b377e27cb3dfbab41f6736044d0d384bf89/src/main.js#L37

szaimen avatar Aug 23 '21 13:08 szaimen

generateUrl already infers, whether it should use index.php. Can you post your htaccess/nginx config?

marcelklehr avatar Aug 23 '21 14:08 marcelklehr

Ah okay... I don't use nginx but apache and the default nextcloud .htaccess config. You find the apache config here: https://github.com/nextcloud/vm/blob/219e21d3b303f27c3a08d48f605e391e5724b7e7/lets-encrypt/activate-tls.sh#L131-L206

szaimen avatar Aug 23 '21 15:08 szaimen

Does it work on your production instance if you enable pretty urls?

szaimen avatar Aug 23 '21 15:08 szaimen

Does it work on your production instance if you enable pretty urls?

Yes.

marcelklehr avatar Aug 23 '21 15:08 marcelklehr

Maybe it's a nextcloud version thing? I've been successfully using this with nc 20 and 21

marcelklehr avatar Aug 23 '21 15:08 marcelklehr

not sure... but seems to be setup related

szaimen avatar Aug 23 '21 15:08 szaimen

Okay, I think I may have understood the problem now. As far as I know are all js files never routed through the index.php when pretty urls are activated via .htaccess. So In order to make this work, you need to add index.php manually also for these instances. generateUrl doesn't work here because it modifies the url to https://domain.com/apps/bookmarks/service-worker.js. however the file is not lying in that generated directory but only generrated on the fly. So here is one place where index.php needs to be consistantly added even when pretty urls are activated... Not sure how to work around this though. Any idea @marcelklehr?

szaimen avatar Sep 03 '22 18:09 szaimen

found a fix in #1889

szaimen avatar Sep 03 '22 18:09 szaimen