New issue
Advanced search Search tips

Issue 713803 link

Starred by 1 user

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: 1
NextAction: ----
OS: Mac
Pri: 2
Type: Bug



Sign in to add a comment

onbeforeunload fires twice when closing a page with window.close()

Reported by benjamin...@gmail.com, Apr 20 2017

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36

Steps to reproduce the problem:
1. Create this page
<!doctype html>
<button onclick="window.open(window.location.href);">open</button>
<button onclick="window.close();">close</button>
<script>
window.onunload = function () {
    console.log('onunload');
};
window.onbeforeunload = function () {
    console.log('onbeforeunload');
}
</script>
2. Navigate to the page, and click the open button to open a new page via JS (to avoid getting the "Scripts may close only the windows that were opened by it." warning)
3. From the child page, put breakpoints in the onunload and onbeforeunload functions
4. From the child page, click the close button. It will hit the onbeforeunload function twice, writing "onbeforeunload" twice to the console before running the onunload function

What is the expected behavior?
It should only run the onbeforeunload function once, the same as it does if you close the window by clicking the X next to the tab name

What went wrong?
onbeforeunload ran twice instead of once

Did this work before? N/A 

Chrome version: 57.0.2987.133  Channel: stable
OS Version: OS X 10.12.4
Flash Version:
 

Comment 1 by kojii@chromium.org, Apr 21 2017

Owner: a...@chromium.org
avi@, is this something you're familiar with? If so, could you suggest appropriate Components?
Labels: Needs-Milestone
Components: -Blink Blink>DOM
Status: Assigned (was: Unconfirmed)
DOM team maybe? Loading?

Comment 4 by hayato@chromium.org, Aug 28 2017

Cc: tzik@chromium.org
Components: -Blink>DOM Blink>Loader
EstimatedDays: 1
tzik@, is this something you're familiar with? 

Sign in to add a comment