<?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>255837</bug_id>
          
          <creation_ts>2023-04-22 22:06:11 -0700</creation_ts>
          <short_desc>The `beforeunload` event doesn&apos;t occur when clicking on a link</short_desc>
          <delta_ts>2023-12-01 11:11:28 -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>Page Loading</component>
          <version>Safari 16</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=206366</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Blocker</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tee Ming">chewteeming01</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>beidson</cc>
    
    <cc>cdumez</cc>
    
    <cc>karlcow</cc>
    
    <cc>nham</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1950616</commentid>
    <comment_count>0</comment_count>
      <attachid>466050</attachid>
    <who name="Tee Ming">chewteeming01</who>
    <bug_when>2023-04-22 22:06:11 -0700</bug_when>
    <thetext>Created attachment 466050
The HTML file contains a link that should be intercepted by the beforeunload event.

Summary:
Calling `event.preventDefault()` when listening to a `beforeunload` event on the `window` should rightly prompt the user if they want to stay or leave the page. This is currently broken in macOS Safari 16.4.

OS:
I have tested this issue on both iOS Safari 16.4.1 and macOS Safari Version 16.4 (18615.1.26.11.23).

Steps to reproduce:
An example page such as https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onbeforeunload will not work on iOS, but will still work on macOS (it only works on macOS because the unload event is contained in an iframe.)
I have attached a sample HTML file that can be opened in a Webkit browser. Clicking on the link should prompt the user with an alert. The code was copied from the example provided by W3Schools.

Actual results:
The browser navigates to the link normally.

Expected results:
The browser prompts the user with an alert to stay or leave the page before navigating to the new page.

Build Date &amp; Hardware:
Apple M1 Pro
macOS 13.3.1 (22E261)

Additional information:
I first noticed this issue during some cross-browser tests for cancelling the `beforeunload` event. Only Safari was failing the tests at the time so I started to investigate. The PR with those cross-browser tests can be found here: https://github.com/sveltejs/kit/pull/9747</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1950662</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2023-04-23 14:15:41 -0700</bug_when>
    <thetext>The attached test case doesn&apos;t contain &quot;preventDefault()&quot;, is this one that you intended to provide? It does behave differently that in Chrome, but I&apos;d like to make certain that we are talking about the same issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1950674</commentid>
    <comment_count>2</comment_count>
      <attachid>466055</attachid>
    <who name="Tee Ming">chewteeming01</who>
    <bug_when>2023-04-23 17:19:59 -0700</bug_when>
    <thetext>Created attachment 466055
The HTML file contains a link that should be intercepted by the beforeunload event (event.preventDefault).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1950675</commentid>
    <comment_count>3</comment_count>
    <who name="Tee Ming">chewteeming01</who>
    <bug_when>2023-04-23 17:21:29 -0700</bug_when>
    <thetext>(In reply to Alexey Proskuryakov from comment #1)
&gt; The attached test case doesn&apos;t contain &quot;preventDefault()&quot;, is this one that
&gt; you intended to provide? It does behave differently that in Chrome, but I&apos;d
&gt; like to make certain that we are talking about the same issue.

Sorry about that. I forgot to include the `event.preventDefault()` line in the test case. I&apos;ve uploaded an updated test case that includes the line.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1952064</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-04-29 22:07:19 -0700</bug_when>
    <thetext>&lt;rdar://problem/108706692&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1996287</commentid>
    <comment_count>5</comment_count>
    <who name="Tee Ming">chewteeming01</who>
    <bug_when>2023-12-01 11:11:28 -0800</bug_when>
    <thetext>After another look at this, it seems the confirmation dialog isn&apos;t appearing because the `beforeunload` event is never invoked when clicking on the link.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>466050</attachid>
            <date>2023-04-22 22:06:11 -0700</date>
            <delta_ts>2023-04-22 22:06:11 -0700</delta_ts>
            <desc>The HTML file contains a link that should be intercepted by the beforeunload event.</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>431</size>
            <attacher name="Tee Ming">chewteeming01</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8Ym9keSBvbmJlZm9yZXVubG9hZD0icmV0dXJuIG15RnVu
Y3Rpb24oZXZlbnQpIj4KPGgxPkhUTUwgRE9NIEV2ZW50czwvaDE+CjxoMj5UaGUgYmVmb3JldW5s
b2FkIEV2ZW50PC9oMj4KCjxwPlJlbG9hZCB0aGlzIHBhZ2UsIG9yIGNsaWNrIG9uIHRoZSBsaW5r
IGJlbG93IHRvIGludm9rZSB0aGUgb25iZWZvcmV1bmxvYWQgZXZlbnQuPC9wPgoKPGEgaHJlZj0i
aHR0cHM6Ly93d3cudzNzY2hvb2xzLmNvbSI+Q2xpY2sgaGVyZSB0byBnbyB0byB3M3NjaG9vbHMu
Y29tPC9hPgogICAgCjxzY3JpcHQ+CmZ1bmN0aW9uIG15RnVuY3Rpb24oZXZlbnQpIHsKICBjb25z
b2xlLmxvZyhldmVudCk7CiAgcmV0dXJuICJXcml0ZSBzb21ldGhpbmcgY2xldmVyIGhlcmUuLi4i
Owp9Cjwvc2NyaXB0PgoKPC9ib2R5Pgo8L2h0bWw+Cgo=
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>466055</attachid>
            <date>2023-04-23 17:19:59 -0700</date>
            <delta_ts>2023-04-23 17:19:59 -0700</delta_ts>
            <desc>The HTML file contains a link that should be intercepted by the beforeunload event (event.preventDefault).</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>457</size>
            <attacher name="Tee Ming">chewteeming01</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8Ym9keSBvbmJlZm9yZXVubG9hZD0icmV0dXJuIG15RnVu
Y3Rpb24oZXZlbnQpIj4KPGgxPkhUTUwgRE9NIEV2ZW50czwvaDE+CjxoMj5UaGUgYmVmb3JldW5s
b2FkIEV2ZW50PC9oMj4KCjxwPlJlbG9hZCB0aGlzIHBhZ2UsIG9yIGNsaWNrIG9uIHRoZSBsaW5r
IGJlbG93IHRvIGludm9rZSB0aGUgb25iZWZvcmV1bmxvYWQgZXZlbnQuPC9wPgoKPGEgaHJlZj0i
aHR0cHM6Ly93d3cudzNzY2hvb2xzLmNvbSI+Q2xpY2sgaGVyZSB0byBnbyB0byB3M3NjaG9vbHMu
Y29tPC9hPgogICAgCjxzY3JpcHQ+CmZ1bmN0aW9uIG15RnVuY3Rpb24oZXZlbnQpIHsKICBjb25z
b2xlLmxvZyhldmVudCk7CiAgZXZlbnQucHJldmVudERlZmF1bHQoKTsKICByZXR1cm4gIldyaXRl
IHNvbWV0aGluZyBjbGV2ZXIgaGVyZS4uLiI7Cn0KPC9zY3JpcHQ+Cgo8L2JvZHk+CjwvaHRtbD4K
Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>