Testcase (read the console log):
http://jsbin.com/junefib/1/edit?html,js,output Alternate version without event capturing: http://jsbin.com/qoyitu/edit?html,js,output
input.focus() runs https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps
None of the special cases apply, so we just run focus update steps with the focus chains old chain and new chain.
This part is tricky to follow, but my reading of the spec is that, in our particular case:
old chain = [body, Document] new chain = [input, Document]
(2) If the last entry in old chain and the last entry in new chain are the same, pop the last entry from old chain and the last entry from new chain and redo this step.
In our case,
Document is the last entry in both chains, so we pop it off to yield:
old chain = [body] new chain = [input]
And then the relevant part of the rest of the algorithm is to iterate over the old chain and fire
and later iterate over the new chain and fire
(5)(3) If entry is a
Documentobject, let focus event target be that
This doesn't affect us since we popped off the
Document object above, but this retargeting will become relevant in a moment.
So, there should be exactly 1
focus event, targeted at
However, only IE11/Edge actually do that. Other browsers fire additional
focus events at other targets:
// Safari/Chrome: [<input>] (Per spec(?!)) // Edge [window, <input>] (If we hadn't popped off Document in step (2) above, this would be correct) // Firefox: [document, window, <input>] (Blatantly wrong per step (5)(3); see http://bugzil.la/1228802)
So my question was whether the spec is wrong or Edge+Firefox are wrong, with respect to firing