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

Issue 692224 link

Starred by 1 user

Issue metadata

Status: Duplicate
Merged: issue 707007
Owner: ----
Closed: Apr 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Only fire beforeunload in frames the user has interacted with

Project Member Reported by domenic@chromium.org, Feb 14 2017

Issue description

Chrome Version: Version 58.0.3012.0 (Official Build) canary (64-bit)
OS: Windows 10

Consider the test at https://w3c-test.org/submissions/4800/html/browsers/browsing-the-web/unloading-documents/beforeunload-canceling.html . It pops up a lot of beforeunload dialogs, as it navigates several iframes that have beforeunload handlers which return things. (See also https://bugs.chromium.org/p/chromium/issues/detail?id=692203 .)

Firefox, on the other hand, does not prompt at all. It just ignores the request to cancel the unloading process.

Per spec either is allowed: https://html.spec.whatwg.org/multipage/browsers.html#prompt-to-unload-a-document step 8 says "the user agent may ask the user to confirm that they wish to unload the document". The key word being "may".

It seems possibly nicer to avoid such popups in iframe cases. They are fairly misleadingly worded anyway: "Do you want to leave this site" is not quite accurate. See also https://bugs.chromium.org/p/chromium/issues/detail?id=95598.

 
Description: Show this description

Comment 2 by dcheng@chromium.org, Feb 14 2017

Cc: creis@chromium.org nasko@chromium.org
This would let us simplify things in //content as well, so I think it's desirable. That being said... SubFrameBeforeUnloadFired is apparently fired on 2% of page loads (https://www.chromestatus.com/metrics/feature/timeline/popularity/98), which is pretty high!
Does that track beforeunload in general, or attempts to cancel beforeunload? We'd presumably still fire the event, just not allow it to pop up the dialog.

My impression from bugs like https://bugs.chromium.org/p/chromium/issues/detail?id=120933 is that a lot of people use onbeforeunload for analytics stuff, which (hopefully) doesn't attempt to cancel the unload.

Comment 4 by dcheng@chromium.org, Feb 14 2017

Ah, you're right: the current UMA doesn't actually track how many of those actually block navigation. I'll add a metric for that then.
Note that we behave differently for `e.preventDefault()` and for `return "a string". Separate bug, I guess. So let's test "return a string" only: https://ns-wauccuusnb.now.sh for same-origin iframe; https://ns-zjaxputfgt.now.sh for cross-origin.

I tested Edge, Safari Tech Preview, Chrome, and Firefox. It appears everyone but Firefox pops up the dialog for same-origin, and nobody pops up the dialog for cross-origin.

Comment 6 by bzbar...@mit.edu, Mar 14 2017

For Firefox, the behavior depends on whether the user has meaningfully interacted with the document.  This is not limited to iframes.  The point of beforeunload is to prompt to save data or whatnot.  No interaction means nothing to worry about saving.

Comment 7 by dcheng@chromium.org, Mar 27 2017

Cc: a...@chromium.org
Status: Available (was: Untriaged)
Summary: Only fire beforeunload in frames the user has interacted with (was: Consider not prompting for unload of iframes)
(Retitling this bug to reflect the updated understanding of sad reality)

Comment 8 by a...@chromium.org, Mar 27 2017

Question: is this

1) Do not fire the `beforeunload` event on pages with no user interaction or
2) Fire the `beforeunload` event on all page but ignore dialog requests from pages with no user interaction

? This is what Domenic in comment 3, but no one seemed to answer.

I believe that Firefox is 2. I was going to propose 2 for Chromium. I suspect that 1 would be rather web-breaking and visible. If 2, then we should change the bug summary.

Comment 9 by ojan@chromium.org, Mar 27 2017

IMO doing #2 and (roughly) matching Firefox is the no-brainer change that gets the primary user value and what we should focus on in the short-term.

I'd eventually like to kill beforeunload altogether, but that's a much move involved idea with a very long deprecation timeline, etc.

Comment 10 by a...@chromium.org, Mar 28 2017

Is everyone in agreement that we want to do 2? I'm a few days away from sending an intent to do it.

If we're good with 2, I can make this the bug.

If we're not, I'll pursue 2 anyway but in a different bug and we can have this be the bug for 1.

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

Mergedinto: 707007
Status: Duplicate (was: Available)
I'm just going to call this a dup.

Sign in to add a comment