MAX POWER
MAX POWER

Reputation: 5458

Google Chrome - add to homescreen - force refresh

I have a website with "add to homescreen" enabled - i.e. I have got a manifest.json file with "display": "standalone".

The problem I'm having is when I open the website via the homescreen shortcut, it will resume from when I last accessed it. I have to pull to refresh to make it fetch the latest content.

My question is, is it possible to make it do a refresh every time it is accessed?

Upvotes: 0

Views: 1187

Answers (1)

Jeff Posnick
Jeff Posnick

Reputation: 56144

If you'd like to take specific action inside of your web app whenever it moves from the "background" to the "foreground" again, you could listen for the appropriate events using the Page Lifecycle API.

The most straightforward way of doing this would probably be to listen for visibilitychange events, and programmatically refresh your data source when you detect that the current visibilityState has transitioned to 'visible'.

This could look like:

document.addEventListener('visibilitychange', () => {
  if (document.visibilityState === 'visible') {
    // Your refresh logic goes here.
  }
});

Upvotes: 2

Related Questions