Just to be sure, we should double check the visibility, in theory with this listener can be triggered with a change from visible to hidden, so to be completely sure we could check the document visibility and execute just when we are visible ;)