New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 701434 link

Starred by 2 users

Issue metadata

Status: Duplicate
Merged: issue 832234
Owner: ----
Closed: Sep 12
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug



Sign in to add a comment

closing window with beforeunload | unload handlers takes too long

Project Member Reported by ojan@chromium.org, Mar 14 2017

Issue description

window.addEventListener('beforeunload', function() {
  while (true) {}
});

http://plexode.com/eval3/#s=aekVQXANLVQMbA28PQkVFJldGT1UtSlRVnEZTCQhDRkdQU0ZWT01QlwgNAWAJCgFcPU8BAVhJSk1GAQlVU1ZGuFxeu14KHANeAA==

Closing a tab with that code takes ~2 seconds on Chrome 56 on ChromeOS. It should take ~1 second because we trigger hang detection after 1 second.

I'm hitting this on real world content. For example:
1. Go to politico.com
2. ctrl+click to open a half dozen articles in background tabs
3. Wait a second. Then, while the background tabs are still loading, try to close the background tabs by clicking the x button in the tab strip.

Closing each one takes ~2 seconds.
 

Comment 1 by ojan@chromium.org, Mar 14 2017

See also related  issue 701435  for reducing the timeout lower than 1 second. I want to keep this bug focused on understanding why it takes longer than the currently intended 1 second timeout.

Comment 2 by a...@chromium.org, Apr 6 2017

What's going on here is that when you close a tab, the browser sends the beforeunload IPC to the render process and starts a 1 second timeout. It fires. It then continues to close the page, which has its own independent 1 second timeout. That one too must fire before the page closes.

That's why it's 2 seconds.

Comment 3 by ojan@chromium.org, Aug 22 2017

Cc: panicker@chromium.org
This feels like it's gotten even slower.

Comment 4 by ojan@chromium.org, Aug 22 2017

Cc: creis@chromium.org dcheng@chromium.org nasko@chromium.org
Making it so that we cap at a total of one second might be something navigation folks would be interested in fixing. CCing them. :)

Comment 5 by creis@chromium.org, Aug 25 2017

Cc: clamy@chromium.org
Components: UI>Browser>Navigation
It seems like we should instead put effort into skipping beforeunload entirely if there aren't any handlers registered for it, in issue 365039.  That's likely to improve performance here in the vast majority of cases.

With shortening the timeout, we risk losing user data in more cases on a slow machine, so we have to be careful with that.

Comment 6 by ojan@chromium.org, Aug 25 2017

IMO waiting >2 seconds for anything to happen after you try to close a tab is a bad enough user experience that we should be more aggressive.

I'm supportive of adding measurement to see how often we kill the tab before the unload is completed though to make sure it doesn't go through the roof.

Comment 7 by panicker@google.com, Aug 29 2017

Summary: closing window with beforeunload | unload handlers takes too long (was: closing window with beforeunload handler takes too long)
BTW same problem happens on unload too, not just beforeunload (update the demo code to unload).
+1 for measurement, I'll look into that aspect.

Components: Blink>PageLifecycle
Mergedinto: 832234
Status: Duplicate (was: Untriaged)

Sign in to add a comment