This works in all relevant browsers:
document.activeElement
Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!
You can use this in your Selenium steps, for example, to assert that a form field is or is not focused.