WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
255837
The `beforeunload` event doesn't occur when clicking on a link
https://bugs.webkit.org/show_bug.cgi?id=255837
Summary
The `beforeunload` event doesn't occur when clicking on a link
Tee Ming
Reported
2023-04-22 22:06:11 PDT
Created
attachment 466050
[details]
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 & 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
Attachments
The HTML file contains a link that should be intercepted by the beforeunload event.
(431 bytes, text/html)
2023-04-22 22:06 PDT
,
Tee Ming
no flags
Details
The HTML file contains a link that should be intercepted by the beforeunload event (event.preventDefault).
(457 bytes, text/html)
2023-04-23 17:19 PDT
,
Tee Ming
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Alexey Proskuryakov
Comment 1
2023-04-23 14:15:41 PDT
The attached test case doesn't contain "preventDefault()", is this one that you intended to provide? It does behave differently that in Chrome, but I'd like to make certain that we are talking about the same issue.
Tee Ming
Comment 2
2023-04-23 17:19:59 PDT
Created
attachment 466055
[details]
The HTML file contains a link that should be intercepted by the beforeunload event (event.preventDefault).
Tee Ming
Comment 3
2023-04-23 17:21:29 PDT
(In reply to Alexey Proskuryakov from
comment #1
)
> The attached test case doesn't contain "preventDefault()", is this one that > you intended to provide? It does behave differently that in Chrome, but I'd > 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've uploaded an updated test case that includes the line.
Radar WebKit Bug Importer
Comment 4
2023-04-29 22:07:19 PDT
<
rdar://problem/108706692
>
Tee Ming
Comment 5
2023-12-01 11:11:28 PST
After another look at this, it seems the confirmation dialog isn't appearing because the `beforeunload` event is never invoked when clicking on the link.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug