onbeforeunload only respected once during lifetime of tab on a domain

Originator:andrewrn
Number:rdar://28814642 Date Originated:18-Oct-2016
Status:Duplicate Resolved:
Product:Safari Product Version:10.0
Classification: Reproducible:Always
 
Summary:
When setting the JS onbeforeunload event, the dialogue is only shown until the user chooses to navigate away.
On subsequent pages on the same site, the onbeforeunload function is called, but the dialogue is no longer shown.

Steps to Reproduce:
1. Open a new tab and navigate to any page (e.g. apple.com)
2. Open the JS console and paste the following:
    window.onbeforeunload = function() {return true;};
3. Click on the page
4. Hit Refresh
5. *Observe the warning is shown*
6. Click to stay
7. Hit Refresh again
8. *Observe the warning is shown*
9. Click to leave (the page will refresh)
10. Paste exactly the same code in the JS console again
11. Hit refresh
12. *Observe that the warning is not shown* :(

Expected Results:
The dialogue should once again confirm whether you wish to leave

Actual Results:
The dialogue does not confirm

Version:
OS X 10.11.6 (15G1004); Safari: Version 9.1.3 (11601.7.8)

OSX: 10.12 (16A323); Safari: Version 10.0 (12602.1.50.0.10)

Notes:
If the user navigates to a different site (e.g. initially on apple.com, then moves to icloud.com) then the dialogue is shown for one page on that site too. Upon navigating back to the first site, it works there again for one time.

Having the JS return nothing:
    window.onbeforeunload = function() {return;}
instead of clicking on the Leave button means that subsequent pages work, but this doesn't really solve the issues with the typical usage of this feature - e.g. to confirm whether a user wants to move away from a page after making changes to a form.

See https://tracker.moodle.org/browse/MDL-56465 for our internal issue.

Configuration:
MacBook Air 11" Mid 2013 
MacBook Pro 13" Mid 2013

Attachments:

Comments

Apple Developer Relations

Thank you for contacting us.

The original report on this issue, Bug ID 24282438, is still under investigation. We will notify you when it is closed.

Please note that you will not be able to directly view the original report in order to keep its information confidential.

We will do our best to keep you informed as new information becomes available. Please check release notes regularly for changes affecting this issue.

If you have further questions about this issue or wish to check on the status, please update your report again using the Apple Bug Reporter http://bugreport.apple.com.

andrewrn

Can I ask for information on an expected resolution timeframe for this issue? I am (obviously) unable to view the issue that this one was closed in favour of.

Apple Developer Relations - Duplicate of 24282438 (Open)

Engineering has determined that your bug report is a duplicate of another issue and will be closed.

The open or closed status of the original bug report your issue was duplicated to appears in the yellow "Duplicate of XXXXXXXX" section of the bug reporter user interface. This section appears near the top of the right column's bug detail view just under the bug number, title, state, product and rank.

If you have any questions or concerns, please update your report directly here: http://bugreport.apple.com/.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!