From 4c2a0b57cec0a502c87db40afa47bfa96c84cc3d Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 7 Jan 2025 09:56:30 +0000 Subject: [PATCH 1/4] Add `NavigateEvent.sourceElement` The `sourceElement` of the `navigate` event is either the clicked link, the submitter button, or the submitted form if there was no submitter button. See https://github.com/WICG/navigation-api?tab=readme-ov-file#navigation-monitoring-and-interception --- source | 64 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/source b/source index 5eeed7af23a..6574eb5ba0e 100644 --- a/source +++ b/source @@ -25639,8 +25639,9 @@ document.body.appendChild(wbr);
  • Navigate targetNavigable to urlString using subject's node document, with referrerPolicy set to referrerPolicy and userInvolvement set to userInvolvement.

    + data-x="navigation-referrer-policy">referrerPolicy set to referrerPolicy, userInvolvement set to userInvolvement, + and sourceElement set to subject.

    Unlike many other types of navigations, following hyperlinks does not have special "replace" behavior for when @@ -25720,7 +25721,8 @@ document.body.appendChild(wbr); navigation with destinationURL set to urlString, userInvolvement set to - userInvolvement, and filename set to + userInvolvement, sourceElement + set to subject, and filename set to filename.

  • If continue is false, then return.

  • @@ -60147,6 +60149,7 @@ fur using the form element's node document, with historyHandling set to historyHandling, userInvolvement set to userInvolvement, + sourceElement set to submitter, referrerPolicy set to referrerPolicy, documentResource set to postResource, and formDataEntryList set to entry @@ -94869,6 +94872,7 @@ interface NavigateEvent : Event { readonly attribute DOMString? downloadRequest; readonly attribute any info; readonly attribute boolean hasUAVisualTransition; + readonly attribute Element? sourceElement; undefined intercept(optional NavigationInterceptOptions options = {}); undefined scroll(); @@ -94999,6 +95003,11 @@ callback NavigationInterceptHandler = event.sourceElement +

    Returns the Element responsible for this navigation, be it an a + element that was clicked, a Submit Button, or a + submitted form.

    +
    event.intercept({ handler, focusReset, scroll })

    Intercepts this navigation, preventing its normal handling and instead converting it into a @@ -95103,9 +95112,11 @@ callback NavigationInterceptHandler = formData, downloadRequest, info, and info, hasUAVisualTransition attributes + data-x="dom-NavigateEvent-hasUAVisualTransition">hasUAVisualTransition, and + sourceElement attributes must return the values they are initialized to.

    The NavigationDestination {

  • Return the result of performing the inner navigate event firing algorithm given navigation, "traverse", - event, destination, userInvolvement, null, and null.

  • + event, destination, userInvolvement, null, null, and + null.

    To fire a push/replace/reload navigate event at @@ -95428,7 +95440,9 @@ interface NavigationDestination { data-x="fire-navigate-prr-isSameDocument">isSameDocument, an optional user navigation involvement userInvolvement (default "none"), an optional entry list-or-null none"), an optional Element-or-null sourceElement (default null), an + optional entry list-or-null formDataEntryList (default null), an optional serialized state navigationAPIState (default @@ -95466,14 +95480,17 @@ interface NavigationDestination {

  • Return the result of performing the inner navigate event firing algorithm given navigation, navigationType, event, destination, - userInvolvement, formDataEntryList, and null.

  • + userInvolvement, sourceElement, formDataEntryList, and + null.

    To fire a download request navigate event at a Navigation navigation given a URL destinationURL, a user navigation involvement userInvolvement, and a string + data-x="fire-navigate-download-userInvolvement">userInvolvement, an + Element-or-null sourceElement, and a string filename:

      @@ -95505,15 +95522,17 @@ interface NavigationDestination {
    1. Return the result of performing the inner navigate event firing algorithm given navigation, "push", event, - destination, userInvolvement, null, and filename.

    2. + destination, userInvolvement, sourceElement, null, and + filename.

    The inner navigate event firing algorithm consists of the following steps, given a Navigation navigation, a NavigationType navigationType, a NavigateEvent event, a NavigationDestination destination, a user - navigation involvement userInvolvement, an entry list-or-null - formDataEntryList, and a string-or-null downloadRequestFilename:

    + navigation involvement userInvolvement, an Element-or-null + sourceElement, an entry list-or-null formDataEntryList, and a + string-or-null downloadRequestFilename:

    1. @@ -95635,6 +95654,10 @@ interface NavigationDestination { transition, to display a cached rendered state of the document's latest entry, was done by the user agent. Otherwise, initialize it to false.

    2. +
    3. Initialize event's sourceElement to + sourceElement.

    4. +
    5. Set event's abort controller to a new AbortController created in navigation's relevant realm.

    6. @@ -99849,9 +99872,10 @@ location.href = '#foo'; null formDataEntryList (default null), an optional referrer policy referrerPolicy (default - the empty string), and an optional user navigation involvement user navigation involvement userInvolvement (default "none"):

      + data-x="uni-none">none"), and an optional Element sourceElement (default null):

      1. Let cspNavigationType be "form-submission" if @@ -99971,7 +99995,7 @@ location.href = '#foo';

        1. Navigate to a fragment given navigable, url, historyHandling, userInvolvement, - navigationAPIState, and navigationId.

        2. + sourceElement navigationAPIState, and navigationId.

        3. Return.

        @@ -100074,7 +100098,8 @@ location.href = '#foo'; data-x="fire-navigate-prr-navigationType">navigationType set to historyHandling, isSameDocument set to false, userInvolvement set to - userInvolvement, userInvolvement, sourceElement set + to sourceElement, formDataEntryList set to entryListForFiring, destinationURL set to url, and

        To navigate to a fragment given a navigable navigable, a URL url, a history handling behavior historyHandling, a user navigation involvement userInvolvement, - a serialized state-or-null navigationAPIState, and a navigation - ID navigationId:

        + an Element-or-null sourceElement, a serialized state-or-null + navigationAPIState, and a navigation ID navigationId:

        1. Let navigation be navigable's active @@ -100690,7 +100715,8 @@ location.href = '#foo'; navigation with navigationType set to historyHandling, isSameDocument set to true, userInvolvement set to - userInvolvement, destinationURL + userInvolvement, sourceElement set + to sourceElement, destinationURL set to url, and navigationAPIState set to destinationNavigationAPIState.

        2. From d11d91d5cd12e355260fcc0cfaef361a5cc5743e Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 7 Jan 2025 10:18:11 +0000 Subject: [PATCH 2/4] nit --- source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source b/source index 6574eb5ba0e..46b228e7a57 100644 --- a/source +++ b/source @@ -99995,7 +99995,7 @@ location.href = '#foo';
          1. Navigate to a fragment given navigable, url, historyHandling, userInvolvement, - sourceElement navigationAPIState, and navigationId.

          2. + sourceElement, navigationAPIState, and navigationId.

          3. Return.

          From dce3079bb24dff05a8c91a469aec2510723950d2 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 7 Jan 2025 12:50:41 +0000 Subject: [PATCH 3/4] Accept suggestions --- source | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source b/source index 46b228e7a57..ee88e6aeb13 100644 --- a/source +++ b/source @@ -95005,8 +95005,8 @@ callback NavigationInterceptHandler = event.sourceElement

          Returns the Element responsible for this navigation, be it an a - element that was clicked, a Submit Button, or a - submitted form.

          + element that was clicked, a submit button, or a + submitted form element.

    event.intercept({ handler, focusReset, scroll })
    From 49e18dcb7725f1a88c50341392124bcddcd634e7 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Wed, 15 Jan 2025 09:02:16 +0000 Subject: [PATCH 4/4] Fix wording --- source | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source b/source index ee88e6aeb13..524b1fa4acd 100644 --- a/source +++ b/source @@ -95004,9 +95004,10 @@ callback NavigationInterceptHandler = event.sourceElement -

    Returns the Element responsible for this navigation, be it an a - element that was clicked, a submit button, or a - submitted form element.

    +

    Returns the Element responsible for this navigation. This can be an + aor area element, a submit button, or a submitted form + element.

    event.intercept({ handler, focusReset, scroll })