Closed Bug 1102664 Opened 10 years ago Closed 10 years ago

unload handler that removes itself breaks bfcache, using example from documentation does not work

Categories

(Core :: General, defect)

33 Branch
x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: roan.kattouw, Unassigned)

Details

(Keywords: testcase)

Attachments

(1 file)

Attached file unloadtest.html
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0 Build ID: 20141013200257 Steps to reproduce: 1. Visit unloadtest.html (attached) 2. The text "Hello" is editable. Edit it. 3. Navigate to a different page 4. Use Back to navigate back to the demo Actual results: The page reloads, and the text "Hello" is shown, with your edits having been discarded. bfcache was not used. Expected results: bfcache should be used and the text should remain as you edited it. This works correctly (bfcache is used) if the JavaScript attaching a self-removing unload handler is commented out, so it's the presence of the unload handler that's breaking bfcache. However, the unload handler removes itself, and the documentation claims that won't break bfcache. In fact, I copied my code directly from the sample code in the documentation that tells you how to avoid breaking bfcache: https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching#pagehide_event
Keywords: testcase
Product: Firefox → Core
Olli, I'm told you know about bfcache? :-)
Flags: needinfo?(bugs)
If there is an unload (or beforeunload) event listener when we're about to fire the event, the page will not enter to bfcache. http://mxr.mozilla.org/mozilla-central/source/dom/base/nsDocument.cpp?rev=3366c0fcf9c2&mark=8654-8655,8666-8672#8654 I don't know who has added https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching#pagehide_event That doesn't look right to me.
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Flags: needinfo?(bugs)
Resolution: --- → INVALID
(In reply to Olli Pettay [:smaug] from comment #2) > If there is an unload (or beforeunload) event listener when we're about to > fire the event, the page > will not enter to bfcache. > http://mxr.mozilla.org/mozilla-central/source/dom/base/nsDocument. > cpp?rev=3366c0fcf9c2&mark=8654-8655,8666-8672#8654 > > > I don't know who has added > https://developer.mozilla.org/en-US/docs/Using_Firefox_1. > 5_caching#pagehide_event > That doesn't look right to me. Interestingly that trick DOES work for beforeunload: if you have a beforeunload handler that unsets itself, bfcache does not break. However, a self-unbinding beforeunload handler isn't very useful, because when the user receives the prompt they can choose not to leave the page, and then you have no reliable way or rebinding the event so you aren't able to prompt the user again when they try to leave a second time.
I consider that a bug. Sounds like we check the existence of beforeunload/unload listeners after beforeunload has fired. http://mxr.mozilla.org/mozilla-central/source/docshell/base/nsDocShell.cpp?rev=3366c0fcf9c2&mark=10007-10008,10021-10027#10006
Moving from Core::Untriaged to Core::General https://bugzilla.mozilla.org/show_bug.cgi?id=1407598
Component: Untriaged → General
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: