Hijack Focus
const el = document.body.appendChild(
document.createElement('div')
);
el.innerHTML = `
<button>one</button>
<button>two</button>
<button>three</button>
`;
document.addEventListener('click', e => {
e.target.focus();
});
const origFocus = HTMLElement.prototype.focus
HTMLElement.prototype.focus = function() {
console.log(this.outerHTML, 'focus was called');
origFocus.call(this);
};
el.firstElementChild.focus();
Easy way to debug many calls to focus
.