From 9fa24b914c1d83e4ead652048e82876f3570318c Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Mon, 29 May 2023 13:02:03 -0700 Subject: [PATCH] Catch when path is not in metadata Happens when static assets are loaded on homepage --- script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.js b/script.js index c9bcb62..e4a95f1 100644 --- a/script.js +++ b/script.js @@ -13,7 +13,7 @@ const cacheChannel = new BroadcastChannel('cache'); cacheChannel.addEventListener('message', e => { const resourceUrl = new URL(e.data.resource); const isApiRequest = resourceUrl.pathname === '/api'; - const isCurrentPage = resourceUrl.search.split('/').pop() === metadata.get(window.location.pathname).id; + const isCurrentPage = resourceUrl.search.split('/').pop() === metadata.get(window.location.pathname)?.id; // Only show toast if: // - Non-static asset (static assets logo.svg, style.css, script.js, etc. are not managed by service worker) // - The relevant page is open (if the user has multiple tabs open, do not show the toast on unrelated pages) -- 2.47.3