4
0
Эх сурвалжийг харах

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.
Tali Auster 1 жил өмнө
parent
commit
e02b65d4bc

+ 4 - 4
internal/ui/static/js/app.js

@@ -719,11 +719,11 @@ function isPlayerPlaying(element) {
 /**
 /**
  * handle new share entires and already shared entries
  * handle new share entires and already shared entries
  */
  */
-function handleShare() {
+async function handleShare() {
     const link = document.querySelector(':is(a, button)[data-share-status]');
     const link = document.querySelector(':is(a, button)[data-share-status]');
     const title = document.querySelector(".entry-header > h1 > a");
     const title = document.querySelector(".entry-header > h1 > a");
     if (link.dataset.shareStatus === "shared") {
     if (link.dataset.shareStatus === "shared") {
-        checkShareAPI(title, link.href);
+        await checkShareAPI(title, link.href);
     }
     }
     if (link.dataset.shareStatus === "share") {
     if (link.dataset.shareStatus === "share") {
         const request = new RequestBuilder(link.href);
         const request = new RequestBuilder(link.href);
@@ -738,14 +738,14 @@ function handleShare() {
 /**
 /**
 * wrapper for Web Share API
 * wrapper for Web Share API
 */
 */
-function checkShareAPI(title, url) {
+async function checkShareAPI(title, url) {
     if (!navigator.canShare) {
     if (!navigator.canShare) {
         console.error("Your browser doesn't support the Web Share API.");
         console.error("Your browser doesn't support the Web Share API.");
         window.location = url;
         window.location = url;
         return;
         return;
     }
     }
     try {
     try {
-        navigator.share({
+        await navigator.share({
             title: title ? title.textContent : url,
             title: title ? title.textContent : url,
             url: url
             url: url
         });
         });