From e02b65d4bc5eee855205026b32ea67b0cdda8abb Mon Sep 17 00:00:00 2001 From: Tali Auster Date: Sun, 30 Mar 2025 20:09:09 -0700 Subject: [PATCH] fix: deal with navigator.share exceptions Navigator.share returns a promise that's executed in the background, but unless we await it explicitly, we won't get the exceptions in the try/catch block. --- internal/ui/static/js/app.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/ui/static/js/app.js b/internal/ui/static/js/app.js index cc818063..f8c4836a 100644 --- a/internal/ui/static/js/app.js +++ b/internal/ui/static/js/app.js @@ -719,11 +719,11 @@ function isPlayerPlaying(element) { /** * handle new share entires and already shared entries */ -function handleShare() { +async function handleShare() { const link = document.querySelector(':is(a, button)[data-share-status]'); const title = document.querySelector(".entry-header > h1 > a"); if (link.dataset.shareStatus === "shared") { - checkShareAPI(title, link.href); + await checkShareAPI(title, link.href); } if (link.dataset.shareStatus === "share") { const request = new RequestBuilder(link.href); @@ -738,14 +738,14 @@ function handleShare() { /** * wrapper for Web Share API */ -function checkShareAPI(title, url) { +async function checkShareAPI(title, url) { if (!navigator.canShare) { console.error("Your browser doesn't support the Web Share API."); window.location = url; return; } try { - navigator.share({ + await navigator.share({ title: title ? title.textContent : url, url: url });