Espere o DOM carregar JavaScript

document.addEventListener('DOMContentLoaded', (event) => {
  //the event occurred
})
Breakable Bison