Skip to content

OpenWindow lacks either sourceDocument or userInvolvement argument when running Navigate algorithm #1776

Open

Description

@saschanaz

In the step 7.2.1 of openWindow:

HandleNavigate: Navigate newContext to url with exceptionsEnabled true, and historyHandling "replace".

It doesn't pass source document here so it becomes the default value null, nor the user involvement argument which becomes "none". And the step 5 of the navigate algorithm:

  1. If sourceDocument is null:
    1. Assert: userInvolvement is "browser UI".

Which ends up with an assertion failure.

There's no document to pass (as this is a service worker function), so it seems the only way to make it happy is to pass the user involvement argument, but not sure "browser UI" fits here because the caller is certainly the script here. Thoughts?

Activity

  1. yoshisatoyanagisawa commented on Jun 4, 2025

    @yoshisatoyanagisawa
    Collaborator

    I agree that the two specifications seem to be misaligned.

    Specifically, the Navigate algorithm in the HTML specification does not appear to take ServiceWorker.openWindow() into account. It feels like it lacks consideration for navigations initiated by a ServiceWorker.

    I believe the HTML specification should be updated to properly handle these ServiceWorker-initiated navigations. user navigation involvement may also need to have the ServiceWorker initiated case instead of using "browser UI".

    @domenic @annevk What do you think?

  2. domenic commented on Jun 5, 2025

    @domenic
    Contributor

    Yeah, this is a recent change, and I agree we didn't think there were any other cases where navigation happened without a source document.

    Here is an audit of the places that in HTML depend on the assumption no sourceDocument <-> "browser UI":

    • navigate step 5 and 6
      • What happens if you do openWindow("javascript:...") from a service worker? Should we carry over the origin or not?
      • It doesn't matter, since the fresh window has an opaque origin anyway. So we can relax the assumption here.
    • navigate step 21
      • This takes care of firing the navigate event, which is also inapplicable to fresh windows.
      • So we just would need to fix the "null pointer reference" that would occur when referencing sourceDocument.
    • snapshot source snapshot params
      • This sets "has transient activation" to true on the basis that it's user-initiated. We would probably need to set it to false.
      • This sets fetch client to null. Should it instead be the service worker?
    • create navigation params by fetching
      • This sets the request's origin, service-workers mode, and referrer to values that are appropriate for browser UI navigations
      • Are these values correct for openWindow()? E.g. do we send a referrer header?

    I think @annevk might have similar considerations for declarative web push?

  3. yoshisatoyanagisawa commented on Jun 5, 2025

    @yoshisatoyanagisawa
    Collaborator

    I know Chromium implement openWindow() as an open new tab.
    https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/service_worker/service_worker_clients.cc;l=195;drc=4b816ad8489fde220430098454f287d900486e7e

    • navigate step 5 and 6
      • I suppose it is not expect to carry over the origin.
    • snapshot source snapshot params
      • if "has transient activation" is for user-initiated, I also think it reasonable to set it false for ServiceWorkers.
    • create navigation params by fetching
      • As somewhat touched above, I suppose it is not expected to send referrer.
  4. domenic commented on Jun 5, 2025

    @domenic
    Contributor

    Do you have thoughts on the fetch client? I'm not sure how much it affects beyond the referrer, but I am still unsure on that point.

  5. saschanaz commented on Jun 5, 2025

    @saschanaz
    MemberAuthor

    Where does the navigate algorithm affect the referrer? That was actually the reason to look at this and to me it looks like it never sets referrer. It's a complex algorithm so perhaps I'm just reading it wrong.

  6. mkruisselbrink commented on Jun 5, 2025

    @mkruisselbrink
    Collaborator

    snapshot source snapshot params

    • if "has transient activation" is for user-initiated, I also think it reasonable to set it false for ServiceWorkers.

    I'm not sure I understand this point; openWindow requires transient user activation to be called, so presumably it should be set to true here? Although the spec currently phrases this as any window in the origin having transient user activation, I thought one use case that originally was supposed to be supported by openWindow was opening new windows as a response to a notification click event; I'm not sure how that is supposed to work with how the spec if phrased though. But either way, openWindow is only supposed to be able to be used to open new windows when user-initiated.

  7. domenic commented on Jun 6, 2025

    @domenic
    Contributor

    Where does the navigate algorithm affect the referrer? That was actually the reason to look at this and to me it looks like it never sets referrer. It's a complex algorithm so perhaps I'm just reading it wrong.

    Step 12 of create and initialize a Document object sets the referrer from navigationParams's request's referrer.

    The fetch algorithm is generally responsible for setting a given request's referrer, in https://fetch.spec.whatwg.org/#concept-main-fetch step 9.

    The algorithm it uses, https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer, is highly dependent on the fetch client. It seems to crash if the client is null. (Fix PR: w3c/webappsec-referrer-policy#175.)

    I'm not sure I understand this point; openWindow requires transient user activation to be called, so presumably it should be set to true here?

    Thanks, I didn't read enough about openWindow to know that it required user activation.

    What the source snapshot params "has transient activation" impacts:

    • Interaction with "sandboxed top-level navigation with/without user activation"
    • The request's user activation flag, which I believe underlies Sec-Fetch-User

    I wonder what browsers currently send for Sec-Fetch-User when doing openWindow().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions