{% extends 'layout.html' %}
{% block content %}
<h3>Log In</h3>
<form action="{{url_for('login')}}" method="post" novalidate>
  {{ form.hidden_tag() }}
  <div class="row">
    <div class="col-md-6">
      <div class="form-group">
        {{ form.username.label }}
        {{ form.username(class='form-control', type='email', autofocus=True) }}
      </div>
    </div>
    <div class="col-md-6">
      <div class="form-group">
        {{ form.password.label }}
        {{ form.password(class='form-control') }}
      </div>
    </div>
  </div>
  <button class="btn btn-default" type="submit">Log In</button>
</form>
<script>
document.addEventListener('focus', function() {
  window.location.reload();
});
</script>
{% endblock %}

{% extends 'layout.html' %}
{% block content %}
<h3>Log In</h3>
<form action="{{url_for('login')}}" method="post" novalidate>
  {{ form.hidden_tag() }}
  <div class="row">
    <div class="col-md-6">
      <div class="form-group">
        {{ form.username.label }}
        {{ form.username(class='form-control', type='email', autofocus=True) }}
      </div>
    </div>
    <div class="col-md-6">
      <div class="form-group">
        {{ form.password.label }}
        {{ form.password(class='form-control') }}
      </div>
    </div>
  </div>
  <button class="btn btn-default" type="submit">Log In</button>
</form>
<script>
window.addEventListener('focus', function() {
  window.location.reload();
});
</script>
{% endblock %}

Set focus listener on window not document
Set focus listener on window not document
