From 84723c116487a6b40569a80e71790a972ff2f229 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 10 Jul 2024 17:42:07 +0200 Subject: [PATCH 1/3] Allow notifications and actions to specify a navigable URL This makes notifications more declarative by not requiring explicit handling of the clicks by the web application. This is part of the Declarative Web Push effort: https://github.com/w3c/push-api/issues/360. --- notifications.bs | 74 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/notifications.bs b/notifications.bs index 36bc8f5..73f4ee2 100644 --- a/notifications.bs +++ b/notifications.bs @@ -60,6 +60,9 @@ or "rtl").

A notification has an associated body (a string). +

A notification has an associated navigation URL +(null or a URL). It is initially null. +

A notification has an associated tag (a string).

A notification has an associated data (a @@ -137,6 +140,9 @@ support these features might ignore them.

title
A string. +
navigation URL +
Null or a URL. It is initially null. +
icon URL
Null or a URL. It is initially null. @@ -220,6 +226,11 @@ important information through, e.g., loss of color or clipped corners.
  • Set notification's body to options["{{NotificationOptions/body}}"]. +

  • If options["{{NotificationOptions/navigate}}"] exists, then + parse it using baseURL, and if that does not return failure, set + notification's navigation URL to the return value. (Otherwise + notification's navigation URL remains null.) +

  • Set notification's tag to options["{{NotificationOptions/tag}}"]. @@ -270,6 +281,11 @@ important information through, e.g., loss of color or clipped corners.

  • Set action's title to entry["{{NotificationAction/title}}"]. +

  • If entry["{{NotificationAction/navigate}}"] exists, then + parse it using baseURL, and if that does not return failure, + set action's navigation URL to the return value. + (Otherwise action's navigation URL remains null.) +

  • If entry["{{NotificationAction/icon}}"] exists, then parse it using baseURL, and if that does not return failure, set action's icon URL to the return value. (Otherwise @@ -541,18 +557,51 @@ interpreted as a language tag. Validity or well-formedness are not enforced. [[! platform supports activation, the user agent must (unless otherwise specified) run these steps:

      +
    1. Let action be null. + +

    2. If one of notification's actions was activated by the end + user, then set action to that action. + +

    3. Let navigationURL be notification's + navigation URL. + +

    4. +

      If action is non-null, then set navigationURL to action's + navigation URL. + +

      This intentionally makes it so that when an action's + navigation URL is null, it falls through to the + click event, providing more flexibility to the web developer. + +

    5. +

      If navigationURL is non-null: + +

        +
      1. If there is an existing top-level traversable traversable within + the user agent's top-level traversable set whose + active document's URL equals + navigationURL with exclude fragments set to true, then + navigate traversable to navigationURL and return. If there are + multiple top-level traversables that satisfy the condition the user agent has to + pick one in an implementation-defined manner. + + +

      2. Create a fresh top-level traversable given navigationURL. + +

      3. Return. +

      +
    6. If notification is a persistent notification, then:

        -
      1. Let action be the empty string. +

      2. Let actionName be the empty string. -

      3. If one of notification's actions was activated by the - user, then set action to that notification action's +

      4. If action is non-null, then set actionName to action's name.

      5. Fire a service worker notification event named "notificationclick" given - notification and action. + notification and actionName.
    7. @@ -643,6 +692,7 @@ interface Notification : EventTarget { readonly attribute NotificationDirection dir; readonly attribute DOMString lang; readonly attribute DOMString body; + readonly attribute USVString navigate; readonly attribute DOMString tag; readonly attribute USVString image; readonly attribute USVString icon; @@ -662,6 +712,7 @@ dictionary NotificationOptions { NotificationDirection dir = "auto"; DOMString lang = ""; DOMString body = ""; + USVString navigate; DOMString tag = ""; USVString image; USVString icon; @@ -690,6 +741,7 @@ enum NotificationDirection { dictionary NotificationAction { required DOMString action; required DOMString title; + USVString navigate; USVString icon; }; @@ -853,6 +905,16 @@ return the maximum number of actions supported.

      The body getter steps are to return this's notification's body. +

      The navigate getter steps are: + +

        +
      1. If this's notification's navigation URL is null, then + return the empty string. + +

      2. Return this's notification's navigation URL, + serialized. +

      +

      The tag getter steps are to return this's notification's tag. @@ -925,6 +987,10 @@ then return null.

    8. Set action["{{NotificationAction/title}}"] to entry's title. +

    9. If entry's navigation URL is non-null, then + set action["{{NotificationAction/navigate}}"] to entry's + navigation URL, serialized. +

    10. If entry's icon URL is non-null, then set action["{{NotificationAction/icon}}"] to entry's icon URL, serialized. From f4c96336d408aeaa70eb1c478b7ae0735218f05a Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 7 Nov 2024 16:08:35 +0100 Subject: [PATCH 2/3] Update notifications.bs --- notifications.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notifications.bs b/notifications.bs index 73f4ee2..f2f5aff 100644 --- a/notifications.bs +++ b/notifications.bs @@ -560,7 +560,7 @@ platform supports activation, the user agent must (unless otherwise specified) r

    11. Let action be null.

    12. If one of notification's actions was activated by the end - user, then set action to that action. + user, then set action to that notification action.

    13. Let navigationURL be notification's navigation URL. @@ -569,7 +569,7 @@ platform supports activation, the user agent must (unless otherwise specified) r

      If action is non-null, then set navigationURL to action's navigation URL. -

      This intentionally makes it so that when an action's +

      This intentionally makes it so that when an notification action's navigation URL is null, it falls through to the click event, providing more flexibility to the web developer. From 296067493a703241852147435377dd6a9bb891f9 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 7 Nov 2024 16:10:48 +0100 Subject: [PATCH 3/3] Update notifications.bs --- notifications.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifications.bs b/notifications.bs index f2f5aff..a0c463f 100644 --- a/notifications.bs +++ b/notifications.bs @@ -569,7 +569,7 @@ platform supports activation, the user agent must (unless otherwise specified) r

      If action is non-null, then set navigationURL to action's navigation URL. -

      This intentionally makes it so that when an notification action's +

      This intentionally makes it so that when a notification action's navigation URL is null, it falls through to the click event, providing more flexibility to the web developer.