Request session info from sw if missing (#2664)

* request session info from sw if missing

* fix async session request in fetch

* respond fetch synchronously and add early check for non media requests  (#2670)

* make sure we call respondWith synchronously

* simplify isMediaRequest in sw

* improve naming in sw

* get back baseUrl check into validMediaRequest

* pass original request into fetch in sw

* extract mediaPath util and performs checks properly

---------

Co-authored-by: mmmykhailo <35040944+mmmykhailo@users.noreply.github.com>
This commit is contained in:
Ajay Bura
2026-02-21 12:21:27 +05:30
committed by GitHub
parent 29ec172c8b
commit 170f5cd473
3 changed files with 105 additions and 36 deletions

View File

@@ -34,17 +34,14 @@ if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(swUrl).then(sendSessionToSW);
navigator.serviceWorker.ready.then(sendSessionToSW);
window.addEventListener('load', sendSessionToSW);
// When returning from background
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
navigator.serviceWorker.addEventListener('message', (ev) => {
const { type } = ev.data ?? {};
if (type === 'requestSession') {
sendSessionToSW();
}
});
// When restored from bfcache (important on iOS)
window.addEventListener('pageshow', sendSessionToSW);
}
const mountApp = () => {