summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/badging/resources/setAppBadge_iframe.html
blob: 8738099658fbb2de893658e70242e855ecccd4b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<meta charset="utf-8" />
<title>setAppBadge iframe</title>
<script>
  async function callSetAppBadge() {
    const postMessageData = { message: "callSetAppBadge" };

    try {
      await navigator.setAppBadge();
      postMessageData.status = "success";
    } catch (e) {
      if (e instanceof DOMException) {
        postMessageData.status = "error";
        postMessageData.exceptionType = e.name;
      } else {
        postMessageData.status = "unknown_error";
        postMessageData.error = e.toString();
      }
    } finally {
      window.parent.postMessage(postMessageData, "*");
    }
  }

  window.addEventListener("message", async (event) => {
    switch (event.data) {
      case "callSetAppBadge":
        await callSetAppBadge();
        break;
      default:
        throw new Error(`Unexpected message: ${event.data}`);
    }
  });
</script>