Просмотр исходного кода

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 год назад
Родитель
Сommit
e02b65d4bc
1 измененных файлов с 4 добавлено и 4 удалено
  1. 4 4
      internal/ui/static/js/app.js

+ 4 - 4
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
         });