<?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>257889</bug_id>
          
          <creation_ts>2023-06-09 08:25:12 -0700</creation_ts>
          <short_desc>Permissions API reports wrong permissions for notifications</short_desc>
          <delta_ts>2023-06-16 13:16:37 -0700</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 Misc.</component>
          <version>Safari 16</version>
          <rep_platform>All</rep_platform>
          <op_sys>macOS 13</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=257710</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>cj</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>sihui_liu</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1960739</commentid>
    <comment_count>0</comment_count>
    <who name="">cj</who>
    <bug_when>2023-06-09 08:25:12 -0700</bug_when>
    <thetext># Overview

After denying permission status for notifications, leaving the site, and returning to the site the Permissions API (and window[&quot;Notifications&quot;].permission) incorrectly reports that the visitor is not in Deny status.

# Steps to Reproduce:

* Visit: https://web-push-book.gauntface.com/demos/notification-examples/
* Click the switch to prompt for enabling push notifications
* Choose to deny notifications
* Close the browser tab
* Open a new tab and re-visit https://web-push-book.gauntface.com/demos/notification-examples/
* In console run:
** `window[&quot;Notification&quot;].permission` - reports &quot;default&quot; when should be &quot;denied&quot;
** `navigator.permissions.query({name: &quot;notifications&quot;}).then(p =&gt; { console.log(p.state) })` - reports &quot;prompt&quot; when should be &quot;denied&quot;
* Note that in Safari Preferences -&gt; Websites -&gt; Notifications that &quot;Deny&quot; is shown for web-push-book.gauntface.com

# Expected Results:

The permission status should properly report that the visitor&apos;s notification permission is in Deny status

# Actual Results:

The permission status reports that visitor&apos;s notification permission is in a promptable state / not in Deny status

# Version Information:

Safari browser version: 16.6
Operating system: macOS Ventura 13.5

# Additional Information:

Likely related to: https://bugs.webkit.org/show_bug.cgi?id=257710</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1962101</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-06-16 08:26:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/110901531&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1962103</commentid>
    <comment_count>2</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2023-06-16 08:27:21 -0700</bug_when>
    <thetext>cc @youenn. I believe this behavior was intentional to avoid fingerprinting.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1962120</commentid>
    <comment_count>3</comment_count>
    <who name="Sihui Liu">sihui_liu</who>
    <bug_when>2023-06-16 09:11:30 -0700</bug_when>
    <thetext>(In reply to Chris Dumez from comment #2)
&gt; cc @youenn. I believe this behavior was intentional to avoid fingerprinting.

Yes, this is intentional. In current implementation, if the site has not requested permission before (`Notification.requestPermission()`) in the page, we will not return real permission state.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1962150</commentid>
    <comment_count>4</comment_count>
    <who name="">cj</who>
    <bug_when>2023-06-16 12:03:59 -0700</bug_when>
    <thetext>To be clear, I am not talking about `Notification.requestPermission()` in this scenario. I am talking about the Permissions API.

If this is indeed the intended behavior, how do you suggest that we are able to get the current permission status of a visitor to show relevant on-page elements? 

For example, a site may have a page where the visitor can &quot;Click here to subscribe&quot; or &quot;Click here to unsusbcribe&quot; but if we are unable to determine if the visitor is already in &quot;deny&quot; or &quot;allow&quot; status how can we programmatically display the proper messaging to the visitor?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1962158</commentid>
    <comment_count>5</comment_count>
    <who name="Sihui Liu">sihui_liu</who>
    <bug_when>2023-06-16 13:16:37 -0700</bug_when>
    <thetext>(In reply to cj from comment #4)
&gt; To be clear, I am not talking about `Notification.requestPermission()` in
&gt; this scenario. I am talking about the Permissions API.

In our current implementation, whether the web page has requested permission will affect the result of permission query.

Specifically, if the per-site setting is &quot;Ask&quot; or &quot;Allow&quot;, query() will return real value, i.e. &quot;prompt&quot; and &quot;granted&quot;. 
If the per-site setting is &quot;Deny&quot;, query() will return &quot;prompt&quot; until the page requests permission, which indicates the site wants to use the API, not just checking it for fingerprinting.

If per-site setting is &quot;Deny&quot;, `Notification.requestPermission()` will return &quot;denied&quot; without prompting user.

&gt; 
&gt; If this is indeed the intended behavior, how do you suggest that we are able
&gt; to get the current permission status of a visitor to show relevant on-page
&gt; elements? 
&gt; 
&gt; For example, a site may have a page where the visitor can &quot;Click here to
&gt; subscribe&quot; or &quot;Click here to unsusbcribe&quot; but if we are unable to determine
&gt; if the visitor is already in &quot;deny&quot; or &quot;allow&quot; status how can we
&gt; programmatically display the proper messaging to the visitor?

You will know &quot;Allow&quot; state. For &quot;Deny&quot;, if query returns &quot;prompt&quot;, you can just think of it as &quot;Ask&quot; and invoke Notification.requestPermission (or display the subscribe button; if user clicks on it, you will get `denied` and you could tell user notification must be turned on for this feature).</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>