From d5c8e5cb3b6fc7cddbebd19737d6215a7a721895 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 28 Jan 2025 08:14:31 +0000 Subject: [PATCH] Add sourceElement to NavigateEvent The sourceElement 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/blob/main/README.md#navigation-monitoring-and-interception for the original explainer. --- source | 65 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/source b/source index eb0d4e07b6d..864a982e0de 100644 --- a/source +++ b/source @@ -25640,8 +25640,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 @@ -25721,7 +25722,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.

  • @@ -60152,6 +60154,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 @@ -95383,6 +95386,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(); @@ -95513,6 +95517,12 @@ callback NavigationInterceptHandler = event.sourceElement +

    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 })

    Intercepts this navigation, preventing its normal handling and instead converting it into a @@ -95617,9 +95627,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 @@ -95942,7 +95955,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 @@ -95980,14 +95995,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:

      @@ -96019,15 +96037,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. @@ -96149,6 +96169,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. @@ -100364,9 +100388,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 @@ -100486,7 +100511,7 @@ location.href = '#foo';

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

        2. + sourceElement, navigationAPIState, and navigationId.

        3. Return.

        @@ -100585,7 +100610,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 @@ -101201,7 +101227,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.