Element#focus() sometimes clear selection.
Steps
1. Visit https://jsfiddle.net/mj6m7kwb/
2. Click "Set focus to x2"
3. Click "Set focus to x3"
Expected:
Step 3 should display
before: body, 6
after: body, 6
Actual:
Chrome: before=null, after=null
Firefox: before=x2,0 after=x2,0
Edge: before BODY,6 after=BODY,6
Note:
Chrome's behavior is caused by clearSelectionIfNeeded() called from FocusController::setFocusedElement().
It seems this behavior is introduced for workaround of issue 89026 , hitting keyboard inserts a character in non-focused element.
Comment 1 by yosin@chromium.org
, Jan 23 2017