<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>263687</bug_id>
          
          <creation_ts>2023-10-25 15:08:56 -0700</creation_ts>
          <short_desc>notificationClick openWindow goes to PWA root instead of url given</short_desc>
          <delta_ts>2025-12-02 05:03:23 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKit API</component>
          <version>Safari 17</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 17</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Mark R">mark.romano</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>beidson</cc>
    
    <cc>bfulgham</cc>
    
    <cc>conner</cc>
    
    <cc>dernbu</cc>
    
    <cc>dlarocque</cc>
    
    <cc>gillette</cc>
    
    <cc>pataridzegivi</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1987583</commentid>
    <comment_count>0</comment_count>
    <who name="Mark R">mark.romano</who>
    <bug_when>2023-10-25 15:08:56 -0700</bug_when>
    <thetext>Overview:

What I&apos;m seeing is similar to https://bugs.webkit.org/show_bug.cgi?id=252544#c18 but I didn&apos;t find a logged bug.

Steps to Reproduce:

Service Worker handles push/notificationclick where the event data can contain a deeplink to open.
Install the PWA on Home Screen.
Close the PWA app.
Tap a Notification with a deeplink in the data.
notificationclick calls clients.openWindow() with the deeplink.

Actual Results:

PWA is opened, but to the pwa root url.

Expected Results:

PWA is opened to the deeplink url sent to openWindow().
This is the behavior seen if the PWA is already open.

Build Date &amp; Hardware:

iPhone 14 MPUA3LL/A, iOS Version 17.0.3 (21A360)

Additional Information:

Contrary to the link above, I know that the service worker is handling the push event because I added &quot;sw-&quot; to the title sent to showNotification(), to confirm.

I also am struggling with similar Safari devtools behavior:
&quot;In this case, I cannot open the Safari devtools for the service worker running on my phone, it simply isn&apos;t listed in the Develop menu under my phone submenu, which is really strange. If I open the app manually then the service worker appears in the menu as expected.&quot;


notificationclick handler calls a focus() function with parameters extracted from notification.data:

function focus(event, parameters) {
  const destinationUrl = (parameters &amp;&amp; parameters.urlPath) ? new URL(parameters.urlPath, appPath).href : appPath;

  const matchOptions = {
    type: &apos;window&apos;,
    includeUncontrolled: false,
  };
  const result = globalThis.clients.matchAll(matchOptions)
    .then((windowClients) =&gt; {
      // See if there is client for this application already open
      const matchingClient = windowClients.find((windowClient) =&gt; windowClient.url.startsWith(appPath));

      if (matchingClient) {
        logger.info(&apos;Found a matching client, focussing it&apos;);
        if (destinationUrl !== appPath) {
          return matchingClient.navigate(destinationUrl).then(() =&gt; matchingClient.focus());
        }
        return matchingClient.focus();
      }

      logger.info(&apos;Opening a new client at&apos;, destinationUrl);
      return globalThis.clients.openWindow(destinationUrl)
        .catch((error) =&gt; {
          logger.error(`openWindow(${destinationUrl}) failed! ${error})`);
        });
    });

  event.waitUntil(result);
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1988097</commentid>
    <comment_count>1</comment_count>
    <who name="Mark R">mark.romano</who>
    <bug_when>2023-10-27 14:37:14 -0700</bug_when>
    <thetext>We have determined that it is actually the call to 
matchingClient.navigate(destinationUrl)
that is failing with &quot;TypeError: navigate failed&quot;

There are no windows open for the service worker, the PWA has been closed, and so has Safari.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1989271</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-11-01 15:09:17 -0700</bug_when>
    <thetext>&lt;rdar://problem/117817784&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1997160</commentid>
    <comment_count>3</comment_count>
    <who name="Mark R">mark.romano</who>
    <bug_when>2023-12-05 11:18:40 -0800</bug_when>
    <thetext>Are there any updates on why this isn&apos;t working properly?

As you can see in my snippet, we have a notificationclick message that can have a URL in it.

Basically we want to focus and navigate (or openWindow to the url if no client found).

It seems pretty straightforward, but users variably see different behaviors - sometimes the app is focused but doesn&apos;t navigate, sometimes the app doesn&apos;t even focus.

Is there a specific pattern to follow in a notificationclick event handler such that focus/navigate/openWindow always works on ios?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2018601</commentid>
    <comment_count>4</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2024-03-04 15:42:36 -0800</bug_when>
    <thetext>This is a regression (i.e. used to work on some versions of iOS)?f</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2022515</commentid>
    <comment_count>5</comment_count>
    <who name="Mark R">mark.romano</who>
    <bug_when>2024-03-20 11:28:45 -0700</bug_when>
    <thetext>Are there any updates on this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2112419</commentid>
    <comment_count>6</comment_count>
    <who name="Mark R">mark.romano</who>
    <bug_when>2025-04-22 08:24:27 -0700</bug_when>
    <thetext>Are there any updates on this?
&quot;It seems pretty straightforward, but users variably see different behaviors&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2162521</commentid>
    <comment_count>7</comment_count>
    <who name="Kim Yongbeom">dernbu</who>
    <bug_when>2025-12-02 05:03:23 -0800</bug_when>
    <thetext>On iOS 26.0, I am unable to reproduce this bug, and both calling self.clients.openWindow() and client.navigate() has no issues for me. Any specific iOS / webkit version for which this issue is reproducible?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>