beforeunload handler can still alter window.location from a timeout
Categories
(Core :: DOM: Navigation, defect, P3)
Tracking
()
People
(Reporter: Smylers, Unassigned)
References
(Blocks 1 open bug)
Details
Updated•9 years ago
|
Comment 1•9 years ago
|
||
Comment 2•9 years ago
|
||
Comment 3•9 years ago
|
||
Comment 4•9 years ago
|
||
Comment 5•9 years ago
|
||
Comment 6•9 years ago
|
||
Comment 7•9 years ago
|
||
Comment 8•9 years ago
|
||
Comment 9•9 years ago
|
||
Comment 10•9 years ago
|
||
Comment 11•9 years ago
|
||
Comment 12•9 years ago
|
||
Comment 13•9 years ago
|
||
Updated•8 years ago
|
Comment 15•8 years ago
|
||
Updated•8 years ago
|
Updated•8 years ago
|
Comment 21•6 years ago
|
||
My recollection is that the current version of the spec tries to distinguish user-initiated navigation and, once we start trying to execute that (by firing beforeunload, followed by unload, followed by actually loading a new page), any subsequent manipulation of location should have no effect (unless the user bails out in beforeunload). (Paraphrasing spec language for something roughly like this, obviously)
Boris/Anne, is that recollection at all near the truth? What should we be doing here? And any chance we can re-prio this?
Comment 22•6 years ago
|
||
No, the situation around this specification-wise hasn't really improved from three years ago unfortunately.
Comment 23•6 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #3)
are there spec reasons we can't just stop navigation permanently as soon as we fire beforeunload
At first blush, per spec you can't stop navigation inside beforeunload at
all. Or something. Figuring out what the spec says here is rocket science.
:(
(In reply to Anne (:annevk) from comment #5)
First of all, agreed with bz that this is in need of heavy refactoring.
Unfortunately there has been a lot of that, so I haven't gotten around to it
yet. If we had more editors, maybe...Having read through navigate and its various associated algorithms a few
times now, I don't think anything there stops this, since the user is
allowed to navigate elsewhere until the page navigated to actually starts
arriving (at that point navigate starts blocking certain navigation
attempts, though not all).Now, we could make tweaks, but that's tricky. E.g., if the user clicks <a
onclick=window.location='/x'>test</a> after dismissing the dialog, should
that fail or work?
(In reply to Anne (:annevk) from comment #22)
No, the situation around this specification-wise hasn't really improved from three years ago unfortunately.
So... I'm going to be quite tentative here, because I'm very much not an expert, and both of you are. But if I'm reading:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate
Specifically,
If there is a preexisting attempt to navigate browsingContext, and the source browsing context is the same as browsingContext, and that attempt is currently running the unload a document algorithm, then return without affecting the preexisting attempt to navigate browsingContext.
If the prompt to unload algorithm is being run for the active document of browsingContext, then return without affecting the prompt to unload algorithm.
I assume that the second of these now does mean that we can avoid navigation from within beforeunload itself, right?
I'm guessing (it's a bit hard to tell for me, not knowing where to look in the spec) that we don't unload the current document (ie we don't hit the first cited condition) until we start getting a response for the initial navigation, and so between these two conditions (ie after beforeunload
and before unload
), timers (setTimeout etc.) and any other events may trigger JS that starts another navigation, and per spec that should override the earlier navigation.
As Anne points out at the end of comment 5, blocking all navigation after 1 navigation has started is tricky.
I'm tempted to suggest we try to pass whether a navigation was the result of a user action (similar/using popup blocking state) down to loadinfo in some way, and make user-triggered navigation be un-overridable by webpage navigations. That would, AIUI fix this bug (and all its variations).
It's also a bit complex, and I would be happy to hear other alternatives - in particular, I'm quite curious if any of these bugs affect other browsers and what, if any, mitigations they have in place.
Comment 24•6 years ago
|
||
I assume that the second of these now does mean that we can avoid navigation from within beforeunload itself, right?
Yes, and we do. See nsDocShell::IsNavigationAllowed.
we don't unload the current document (ie we don't hit the first cited condition) until we start getting a response for the initial navigation
That's correct. It has to be that way, because the response could be a type that we'd hand off to a helper app instead of handling internally, so we can't know whether we'll be unloading at all until we get the response headers.
I too would be interested in what other browsers do. Conceptually, treating "user-triggered" and "page just randomly did it" navigations differently makes sense to me.
Comment 28•5 years ago
|
||
1.Step: open https://mozhelp.dynvpn.de/dateien/wl
2.Step: click on a bookmark in Firefox. For example http://example.org/foo (not a mozilla.org bookmark)
Expected result: it should open your bookmark in the same tab.
In Google Chrome/Opera it opens the wanted bookmark when I click on it.
In IE 11 and Edge and Firefox i can not override the actual tab with my bookmark
Updated•5 years ago
|
Updated•2 years ago
|
Description
•