Last Comment Bug 656283 - accessing document.activeElement throws an exception
: accessing document.activeElement throws an exception
Product: Core
Classification: Components
Component: DOM: Core & HTML (show other bugs)
: unspecified
: x86 Windows 7
: -- normal (vote)
: ---
Assigned To: Olli Pettay [:smaug]
: Andrew Overholt [:overholt]
Depends on:
  Show dependency treegraph
Reported: 2011-05-11 06:59 PDT by Miroslav Kroc
Modified: 2011-05-13 01:25 PDT (History)
2 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

patch (4.13 KB, patch)
2011-05-11 10:02 PDT, Olli Pettay [:smaug]
bzbarsky: review+
Details | Diff | Splinter Review

Description Miroslav Kroc 2011-05-11 06:59:39 PDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; cs; rv: Gecko/20110420 Firefox/3.6.17
Build Identifier: Firefox 3.6.17, Firefox 4.0.0

JS exception "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE" occurs if property document.activeElement refers to DOM element from previous document. We discovered this bug in following scenario.

Website contains two pages. First page is login page with two input elements for username and password and "submit" button. Second page is a page accessing document.activeElement.
User click on "submit" button (first step) and then on input element with username (second step). JS exception mentioned above occurs when the second page (loaded after submitting the first page) tries to access document.activeElement property.
I can reproduce this bug easily in Firefox with Firebug.

Reproducible: Sometimes

Steps to Reproduce:
1. load simple login page (username, password, submit button)
2. fill username and password
3. click on "submit" button (active element is button)
4. click on input element before the second page appears (active element is input element)
5. wait until the second page is loaded

Actual Results:  
JS exception:
[Exception... "Component returned failure code: 0x80004005
(NS_ERROR_FAILURE) [nsIDOMNSDocument.activeElement]" nsresult: "0x80004005
(NS_ERROR_FAILURE)" location: "JS frame ::
http://serverName/pathToFile ::
<TOP_LEVEL> :: line 24" data: no]

Expected Results:  
No js exception. Property document.activeElement refers to any DOM element in the current document or is null.

This bug is OS and version independent.

Used software:
- Firefox 3.6.17, Firefox 4.0.0
- Windows 7 x64, Windows 7 x86, MacOs 10.6
Comment 1 Olli Pettay [:smaug] 2011-05-11 08:47:54 PDT
A testcase would be great.
Comment 2 Olli Pettay [:smaug] 2011-05-11 08:55:15 PDT
But the implementation is certainly wrong.
(And I reviewed the code :( )
Comment 3 Olli Pettay [:smaug] 2011-05-11 09:51:03 PDT
Patch with tests coming....
Comment 4 Olli Pettay [:smaug] 2011-05-11 10:02:25 PDT
Created attachment 531662 [details] [diff] [review]

This should do it. Make sure .activeElement doesn't throw, ever.
Comment 5 Boris Zbarsky [:bz] (still a bit busy) 2011-05-11 10:06:30 PDT
Comment on attachment 531662 [details] [diff] [review]

Comment 6 Olli Pettay [:smaug] 2011-05-11 16:06:10 PDT
Comment 7 Miroslav Kroc 2011-05-13 01:25:46 PDT
Thank you for fast solution. I apologize for missing testcase. We haven't finished simplified testcase when this bug was reported.

Note You need to log in before you can comment on or make changes to this bug.