From: Ardis Lu Date: Mon, 29 May 2023 20:02:03 +0000 (-0700) Subject: Catch when path is not in metadata X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=9fa24b914c1d83e4ead652048e82876f3570318c;p=ardislu.dev Catch when path is not in metadata Happens when static assets are loaded on homepage --- 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)