I have webapp which uses a service worker that detects, when the network is offline, and serves a cached offline page.
I have a case where:
- the program is started, while the network is connected, and loads the url https://localhost/my_site
- the user pushes a button which triggers a fetch call
- during that time, the network is disconnected,
- the service worker detects this state and returns a cached offline page
- the javascript code checks the response content type, finds that it is text/html (instead of the original response that was supposed to be e.g. application/json)
- the javascript code renders the offline page (by setting "window.location.href = response.url"). The offline url is https://localhost/static/offline/offline.html
- at this point, the address bar of the sites shows the offline url.
I expect that the user then will refresh the page (e.g. by pressing F5), to reload the original content, once the network is re-connected.
But because the address bar now shows the offline url, refreshing the page will just reload the offline page again and again.
How can the user get back to the original url: https://localhost/my_site ?
Thanks,
Avner
EDIT:
Why not just serve the offline page from the service worker as localhost/my_site
This can happen from various pages. How would you programatically change the response.url?
I tried using the solution based on here.
When the fetch returns, I check the response type.
If it is text/html I load the new page from the response, and then
use:
window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", queryUrl1);
to set the url, but it only changes the url in the history, not in the currently presented url...